Collage  1.0.1
Object-Oriented C++ Network Library
iCommand.h
1 
2 /* Copyright (c) 2006-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef CO_ICOMMAND_H
22 #define CO_ICOMMAND_H
23 
24 #include <co/api.h>
25 #include <co/commands.h> // for enum CommandType
26 #include <co/dataIStream.h> // base class
27 
28 
29 namespace co
30 {
31 namespace detail { class ICommand; }
32 
43  class ICommand : public DataIStream
44  {
45  public:
46  CO_API ICommand();
47  CO_API ICommand( LocalNodePtr local, NodePtr remote,
48  ConstBufferPtr buffer, const bool swap );
49  CO_API ICommand( const ICommand& rhs );
50 
51  CO_API virtual ~ICommand();
52 
53  CO_API ICommand& operator = ( const ICommand& rhs );
54 
55  CO_API void clear();
56 
60  CO_API uint32_t getType() const;
61 
63  CO_API uint32_t getCommand() const;
64 
66  CO_API uint64_t getSize() const;
67 
69  template< typename T > T get()
70  {
71  T value;
72  *this >> value;
73  return value;
74  }
75 
77  CO_API NodePtr getNode() const;
78 
80  CO_API LocalNodePtr getLocalNode() const;
81 
83  CO_API bool isValid() const;
84 
86  CO_API ConstBufferPtr getBuffer() const;
88 
92  CO_API void setType( const CommandType type );
93 
95  CO_API void setCommand( const uint32_t cmd );
96 
98  void setDispatchFunction( const Dispatcher::Func& func );
99 
101  CO_API bool operator()();
103 
104  private:
105  detail::ICommand* const _impl;
106 
107  friend CO_API std::ostream& operator << (std::ostream&,const ICommand&);
108 
111  CO_API virtual size_t nRemainingBuffers() const;
112  CO_API virtual uint128_t getVersion() const;
113  CO_API virtual NodePtr getMaster();
114  CO_API virtual bool getNextBuffer( uint32_t&, uint32_t&, const void**,
115  uint64_t& );
117 
118  void _skipHeader();
119  };
120 
121  CO_API std::ostream& operator << ( std::ostream& os, const ICommand& );
122 }
123 #endif // CO_ICOMMAND_H
CO_API uint32_t getType() const
A class managing received commands.
Definition: iCommand.h:43
CO_API NodePtr getNode() const
CO_API LocalNodePtr getLocalNode() const
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:84
static void swap(T &v)
Byte-swap a plain data item.
Definition: dataIStream.h:94
A wrapper to register a function callback on an object instance.
Definition: commandFunc.h:38
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:80
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:40
CO_API bool isValid() const
CO_API uint64_t getSize() const
CommandType
Definition: commands.h:28
CO_API uint32_t getCommand() const