Collage  1.7.0
High-performance C++ library for developing object-oriented distributed applications.
node.h
1 
2 /* Copyright (c) 2005-2017, 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/connection.h> // used in inline template method
26 #include <co/dispatcher.h> // base class
27 #include <co/nodeType.h> // for NODETYPE_NODE enum
28 #include <co/types.h>
29 
30 namespace co
31 {
32 namespace detail
33 {
34 class Node;
35 }
36 
45 class Node : public Dispatcher, public lunchbox::Referenced
46 {
47 public:
54  CO_API explicit Node(const uint32_t type = co::NODETYPE_NODE);
55 
68  CO_API const NodeID& getNodeID() const;
69 
71  CO_API uint32_t getType() const;
72 
73  bool operator==(const Node* n) const;
74 
76  CO_API bool isReachable() const;
77 
79  CO_API bool isConnected() const;
80 
82  CO_API bool isListening() const;
83 
85  CO_API bool isClosed() const;
86 
88  CO_API bool isClosing() const;
90 
94  bool isLocal() const { return isListening(); }
103  CO_API void addConnectionDescription(ConnectionDescriptionPtr cd);
104 
114  CO_API bool removeConnectionDescription(ConnectionDescriptionPtr cd);
115 
117  CO_API ConnectionDescriptions getConnectionDescriptions() const;
118 
126  CO_API ConnectionPtr getConnection(const bool multicast = false);
128 
143  CO_API OCommand send(const uint32_t cmd, const bool multicast = false);
144 
160  CO_API CustomOCommand send(const uint128_t& commandID,
161  const bool multicast = false);
163 
167  CO_API void setHostname(const std::string& host);
168 
170  CO_API const std::string& getHostname() const;
171 
173  CO_API virtual std::string getWorkDir() const;
174 
176  CO_API virtual std::string getLaunchQuote() const;
178 
180  CO_API int64_t getLastReceiveTime() const;
181 
183  CO_API std::string serialize() const;
185  CO_API bool deserialize(std::string& data);
186 
187 protected:
189  CO_API virtual ~Node();
190 
192  void _addConnectionDescription(ConnectionDescriptionPtr cd);
194  bool _removeConnectionDescription(ConnectionDescriptionPtr cd);
195 
197  ConnectionPtr _getMulticast() const;
198 
209  ConnectionPtr getMulticast();
210 
211 private:
212  detail::Node* const _impl;
213  CO_API friend std::ostream& operator<<(std::ostream&, const Node&);
214 
216  ConnectionPtr _getConnection(const bool preferMulticast);
217 
220  void _addMulticast(NodePtr node, ConnectionPtr connection);
221  void _removeMulticast(ConnectionPtr connection);
222  void _connectMulticast(NodePtr node);
223  void _connectMulticast(NodePtr node, ConnectionPtr connection);
224  void _setListening();
225  void _setClosing();
226  void _setClosed();
227  void _connect(ConnectionPtr connection);
228  void _disconnect();
229  void _setLastReceive(const int64_t time);
230  friend class LocalNode;
232 };
233 
234 CO_API std::ostream& operator<<(std::ostream& os, const Node& node);
235 }
236 
237 #endif // CO_NODE_H
std::vector< ConnectionDescriptionPtr > ConnectionDescriptions
A vector of ConnectionDescriptionPtr&#39;s.
Definition: types.h:131
CO_API std::string serialize(const ConnectionDescriptions &)
Serialize a vector of connection descriptions to a string.
uint128_t NodeID
A unique identifier for nodes.
Definition: types.h:82
Proxy node representing a remote LocalNode.
Definition: node.h:45
A class for sending custom commands and data to nodes.
Object-oriented network library.
Definition: barrier.h:27
bool isLocal() const
Definition: node.h:94
Node specialization for a local node.
Definition: localNode.h:49
A class for sending commands with data to local and external nodes.
Definition: oCommand.h:41
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
Definition: types.h:95
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
Definition: types.h:93
CO_API bool deserialize(std::string &data, ConnectionDescriptions &descriptions)
Deserialize a vector or connection descriptions from a string.
A plain co::Node.
Definition: nodeType.h:31
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:85
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:41