22 #ifndef CO_LOCALNODE_H 23 #define CO_LOCALNODE_H 26 #include <co/objectHandler.h> 27 #include <co/objectVersion.h> 28 #include <lunchbox/requestHandler.h> 30 #include <boost/function/function1.hpp> 31 #include <boost/function/function4.hpp> 97 CO_API
virtual bool initLocal(
const int argc,
char** argv);
111 CO_API
virtual bool listen();
122 CO_API
virtual bool close();
142 CO_API
bool connect(
NodePtr node);
170 CO_API
NodePtr connectObjectMaster(
const uint128_t&
id);
179 CO_API
virtual bool disconnect(
NodePtr node);
200 CO_API
bool launch(
NodePtr node,
const std::string& command);
207 CO_API
NodePtr syncLaunch(
const uint128_t& nodeID, int64_t timeout);
224 CO_API
bool registerObject(
Object*
object)
override;
235 CO_API
void deregisterObject(
Object*
object)
override;
281 CO_API f_bool_t mapObject(
Object*
object,
const uint128_t&
id,
283 const uint128_t& version = VERSION_OLDEST);
293 const uint128_t& version = VERSION_OLDEST)
295 return mapObject(
object,
id, 0, version);
299 CO_API uint32_t mapObjectNB(
Object*
object,
const uint128_t&
id,
300 const uint128_t& version = VERSION_OLDEST);
303 CO_API uint32_t mapObjectNB(
Object*
object,
const uint128_t&
id,
304 const uint128_t& version,
308 CO_API
bool mapObjectSync(
const uint32_t requestID)
override;
331 syncObject(
Object*
object,
const uint128_t&
id,
NodePtr master,
332 const uint32_t instanceID = CO_INSTANCE_ALL)
override;
339 CO_API
void unmapObject(
Object*
object)
override;
342 CO_API
void disableInstanceCache();
345 CO_API
void expireInstanceData(
const int64_t age);
364 CO_API
void enableSendOnRegister();
367 CO_API
void disableSendOnRegister();
389 CO_API
virtual void objectPush(
const uint128_t& groupID,
390 const uint128_t& objectType,
391 const uint128_t& objectID,
395 typedef boost::function<void(
const uint128_t&,
410 CO_API
void registerPushHandler(
const uint128_t& groupID,
430 CO_API
bool registerCommandHandler(
const uint128_t& command,
431 const CommandHandler& func,
436 CO_API
void swapObject(
Object* oldObject,
Object* newObject);
453 CO_API
Nodes getNodes(
const bool addSelf =
true)
const;
463 CO_API
bool inCommandThread()
const;
466 CO_API
const Strings& getCommandLine()
const;
468 CO_API int64_t getTime64()
const;
469 CO_API ssize_t getCounter(
const Counter counter)
const;
484 CO_API
void removeListeners(
const Connections& connections);
492 CO_API
void flushCommands();
495 CO_API BufferPtr allocBuffer(
const uint64_t size);
508 CO_API
bool dispatchCommand(
ICommand& command)
override;
521 CO_API SendToken acquireSendToken(
NodePtr toNode);
524 CO_API
void releaseSendToken(SendToken token);
531 CO_API
void ackRequest(
NodePtr node,
const uint32_t requestID);
534 CO_API
void ping(
NodePtr remoteNode);
541 CO_API
bool pingIdleNodes();
547 CO_API
void setAffinity(
const int32_t affinity);
571 virtual void notifyConnect(
NodePtr) {}
573 virtual void notifyDisconnect(
NodePtr) {}
582 CO_API
virtual NodePtr createNode(
const uint32_t type);
585 detail::LocalNode*
const _impl;
587 friend class detail::ReceiverThread;
588 bool _startCommandThread(
const int32_t threadID);
589 void _runReceiverThread();
591 friend class detail::CommandThread;
592 bool _notifyCommandThreadIdle();
599 lunchbox::Request<void> _removeListener(
ConnectionPtr connection);
601 uint32_t _connect(
NodePtr node);
608 bool _setupPeer(
const std::string& setupOpts);
610 void _handleConnect();
611 void _handleDisconnect();
619 friend class ObjectStore;
620 template <
typename T>
621 void _registerCommand(
const uint32_t command,
const CommandFunc<T>& func,
624 registerCommand(command, func, destinationQueue);
627 void _dispatchCommand(
ICommand& command);
628 void _redispatchCommands();
631 bool _cmdAckRequest(
ICommand& command);
632 bool _cmdStopRcv(
ICommand& command);
633 bool _cmdStopCmd(
ICommand& command);
634 bool _cmdSetAffinity(
ICommand& command);
635 bool _cmdConnect(
ICommand& command);
636 bool _cmdConnectReply(
ICommand& command);
637 bool _cmdConnectAck(
ICommand& command);
639 bool _cmdDisconnect(
ICommand& command);
640 bool _cmdGetNodeData(
ICommand& command);
641 bool _cmdGetNodeDataReply(
ICommand& command);
642 bool _cmdAcquireSendToken(
ICommand& command);
643 bool _cmdAcquireSendTokenReply(
ICommand& command);
644 bool _cmdReleaseSendToken(
ICommand& command);
645 bool _cmdAddListener(
ICommand& command);
646 bool _cmdRemoveListener(
ICommand& command);
648 bool _cmdCommand(
ICommand& command);
649 bool _cmdCommandAsync(
ICommand& command);
650 bool _cmdAddConnection(
ICommand& command);
651 bool _cmdDiscard(
ICommand&) {
return true; }
654 LB_TS_VAR(_cmdThread)
655 LB_TS_VAR(_rcvThread)
658 inline
std::ostream& operator<<(
std::ostream& os, const
LocalNode& node)
660 os << static_cast<const Node&>(node);
664 #endif // CO_LOCALNODE_H boost::function< void(const uint128_t &, const uint128_t &, const uint128_t &, DataIStream &)> PushHandler
Function signature for push handlers.
Num of mapObjects served for other nodes.
uint128_t NodeID
A unique identifier for nodes.
boost::function< bool(CustomICommand &)> CommandHandler
Function signature for custom command handlers.
A helper struct bundling an object identifier and version.
A thread-safe, blocking queue for ICommand buffers.
Proxy node representing a remote LocalNode.
f_bool_t mapObject(Object *object, const ObjectVersion &v)
Convenience wrapper for mapObject().
uint128_t identifier
the object identifier
f_bool_t mapObject(Object *object, const uint128_t &id, const uint128_t &version=VERSION_OLDEST)
Counter
Counters are monotonically increasing performance variables for operations performed by a LocalNode i...
Object-oriented network library.
virtual bool exitLocal()
Close a listening node.
Interface for entities which map and register objects.
std::vector< NodePtr > Nodes
A vector of NodePtr's.
A class managing received commands.
Node specialization for a local node.
uint128_t version
the object version
A wrapper to register a function callback on an object instance.
A std::istream-like input data stream for binary data.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
lunchbox::RefPtr< co::SendToken > SendToken
A handle for a send token acquired by acquireSendToken().
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.