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; }
91 CO_API
virtual bool initLocal(
const int argc,
char** argv );
105 CO_API
virtual bool listen();
116 CO_API
virtual bool close();
137 CO_API
bool connect(
NodePtr node );
165 CO_API
NodePtr connectObjectMaster(
const uint128_t&
id );
174 CO_API
virtual bool disconnect(
NodePtr node );
195 CO_API
bool launch(
NodePtr node,
const std::string& command );
202 CO_API
NodePtr syncLaunch(
const uint128_t& nodeID, int64_t timeout );
219 CO_API
bool registerObject(
Object*
object )
override;
230 CO_API
void deregisterObject(
Object*
object )
override;
276 CO_API f_bool_t mapObject(
Object*
object,
const uint128_t&
id,
278 const uint128_t& version = VERSION_OLDEST );
286 const uint128_t& version = VERSION_OLDEST )
287 {
return mapObject(
object,
id, 0, version ); }
290 CO_API uint32_t mapObjectNB(
Object*
object,
const uint128_t&
id,
291 const uint128_t& version = VERSION_OLDEST );
294 CO_API uint32_t mapObjectNB(
Object*
object,
const uint128_t&
id,
295 const uint128_t& version,
299 CO_API
bool mapObjectSync(
const uint32_t requestID )
override;
321 CO_API f_bool_t syncObject(
Object*
object,
const uint128_t&
id,
323 const uint32_t instanceID = CO_INSTANCE_ALL )
override;
330 CO_API
void unmapObject(
Object*
object )
override;
333 CO_API
void disableInstanceCache();
336 CO_API
void expireInstanceData(
const int64_t age );
355 CO_API
void enableSendOnRegister();
358 CO_API
void disableSendOnRegister();
380 CO_API
virtual void objectPush(
const uint128_t& groupID,
381 const uint128_t& objectType,
382 const uint128_t& objectID,
386 typedef boost::function< void(
const uint128_t&,
400 CO_API
void registerPushHandler(
const uint128_t& groupID,
401 const PushHandler& handler );
421 CO_API
bool registerCommandHandler(
const uint128_t& command,
422 const CommandHandler& func,
427 CO_API
void swapObject(
Object* oldObject,
Object* newObject );
444 CO_API
Nodes getNodes(
const bool addSelf =
true )
const;
454 CO_API
bool inCommandThread()
const;
457 CO_API
const Strings& getCommandLine()
const;
459 CO_API int64_t getTime64()
const;
460 CO_API ssize_t getCounter(
const Counter counter )
const;
475 CO_API
void removeListeners(
const Connections& connections );
483 CO_API
void flushCommands();
486 CO_API BufferPtr allocBuffer(
const uint64_t size );
499 CO_API
bool dispatchCommand(
ICommand& command )
override;
513 CO_API SendToken acquireSendToken(
NodePtr toNode );
516 CO_API
void releaseSendToken( SendToken token );
523 CO_API
void ackRequest(
NodePtr node,
const uint32_t requestID );
526 CO_API
void ping(
NodePtr remoteNode );
533 CO_API
bool pingIdleNodes();
539 CO_API
void setAffinity(
const int32_t affinity );
563 virtual void notifyConnect(
NodePtr ) {}
566 virtual void notifyDisconnect(
NodePtr ) {}
576 CO_API
virtual NodePtr createNode(
const uint32_t type );
579 detail::LocalNode*
const _impl;
581 friend class detail::ReceiverThread;
582 bool _startCommandThread(
const int32_t threadID );
583 void _runReceiverThread();
585 friend class detail::CommandThread;
586 bool _notifyCommandThreadIdle();
589 void _closeNode(
NodePtr node );
593 lunchbox::Request< void > _removeListener(
ConnectionPtr connection );
595 uint32_t _connect(
NodePtr node );
602 bool _setupPeer(
const std::string& setupOpts );
604 void _handleConnect();
605 void _handleDisconnect();
613 friend class ObjectStore;
614 template<
typename T >
615 void _registerCommand(
const uint32_t command,
const CommandFunc< T >& func,
618 registerCommand( command, func, destinationQueue );
621 void _dispatchCommand(
ICommand& command );
622 void _redispatchCommands();
625 bool _cmdAckRequest(
ICommand& command );
626 bool _cmdStopRcv(
ICommand& command );
627 bool _cmdStopCmd(
ICommand& command );
628 bool _cmdSetAffinity(
ICommand& command );
629 bool _cmdConnect(
ICommand& command );
630 bool _cmdConnectReply(
ICommand& command );
631 bool _cmdConnectAck(
ICommand& command );
633 bool _cmdDisconnect(
ICommand& command );
634 bool _cmdGetNodeData(
ICommand& command );
635 bool _cmdGetNodeDataReply(
ICommand& command );
636 bool _cmdAcquireSendToken(
ICommand& command );
637 bool _cmdAcquireSendTokenReply(
ICommand& command );
638 bool _cmdReleaseSendToken(
ICommand& command );
639 bool _cmdAddListener(
ICommand& command );
640 bool _cmdRemoveListener(
ICommand& command );
642 bool _cmdCommand(
ICommand& command );
643 bool _cmdCommandAsync(
ICommand& command );
644 bool _cmdAddConnection(
ICommand& command );
645 bool _cmdDiscard(
ICommand& ) {
return true; }
648 LB_TS_VAR( _cmdThread )
649 LB_TS_VAR( _rcvThread )
652 inline
std::ostream& operator << (
std::ostream& os, const
LocalNode& node )
654 os << static_cast< const Node& >( node );
658 #endif // CO_LOCALNODE_H Num of mapObjects served for other nodes.
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< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
uint128_t NodeID
A unique identifier for nodes.
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
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
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.
boost::function< bool(CustomICommand &) > CommandHandler
Function signature for custom command handlers.
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.
boost::function< void(const uint128_t &, const uint128_t &, const uint128_t &, DataIStream &) > PushHandler
Function signature for push handlers.
std::vector< NodePtr > Nodes
A vector of NodePtr's.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.