Collage
0.6.1
|
00001 00002 /* Copyright (c) 2005-2012, 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 00030 # define CO_COMMIT_NEXT LB_UNDEFINED_UINT32 //!< the next commit incarnation 00031 00039 class Object : public Dispatcher 00040 { 00041 public: 00043 enum ChangeType 00044 { 00045 NONE, 00046 STATIC, 00047 INSTANCE, 00048 DELTA, 00049 UNBUFFERED 00050 }; 00051 00053 CO_API Object(); 00054 00056 CO_API virtual ~Object(); 00057 00061 bool isAttached() const { return _instanceID != EQ_INSTANCE_INVALID; } 00062 00067 LocalNodePtr getLocalNode() { return _localNode; } 00068 00079 CO_API void setID( const UUID& identifier ); 00080 00082 const UUID& getID() const { return _id; } 00083 00085 uint32_t getInstanceID() const { return _instanceID; } 00086 00088 CO_API bool isBuffered() const; 00089 00093 CO_API bool isMaster() const; 00095 00099 virtual ChangeType getChangeType() const { return STATIC; } 00100 00119 virtual uint64_t getMaxVersions() const 00120 { return std::numeric_limits< uint64_t >::max(); } 00121 00131 CO_API virtual uint32_t chooseCompressor() const; 00132 00144 virtual bool isDirty() const { return true; } 00145 00163 CO_API void push( const uint128_t& groupID, const uint128_t& objectType, 00164 const Nodes& nodes ); 00165 00198 CO_API virtual uint128_t commit( const uint32_t incarnation = 00199 CO_COMMIT_NEXT ); 00200 00211 CO_API void setAutoObsolete( const uint32_t count ); 00212 00214 CO_API uint32_t getAutoObsolete() const; 00215 00246 CO_API virtual uint128_t sync( const uint128_t& version = VERSION_HEAD); 00247 00249 CO_API uint128_t getHeadVersion() const; 00250 00252 CO_API uint128_t getVersion() const; 00253 00267 CO_API virtual void notifyNewHeadVersion( const uint128_t& version ); 00268 00273 virtual void notifyNewVersion() {} 00275 00283 virtual void getInstanceData( DataOStream& os ) = 0; 00284 00293 virtual void applyInstanceData( DataIStream& is ) = 0; 00294 00303 virtual void pack( DataOStream& os ) { getInstanceData( os ); } 00304 00310 virtual void unpack( DataIStream& is ) { applyInstanceData( is ); } 00312 00316 CO_API bool send( NodePtr node, ObjectPacket& packet ); 00317 00319 CO_API bool send( NodePtr node, ObjectPacket& packet, 00320 const std::string& string ); 00321 00323 CO_API bool send( NodePtr node, ObjectPacket& packet, 00324 const void* data, const uint64_t size ); 00325 00327 template< class T > bool 00328 send( NodePtr node, ObjectPacket& packet, const std::vector<T>& v ); 00330 00338 virtual void notifyAttach() {} 00339 00347 virtual void notifyAttached() {} 00348 00356 CO_API virtual void notifyDetach(); 00357 00364 virtual void notifyDetached() {} 00366 00370 uint32_t getMasterInstanceID() const; 00371 00373 NodePtr getMasterNode(); 00374 00376 void addSlave( Command& command ); 00377 CO_API void removeSlave( NodePtr node, const uint32_t instanceID ); 00378 CO_API void removeSlaves( NodePtr node ); 00379 void setMasterNode( NodePtr node ); 00380 00381 void addInstanceDatas( const ObjectDataIStreamDeque&, const uint128_t&); 00382 00393 void setupChangeManager( const Object::ChangeType type, 00394 const bool master, LocalNodePtr localNode, 00395 const uint32_t masterInstanceID ); 00400 CO_API virtual void attach( const UUID& id, 00401 const uint32_t instanceID ); 00407 CO_API virtual void detach(); 00408 00410 void transfer( Object* from ); 00411 00412 void applyMapData( const uint128_t& version ); 00413 void sendInstanceData( Nodes& nodes ); 00414 00415 00416 protected: 00418 CO_API Object( const Object& ); 00419 00421 const Object& operator = ( const Object& ) { return *this; } 00422 00423 private: 00424 friend class DeltaMasterCM; 00425 friend class FullMasterCM; 00426 friend class VersionedMasterCM; 00427 friend class ObjectCM; 00428 friend class StaticMasterCM; 00429 friend class StaticSlaveCM; 00430 friend class UnbufferedMasterCM; 00431 friend class VersionedSlaveCM; 00432 00434 UUID _id; 00435 00437 LocalNodePtr _localNode; 00438 00440 uint32_t _instanceID; 00441 00443 ObjectCM* _cm; 00444 00445 void _setChangeManager( ObjectCM* cm ); 00446 00447 LB_TS_VAR( _thread ); 00448 }; 00449 CO_API std::ostream& operator << ( std::ostream&, const Object& ); 00450 00451 template< class T > inline bool 00452 Object::send( NodePtr node, ObjectPacket& packet, const std::vector<T>& v ) 00453 { 00454 LBASSERT( isAttached() ); 00455 packet.objectID = _id; 00456 return node->send( packet, v ); 00457 } 00458 } 00459 00460 #endif // CO_OBJECT_H