Collage  1.0.1
Object-Oriented C++ Network Library
node.h
1 
2 /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2010, Cedric Stalder <cedric.stalder@gmail.com>
4  * 2012, 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 Node( const uint32_t type = co::NODETYPE_NODE );
52 
65  CO_API const NodeID& getNodeID() const;
66 
67 
69  CO_API uint32_t getType() const;
70 
71  bool operator == ( const Node* n ) const;
72  bool isBigEndian() const;
73 
75  CO_API bool isReachable() const;
76 
78  CO_API bool isConnected() const;
79 
81  CO_API bool isListening() const;
82 
84  CO_API bool isClosed() const;
85 
87  CO_API bool isClosing() const;
89 
93  bool isLocal() const { return isListening(); }
94 
104 
116 
119 
127  CO_API ConnectionPtr getConnection( const bool multicast = false );
129 
144  CO_API OCommand send( const uint32_t cmd, const bool multicast = false);
145 
161  CO_API CustomOCommand send( const uint128_t& commandID,
162  const bool multicast = false );
164 
166  CO_API int64_t getLastReceiveTime() const;
167 
169  CO_API std::string serialize() const;
171  CO_API bool deserialize( std::string& data );
172 
173  protected:
175  CO_API virtual ~Node();
176 
178  void _addConnectionDescription( ConnectionDescriptionPtr cd );
180  bool _removeConnectionDescription( ConnectionDescriptionPtr cd );
181 
183  ConnectionPtr _getMulticast() const;
184 
196 
197  private:
198  detail::Node* const _impl;
199  CO_API friend std::ostream& operator << ( std::ostream&, const Node& );
200 
202  ConnectionPtr _getConnection( const bool preferMulticast );
203 
206  void _addMulticast( NodePtr node, ConnectionPtr connection );
207  void _removeMulticast( ConnectionPtr connection );
208  void _connectMulticast( NodePtr node );
209  void _connectMulticast( NodePtr node, ConnectionPtr connection );
210  void _setListening();
211  void _setClosing();
212  void _setClosed();
213  void _connect( ConnectionPtr connection );
214  void _disconnect();
215  void _setLastReceive( const int64_t time );
216  friend class LocalNode;
218  };
219 
220  CO_API std::ostream& operator << ( std::ostream& os, const Node& node );
221 }
222 
223 namespace lunchbox
224 {
225 template<> inline void byteswap( co::Node*& ) { /*NOP*/ }
226 }
227 
228 #endif // CO_NODE_H
CO_API bool removeConnectionDescription(ConnectionDescriptionPtr cd)
Removes a connection description.
virtual CO_API ~Node()
Destruct this node.
CO_API bool isConnected() const
CO_API bool isClosed() const
CO_API uint32_t getType() const
A class for sending commands with data to local and external nodes.
Definition: oCommand.h:40
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:38
UUID NodeID
A unique identifier for nodes.
Definition: types.h:77
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
Definition: types.h:90
Node specialization for a local node.
Definition: localNode.h:45
CO_API ConnectionPtr getConnection(const bool multicast=false)
Get an active connection to this node.
CO_API bool isListening() const
Proxy node representing a remote LocalNode.
Definition: node.h:42
CO_API const NodeID & getNodeID() const
Get the node&#39;s unique identifier.
CO_API bool isClosing() const
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:80
bool isLocal() const
Definition: node.h:93
A class for sending custom commands and data to nodes.
CO_API void addConnectionDescription(ConnectionDescriptionPtr cd)
Add a new description how this node can be reached.
CO_API Node(const uint32_t type=co::NODETYPE_NODE)
Construct a new node proxy.
CO_API OCommand send(const uint32_t cmd, const bool multicast=false)
Send a command with optional data to the node.
ConnectionPtr getMulticast()
Activate and return a multicast connection.
CO_API bool isReachable() const
std::vector< ConnectionDescriptionPtr > ConnectionDescriptions
A vector of ConnectionDescriptionPtr&#39;s.
Definition: types.h:123
A plain co::Node.
Definition: nodeType.h:31
CO_API ConnectionDescriptions getConnectionDescriptions() const
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:88