Equalizer 1.0
|
00001 00002 /* Copyright (c) 2005-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 00004 * This library is free software; you can redistribute it and/or modify it under 00005 * the terms of the GNU Lesser General Public License version 2.1 as published 00006 * by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, but WITHOUT 00009 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00010 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00011 * details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this library; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00016 */ 00017 00018 #ifndef CO_OBJECT_H 00019 #define CO_OBJECT_H 00020 00021 #include <co/dispatcher.h> // base class 00022 #include <co/localNode.h> // used in RefPtr 00023 #include <co/types.h> // for Nodes 00024 #include <co/version.h> // used as default parameter 00025 00026 namespace co 00027 { 00028 class ObjectCM; 00029 struct NodeMapObjectReplyPacket; 00030 00031 # define CO_COMMIT_NEXT EQ_UNDEFINED_UINT32 //!< the next commit incarnation 00032 00040 class Object : public Dispatcher 00041 { 00042 public: 00044 enum ChangeType 00045 { 00046 NONE, 00047 STATIC, 00048 INSTANCE, 00049 DELTA, 00050 UNBUFFERED, 00051 }; 00052 00054 CO_API Object(); 00055 00057 CO_API virtual ~Object(); 00058 00062 bool isAttached() const { return _instanceID != EQ_INSTANCE_INVALID; } 00063 00068 LocalNodePtr getLocalNode(){ return _localNode; }; 00069 00071 const base::UUID& getID() const { return _id; } 00072 00074 uint32_t getInstanceID() const { return _instanceID; } 00075 00077 CO_API bool isBuffered() const; 00078 00082 CO_API bool isMaster() const; 00084 00088 virtual ChangeType getChangeType() const { return STATIC; } 00089 00099 CO_API virtual uint32_t chooseCompressor() const; 00100 00112 virtual bool isDirty() const { return true; } 00113 00149 CO_API uint128_t commit( const uint32_t incarnation = CO_COMMIT_NEXT ); 00150 00161 CO_API virtual uint32_t commitNB( const uint32_t incarnation ); 00162 00170 CO_API virtual uint128_t commitSync( const uint32_t commitID ); 00171 00182 CO_API void setAutoObsolete( const uint32_t count ); 00183 00185 CO_API uint32_t getAutoObsolete() const; 00186 00217 CO_API virtual uint128_t sync( const uint128_t& version = VERSION_HEAD); 00218 00220 CO_API uint128_t getHeadVersion() const; 00221 00223 CO_API uint128_t getVersion() const; 00224 00236 CO_API virtual void notifyNewHeadVersion( const uint128_t& version ); 00237 00242 virtual void notifyNewVersion() {} 00244 00252 virtual void getInstanceData( DataOStream& os ) = 0; 00253 00262 virtual void applyInstanceData( DataIStream& is ) = 0; 00263 00272 virtual void pack( DataOStream& os ) { getInstanceData( os ); } 00273 00279 virtual void unpack( DataIStream& is ) { applyInstanceData( is ); } 00281 00285 CO_API bool send( NodePtr node, ObjectPacket& packet ); 00286 00288 CO_API bool send( NodePtr node, ObjectPacket& packet, 00289 const std::string& string ); 00290 00292 CO_API bool send( NodePtr node, ObjectPacket& packet, 00293 const void* data, const uint64_t size ); 00295 00304 virtual void notifyAttached() {}; 00305 00313 CO_API virtual void notifyDetach(); 00315 00319 CO_API void setID( const base::UUID& identifier ); 00320 00322 uint32_t getMasterInstanceID() const; 00323 00325 NodePtr getMasterNode(); 00326 00328 void addSlave( Command& command, NodeMapObjectReplyPacket& reply ); 00329 void removeSlave( NodePtr node ); 00330 void setMasterNode( NodePtr node ); 00331 00332 void addInstanceDatas( const ObjectDataIStreamDeque&, const uint128_t&); 00333 00344 void setupChangeManager( const Object::ChangeType type, 00345 const bool master, LocalNodePtr localNode, 00346 const uint32_t masterInstanceID ); 00351 CO_API virtual void attach( const base::UUID& id, 00352 const uint32_t instanceID ); 00358 CO_API virtual void detach(); 00359 00361 void transfer( Object* from ); 00362 00363 void applyMapData( const uint128_t& version ); 00364 void sendInstanceData( Nodes& nodes ); 00365 00366 00367 protected: 00369 CO_API Object( const Object& ); 00370 00372 const Object& operator = ( const Object& ) { return *this; } 00373 00374 private: 00375 friend class DeltaMasterCM; 00376 friend class FullMasterCM; 00377 friend class MasterCM; 00378 friend class StaticMasterCM; 00379 friend class StaticSlaveCM; 00380 friend class UnbufferedMasterCM; 00381 friend class VersionedSlaveCM; 00382 00384 base::UUID _id; 00385 00387 LocalNodePtr _localNode; 00388 00390 uint32_t _instanceID; 00391 00393 ObjectCM* _cm; 00394 00395 void _setChangeManager( ObjectCM* cm ); 00396 const Nodes* _getSlaveNodes() const; 00397 00398 EQ_TS_VAR( _thread ); 00399 }; 00400 CO_API std::ostream& operator << ( std::ostream&, const Object& ); 00401 } 00402 00403 #endif // CO_OBJECT_H