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>
35 namespace detail {
class LocalNode;
class ReceiverThread;
class CommandThread; }
86 CO_API
virtual bool initLocal(
const int argc,
char** argv );
100 CO_API
virtual bool listen();
112 CO_API
virtual bool close();
224 const uint128_t& version = VERSION_OLDEST );
232 const uint128_t& version = VERSION_OLDEST);
240 const uint128_t& version,
244 CO_API
virtual bool mapObjectSync(
const uint32_t requestID );
258 CO_API
void expireInstanceData(
const int64_t age );
302 CO_API
virtual void objectPush(
const uint128_t& groupID,
303 const uint128_t& objectType,
304 const uint128_t& objectID,
308 typedef boost::function< void(
const uint128_t&,
347 CO_API
void swapObject(
Object* oldObject,
Object* newObject );
364 CO_API
void getNodes(
Nodes& nodes,
const bool addSelf =
true )
const;
377 CO_API int64_t getTime64()
const;
400 CO_API
void flushCommands();
403 CO_API BufferPtr allocBuffer(
const uint64_t size );
440 CO_API
void ackRequest(
NodePtr node,
const uint32_t requestID );
474 virtual void notifyConnect(
NodePtr node ) {}
477 virtual void notifyDisconnect(
NodePtr node ) {}
490 detail::LocalNode*
const _impl;
494 bool _startCommandThread();
495 bool _notifyCommandThreadIdle();
496 friend class detail::ReceiverThread;
497 friend class detail::CommandThread;
500 void _closeNode(
NodePtr node );
507 uint32_t _connect(
NodePtr node );
510 void _runReceiverThread();
511 void _handleConnect();
512 void _handleDisconnect();
520 friend class ObjectStore;
521 template<
typename T >
void
522 _registerCommand(
const uint32_t command,
const CommandFunc< T >& func,
523 CommandQueue* destinationQueue )
528 void _dispatchCommand( ICommand& command );
529 void _redispatchCommands();
532 bool _cmdAckRequest( ICommand& command );
533 bool _cmdStopRcv( ICommand& command );
534 bool _cmdStopCmd( ICommand& command );
535 bool _cmdSetAffinity( ICommand& command );
536 bool _cmdConnect( ICommand& command );
537 bool _cmdConnectReply( ICommand& command );
538 bool _cmdConnectAck( ICommand& command );
539 bool _cmdID( ICommand& command );
540 bool _cmdDisconnect( ICommand& command );
541 bool _cmdGetNodeData( ICommand& command );
542 bool _cmdGetNodeDataReply( ICommand& command );
543 bool _cmdAcquireSendToken( ICommand& command );
544 bool _cmdAcquireSendTokenReply( ICommand& command );
545 bool _cmdReleaseSendToken( ICommand& command );
546 bool _cmdAddListener( ICommand& command );
547 bool _cmdRemoveListener( ICommand& command );
548 bool _cmdPing( ICommand& command );
549 bool _cmdCommand( ICommand& command );
550 bool _cmdCommandAsync( ICommand& command );
551 bool _cmdAddConnection( ICommand& command );
552 bool _cmdDiscard( ICommand& ) {
return true; }
555 LB_TS_VAR( _cmdThread );
556 LB_TS_VAR( _rcvThread );
559 inline std::ostream& operator << ( std::ostream& os,
const LocalNode& node )
561 os << static_cast< const Node& >( node );
565 #endif // CO_LOCALNODE_H
Interface for entities which map and register objects.
virtual CO_API bool registerObject(Object *object)
Register a distributed object.
CO_API bool registerCommandHandler(const uint128_t &command, const CommandHandler &func, CommandQueue *queue)
Register a custom command handler handled by this node.
CO_API Zeroconf getZeroconf()
std::vector< ConnectionPtr > Connections
A vector of ConnectionPtr's.
CO_API SendToken acquireSendToken(NodePtr toNode)
Acquire a send token from the given node.
CO_API bool connect(NodePtr node)
Connect a remote node (proxy) to this listening node.
CO_API ConnectionPtr addListener(ConnectionDescriptionPtr desc)
Add a listening connection to this listening node.
virtual CO_API bool disconnect(NodePtr node)
Disconnect a connected node.
UUID NodeID
A unique identifier for nodes.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
Node specialization for a local node.
A class managing received commands.
boost::function< bool(CustomICommand &) > CommandHandler
Function signature for custom command handlers.
virtual CO_API bool dispatchCommand(ICommand &command)
Dispatches a command to the registered command queue.
CO_API void removeListeners(const Connections &connections)
Remove listening connections from this listening node.
uint128_t version
the object version
virtual CO_API bool close()
Close a listening node.
lunchbox::RefPtr< co::SendToken > SendToken
A handle for a send token acquired by acquireSendToken().
CO_API CommandQueue * getCommandThreadQueue()
Return the command queue to the command thread.
CO_API void registerPushHandler(const uint128_t &groupID, const PushHandler &handler)
Register a custom handler for Object::push operations.
virtual CO_API ~LocalNode()
Destruct this local node.
CO_API void setAffinity(const int32_t affinity)
Bind this, the receiver and the command thread to the given lunchbox::Thread affinity.
Proxy node representing a remote LocalNode.
virtual CO_API void deregisterObject(Object *object)
Deregister a distributed object.
virtual CO_API bool mapObjectSync(const uint32_t requestID)
Finalize the mapping of a distributed object.
A helper struct bundling an object identifier and version.
CO_API NodePtr getNode(const NodeID &id) const
Get a node by identifier.
uint128_t identifier
the object identifier
CO_API void enableSendOnRegister()
Enable sending instance data after registration.
virtual CO_API bool listen()
Open all connections and put this node into the listening state.
virtual CO_API void unmapObject(Object *object)
Unmap a mapped object.
CO_API void disableSendOnRegister()
Disable sending data of newly registered objects.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
A std::istream-like input data stream for binary data.
CO_API void releaseSendToken(SendToken token)
Release the given send token.
CO_API void getNodes(Nodes &nodes, const bool addSelf=true) const
Assemble a vector of the currently connected nodes.
virtual CO_API void objectPush(const uint128_t &groupID, const uint128_t &objectType, const uint128_t &objectID, DataIStream &istream)
Handler for an Object::push() operation.
CO_API void ping(NodePtr remoteNode)
Request keep-alive update from the remote node.
boost::function< void(const uint128_t &, const uint128_t &, const uint128_t &, DataIStream &) > PushHandler
Function signature for push handlers.
virtual CO_API bool initLocal(const int argc, char **argv)
Initialize the node.
CO_API uint32_t mapObjectNB(Object *object, const UUID &id, const uint128_t &version=VERSION_OLDEST)
Start mapping a distributed object.
virtual bool exitLocal()
Close a listening node.
CO_API void disableInstanceCache()
Disable the instance cache of a stopped local node.
void registerCommand(const uint32_t command, const CommandFunc< T > &func, CommandQueue *queue)
Register a command member function for a command.
CO_API bool pingIdleNodes()
Request updates from all nodes above keep-alive timeout.
bool mapObject(Object *object, const ObjectVersion &v)
Convenience wrapper for mapObject().
CO_API bool mapObject(Object *object, const UUID &id, const uint128_t &version=VERSION_OLDEST)
Map a distributed object.
CO_API bool inCommandThread() const
std::vector< NodePtr > Nodes
A vector of NodePtr's.
virtual CO_API NodePtr createNode(const uint32_t type)
Factory method to create a new node.
CO_API LocalNode(const uint32_t type=co::NODETYPE_NODE)
Construct a new local node of the given type.
A thread-safe queue for ICommand buffers.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.