Collage  1.3.0
High-performance C++ library for developing object-oriented distributed applications.
node.h
1 
2 /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4  * 2012-2014, Daniel Nachbaur <danielnachbaur@gmail.com>
5  *
6  * This file is part of Collage <https://github.com/Eyescale/Collage>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 2.1 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef CO_NODE_H
23 #define CO_NODE_H
24 
25 #include <co/dispatcher.h> // base class
26 #include <co/connection.h> // used in inline template method
27 #include <co/nodeType.h> // for NODETYPE_NODE enum
28 #include <co/types.h>
29 
30 namespace co
31 {
32 namespace detail { class Node; }
33 
42 class Node : public Dispatcher, public lunchbox::Referenced
43 {
44 public:
51  CO_API explicit Node( const uint32_t type = co::NODETYPE_NODE );
52 
65  CO_API const NodeID& getNodeID() const;
66 
68  CO_API uint32_t getType() const;
69 
70  bool operator == ( const Node* n ) const;
71  bool isBigEndian() const;
72 
74  CO_API bool isReachable() const;
75 
77  CO_API bool isConnected() const;
78 
80  CO_API bool isListening() const;
81 
83  CO_API bool isClosed() const;
84 
86  CO_API bool isClosing() const;
88 
92  bool isLocal() const { return isListening(); }
93 
103 
114 
117 
125  CO_API ConnectionPtr getConnection( const bool multicast = false );
127 
142  CO_API OCommand send( const uint32_t cmd, const bool multicast = false);
143 
159  CO_API CustomOCommand send( const uint128_t& commandID,
160  const bool multicast = false );
162 
164  CO_API int64_t getLastReceiveTime() const;
165 
167  CO_API std::string serialize() const;
169  CO_API bool deserialize( std::string& data );
170 
171 protected:
173  CO_API virtual ~Node();
174 
176  void _addConnectionDescription( ConnectionDescriptionPtr cd );
178  bool _removeConnectionDescription( ConnectionDescriptionPtr cd );
179 
181  ConnectionPtr _getMulticast() const;
182 
194 
195 private:
196  detail::Node* const _impl;
197  CO_API friend std::ostream& operator << ( std::ostream&, const Node& );
198 
200  ConnectionPtr _getConnection( const bool preferMulticast );
201 
204  void _addMulticast( NodePtr node, ConnectionPtr connection );
205  void _removeMulticast( ConnectionPtr connection );
206  void _connectMulticast( NodePtr node );
207  void _connectMulticast( NodePtr node, ConnectionPtr connection );
208  void _setListening();
209  void _setClosing();
210  void _setClosed();
211  void _connect( ConnectionPtr connection );
212  void _disconnect();
213  void _setLastReceive( const int64_t time );
214  friend class LocalNode;
216 };
217 
218 CO_API std::ostream& operator << ( std::ostream& os, const Node& node );
219 }
220 
221 namespace lunchbox
222 {
223 template<> inline void byteswap( co::Node*& ) { /*NOP*/ }
224 template<> inline void byteswap( co::NodePtr& ) { /*NOP*/ }
225 }
226 
227 #endif // CO_NODE_H
CO_API OCommand send(const uint32_t cmd, const bool multicast=false)
Send a command with optional data to the node.
CO_API Node(const uint32_t type=co::NODETYPE_NODE)
Construct a new node proxy.
CO_API bool isConnected() const
CO_API uint32_t getType() const
CO_API void addConnectionDescription(ConnectionDescriptionPtr cd)
Add a new description how this node can be reached.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
Definition: types.h:97
CO_API bool isClosed() const
uint128_t NodeID
A unique identifier for nodes.
Definition: types.h:84
CO_API bool isReachable() const
Proxy node representing a remote LocalNode.
Definition: node.h:42
A class for sending custom commands and data to nodes.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:87
Object-oriented network library.
Definition: barrier.h:27
CO_API bool removeConnectionDescription(ConnectionDescriptionPtr cd)
Removes a connection description.
ConnectionPtr getMulticast()
Activate and return a multicast connection.
CO_API ConnectionPtr getConnection(const bool multicast=false)
Get an active connection to this node.
CO_API const NodeID & getNodeID() const
Get the node's unique identifier.
bool isLocal() const
Definition: node.h:92
Node specialization for a local node.
Definition: localNode.h:44
std::vector< ConnectionDescriptionPtr > ConnectionDescriptions
A vector of ConnectionDescriptionPtr's.
Definition: types.h:133
A class for sending commands with data to local and external nodes.
Definition: oCommand.h:40
virtual CO_API ~Node()
Destruct this node.
CO_API ConnectionDescriptions getConnectionDescriptions() const
CO_API bool isClosing() const
A plain co::Node.
Definition: nodeType.h:31
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:38
CO_API bool isListening() const
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:95