Collage  1.5.0
High-performance C++ library for developing object-oriented distributed applications.
node.h
1 
2 /* Copyright (c) 2005-2016, Stefan Eilemann <eile@equalizergraphics.com>
3  * Cedric Stalder <cedric.stalder@gmail.com>
4  * 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 
166  CO_API void setHostname( const std::string& host );
167 
169  CO_API const std::string& getHostname() const;
170 
172  CO_API virtual std::string getWorkDir() const;
173 
175  CO_API virtual std::string getLaunchQuote() const;
177 
179  CO_API int64_t getLastReceiveTime() const;
180 
182  CO_API std::string serialize() const;
184  CO_API bool deserialize( std::string& data );
185 
186 protected:
188  CO_API virtual ~Node();
189 
191  void _addConnectionDescription( ConnectionDescriptionPtr cd );
193  bool _removeConnectionDescription( ConnectionDescriptionPtr cd );
194 
196  ConnectionPtr _getMulticast() const;
197 
209 
210 private:
211  detail::Node* const _impl;
212  CO_API friend std::ostream& operator << ( std::ostream&, const Node& );
213 
215  ConnectionPtr _getConnection( const bool preferMulticast );
216 
219  void _addMulticast( NodePtr node, ConnectionPtr connection );
220  void _removeMulticast( ConnectionPtr connection );
221  void _connectMulticast( NodePtr node );
222  void _connectMulticast( NodePtr node, ConnectionPtr connection );
223  void _setListening();
224  void _setClosing();
225  void _setClosed();
226  void _connect( ConnectionPtr connection );
227  void _disconnect();
228  void _setLastReceive( const int64_t time );
229  friend class LocalNode;
231 };
232 
233 CO_API std::ostream& operator << ( std::ostream& os, const Node& node );
234 }
235 
236 namespace lunchbox
237 {
238 template<> inline void byteswap( co::Node*& ) { /*NOP*/ }
239 template<> inline void byteswap( co::NodePtr& ) { /*NOP*/ }
240 }
241 
242 #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:95
CO_API bool isClosed() const
uint128_t NodeID
A unique identifier for nodes.
Definition: types.h:82
CO_API bool isReachable() const
CO_API const std::string & getHostname() const
virtual CO_API std::string getWorkDir() 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:85
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:131
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 void setHostname(const std::string &host)
Set the host name for the launch command.
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:93
virtual CO_API std::string getLaunchQuote() const