Line data Source code
1 :
2 : /* Copyright (c) 2006-2014, 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 :
33 : /**
34 : * A class managing received commands.
35 : *
36 : * This class is used by the LocalNode to pass received buffers to the
37 : * Dispatcher and ultimately command handler functions. It is not intended to be
38 : * instantiated by applications. The derivates of this ICommand have to be
39 : * instaniated by the application if the command type requires it. The data
40 : * retrieval is possible with the provided DataIStream methods or with the
41 : * templated get() function.
42 : */
43 : class ICommand : public DataIStream
44 : {
45 : public:
46 : CO_API ICommand(); //!< @internal
47 : CO_API ICommand( LocalNodePtr local, NodePtr remote,
48 : ConstBufferPtr buffer, const bool swap ); //!<@internal
49 : CO_API ICommand( const ICommand& rhs ); //!< @internal
50 :
51 : CO_API virtual ~ICommand(); //!< @internal
52 :
53 : CO_API ICommand & operator = ( const ICommand& rhs ); //!< @internal
54 :
55 : CO_API void clear(); //!< @internal
56 :
57 : /** @name Data Access */
58 : //@{
59 : /** @return the command type. @version 1.0 */
60 : CO_API uint32_t getType() const;
61 :
62 : /** @return the command. @version 1.0 */
63 : CO_API uint32_t getCommand() const;
64 :
65 : /** @return the command payload size. @version 1.0 */
66 : CO_API uint64_t getSize() const;
67 :
68 : /** @deprecated use read() */
69 83830 : template< typename T > T get() { return read< T >(); }
70 :
71 : /** @deprecated use getRemoteNode() */
72 198188 : NodePtr getNode() const { return getRemoteNode(); }
73 :
74 : /** @return the sending node proxy instance. @version 1.1.1 */
75 : CO_API NodePtr getRemoteNode() const override;
76 :
77 : /** @return the receiving node. @version 1.0 */
78 : CO_API LocalNodePtr getLocalNode() const override;
79 :
80 : /** @return true if the command has valid data. @version 1.0 */
81 : CO_API bool isValid() const;
82 :
83 : /** @internal @return the buffer */
84 : CO_API ConstBufferPtr getBuffer() const;
85 : //@}
86 :
87 : /** @internal @name Command dispatch */
88 : //@{
89 : /** @internal Change the command type for subsequent dispatching. */
90 : CO_API void setType( const CommandType type );
91 :
92 : /** @internal Change the command for subsequent dispatching. */
93 : CO_API void setCommand( const uint32_t cmd );
94 :
95 : /** @internal Set the function to which the command is dispatched. */
96 : void setDispatchFunction( const Dispatcher::Func& func );
97 :
98 : /** @internal Invoke and clear the command function. */
99 : CO_API bool operator()();
100 : //@}
101 :
102 : private:
103 : detail::ICommand* const _impl;
104 :
105 : friend CO_API std::ostream& operator << (std::ostream&,const ICommand&);
106 :
107 : /** @internal @name DataIStream functions */
108 : //@{
109 : CO_API size_t nRemainingBuffers() const override;
110 : CO_API uint128_t getVersion() const override;
111 : CO_API bool getNextBuffer( uint32_t&, uint32_t&, const void**,
112 : uint64_t& ) override;
113 : //@}
114 :
115 : void _skipHeader(); //!< @internal
116 : };
117 :
118 : CO_API std::ostream& operator << ( std::ostream& os, const ICommand& );
119 : }
120 : #endif // CO_ICOMMAND_H
|