Equalizer  1.4.1
localNode.h
00001 
00002 /* Copyright (c) 2005-2012, Stefan Eilemann <eile@equalizergraphics.com>
00003  *                    2010, Cedric Stalder <cedric.stalder@gmail.com>
00004  *
00005  * This library is free software; you can redistribute it and/or modify it under
00006  * the terms of the GNU Lesser General Public License version 2.1 as published
00007  * by the Free Software Foundation.
00008  *
00009  * This library is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public License
00015  * along with this library; if not, write to the Free Software Foundation, Inc.,
00016  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017  */
00018 
00019 #ifndef CO_LOCALNODE_H
00020 #define CO_LOCALNODE_H
00021 
00022 #include <co/defines.h>
00023 #include <co/node.h>            // base class
00024 #include <co/objectHandler.h>   // base class
00025 #include <co/objectVersion.h>   // VERSION_FOO used inline
00026 #include <lunchbox/requestHandler.h> // base class
00027 #include <boost/function/function1.hpp>
00028 #include <boost/function/function4.hpp>
00029 
00030 namespace co
00031 {
00032 namespace detail { class LocalNode; class ReceiverThread; class CommandThread; }
00033 
00040     class LocalNode : public lunchbox::RequestHandler, public Node,
00041                       public ObjectHandler
00042     {
00043     public:
00044         CO_API LocalNode();
00045         CO_API virtual ~LocalNode();
00046 
00047         typedef NodePtr SendToken; 
00048 
00050         typedef boost::function< void( const uint128_t&, 
00051                                        const uint128_t&, 
00052                                        const uint128_t&, 
00053                                        DataIStream& ) > PushHandler;
00054 
00056         typedef boost::function< bool( Command& ) > CommandHandler;
00057 
00088         CO_API virtual bool initLocal( const int argc, char** argv );
00089 
00102         CO_API virtual bool listen();
00103         CO_API virtual bool listen( ConnectionPtr connection ); 
00104 
00114         CO_API virtual bool close();
00115 
00117         virtual bool exitLocal() { return close(); }
00118 
00134         CO_API bool connect( NodePtr node );
00135 
00147         CO_API NodePtr connect( const NodeID& nodeID );
00148 
00156         CO_API virtual bool disconnect( NodePtr node );
00158 
00162         CO_API void disableInstanceCache();
00163 
00165         CO_API void expireInstanceData( const int64_t age );
00166 
00182         CO_API void enableSendOnRegister();
00183 
00185         CO_API void disableSendOnRegister();
00186 
00198         CO_API virtual bool registerObject( Object* object );
00199 
00205         CO_API virtual void deregisterObject( Object* object );
00206 
00240         CO_API bool mapObject( Object* object, const UUID& id,
00241                                const uint128_t& version = VERSION_OLDEST );
00242 
00244         bool mapObject( Object* object, const ObjectVersion& v )
00245             { return mapObject( object, v.identifier, v.version ); }
00246 
00248         CO_API uint32_t mapObjectNB( Object* object, const UUID& id,
00249                                      const uint128_t& version = VERSION_OLDEST);
00250 
00255         CO_API virtual uint32_t mapObjectNB( Object* object, const UUID& id,
00256                                              const uint128_t& version,
00257                                              NodePtr master );
00258 
00260         CO_API virtual bool mapObjectSync( const uint32_t requestID );
00261 
00267         CO_API virtual void unmapObject( Object* object );
00268 
00270         CO_API void releaseObject( Object* object );
00271 
00290         CO_API virtual void objectPush( const uint128_t& groupID,
00291                                         const uint128_t& objectType,
00292                                         const uint128_t& objectID,
00293                                         DataIStream& istream );
00294 
00304         CO_API void registerPushHandler( const uint128_t& groupID,
00305                                          const PushHandler& handler );
00306 
00315         CO_API bool registerCommandHandler( const uint128_t& command,
00316                                             const CommandHandler& func,
00317                                             CommandQueue* queue );
00318 
00321         CO_API void swapObject( Object* oldObject, Object* newObject );
00323 
00334         CO_API NodePtr getNode( const NodeID& id ) const;
00335 
00337         CO_API void getNodes( Nodes& nodes, const bool addSelf = true ) const;
00338 
00340         CO_API CommandQueue* getCommandThreadQueue();
00341 
00346         CO_API bool inCommandThread() const;
00347 
00349         CO_API int64_t getTime64() const;
00351 
00358         CO_API ConnectionPtr addListener( ConnectionDescriptionPtr desc );
00359 
00361         CO_API void addListener( ConnectionPtr connection );
00362 
00364         CO_API void removeListeners( const Connections& connections );
00365 
00372         CO_API void flushCommands();
00373 
00375         CO_API Command& cloneCommand( Command& command );
00376 
00378         CO_API Command& allocCommand( const uint64_t size );
00379 
00387         CO_API bool dispatchCommand( Command& command );
00388 
00393         CO_API SendToken acquireSendToken( NodePtr toNode );
00394         CO_API void releaseSendToken( SendToken& token );
00395 
00397         CO_API Zeroconf getZeroconf();
00399 
00401         CO_API void ackRequest( NodePtr node, const uint32_t requestID );
00402 
00404         CO_API void ping( NodePtr remoteNode );
00405 
00411         CO_API bool pingIdleNodes();
00412 
00414         CO_API void setAffinity( const int32_t affinity );
00415 
00416     protected:
00429         CO_API bool connect( NodePtr node, ConnectionPtr connection );
00430 
00432         virtual void notifyDisconnect( NodePtr node ) { }
00433 
00434     private:
00435         detail::LocalNode* const _impl;
00436 
00437         bool _connectSelf();
00438         void _connectMulticast( NodePtr node );
00439 
00440         bool _startCommandThread();
00441         bool _notifyCommandThreadIdle();
00442         friend class detail::ReceiverThread;
00443         friend class detail::CommandThread;
00444 
00445         void _cleanup();
00446         CO_API void _addConnection( ConnectionPtr connection );
00447         void _removeConnection( ConnectionPtr connection );
00448 
00449         NodePtr _connect( const NodeID& nodeID, NodePtr peer );
00450         NodePtr _connectFromZeroconf( const NodeID& nodeID );
00451         uint32_t _removeListenerNB( ConnectionPtr connection );
00452         uint32_t _connect( NodePtr node );
00453         uint32_t _connect( NodePtr node, ConnectionPtr connection );
00454 
00455         void _runReceiverThread();
00456         void   _handleConnect();
00457         void   _handleDisconnect();
00458         bool   _handleData();
00459         void   _initService();
00460         void   _exitService();
00461 
00462         friend class ObjectStore;
00463         template< typename T > void
00464         _registerCommand( const uint32_t command, const CommandFunc< T >& func,
00465                           CommandQueue* destinationQueue )
00466         {
00467             registerCommand( command, func, destinationQueue );
00468         }
00469 
00470         void _dispatchCommand( Command& command );
00471         void   _redispatchCommands();
00472 
00474         bool _cmdAckRequest( Command& packet );
00475         bool _cmdStopRcv( Command& command );
00476         bool _cmdStopCmd( Command& command );
00477         bool _cmdSetAffinity( Command& command );
00478         bool _cmdConnect( Command& command );
00479         bool _cmdConnectReply( Command& command );
00480         bool _cmdConnectAck( Command& command );
00481         bool _cmdID( Command& command );
00482         bool _cmdDisconnect( Command& command );
00483         bool _cmdGetNodeData( Command& command );
00484         bool _cmdGetNodeDataReply( Command& command );
00485         bool _cmdAcquireSendToken( Command& command );
00486         bool _cmdAcquireSendTokenReply( Command& command );
00487         bool _cmdReleaseSendToken( Command& command );
00488         bool _cmdAddListener( Command& command );
00489         bool _cmdRemoveListener( Command& command );
00490         bool _cmdPing( Command& command );
00491         bool _cmdCommand( Command& command );
00492         bool _cmdCommandAsync( Command& command );
00493         bool _cmdDiscard( Command& ) { return true; }
00495 
00496         LB_TS_VAR( _cmdThread );
00497         LB_TS_VAR( _rcvThread );
00498     };
00499     inline std::ostream& operator << ( std::ostream& os, const LocalNode& node )
00500     {
00501         os << static_cast< const Node& >( node );
00502         return os;
00503     }
00504 }
00505 #endif // CO_LOCALNODE_H
Generated on Mon Nov 26 2012 14:41:49 for Equalizer 1.4.1 by  doxygen 1.7.6.1