Collage  1.0.1
Object-Oriented C++ Network Library
object.h
1 
2 /* Copyright (c) 2005-2013, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2011-2012, Daniel Nachbaur <danielnachbaur@gmail.com>
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef CO_OBJECT_H
22 #define CO_OBJECT_H
23 
24 #include <co/dispatcher.h> // base class
25 #include <co/localNode.h> // used in RefPtr
26 #include <co/types.h> // for Nodes
27 #include <co/version.h> // used as default parameter
28 #include <lunchbox/bitOperation.h> // byteswap inline impl
29 
30 namespace co
31 {
32 namespace detail { class Object; }
33 class ObjectCM;
34 typedef lunchbox::RefPtr< ObjectCM > ObjectCMPtr;
35 
36 # define CO_COMMIT_NEXT LB_UNDEFINED_UINT32
37 
38 
45 class Object : public Dispatcher
46 {
47 public:
50  {
51  NONE,
56  };
57 
59  CO_API virtual ~Object();
60 
67  CO_API bool isAttached() const;
68 
70  CO_API LocalNodePtr getLocalNode();
71 
82  CO_API void setID( const UUID& identifier );
83 
85  CO_API const UUID& getID() const;
86 
88  CO_API uint32_t getInstanceID() const;
89 
91  CO_API bool isBuffered() const;
92 
97  CO_API bool isMaster() const;
99 
103  virtual ChangeType getChangeType() const { return STATIC; }
104 
123  virtual uint64_t getMaxVersions() const
124  { return std::numeric_limits< uint64_t >::max(); }
125 
135  CO_API virtual uint32_t chooseCompressor() const;
136 
149  virtual bool isDirty() const { return true; }
150 
169  CO_API void push( const uint128_t& groupID, const uint128_t& objectType,
170  const Nodes& nodes );
171 
205  CO_API virtual uint128_t commit( const uint32_t incarnation =
206  CO_COMMIT_NEXT );
207 
217  CO_API void setAutoObsolete( const uint32_t count );
218 
220  CO_API uint32_t getAutoObsolete() const;
221 
252  CO_API virtual uint128_t sync( const uint128_t& version = VERSION_HEAD );
253 
255  CO_API uint128_t getHeadVersion() const;
256 
258  CO_API uint128_t getVersion() const;
259 
273  CO_API virtual void notifyNewHeadVersion( const uint128_t& version );
274 
280  virtual void notifyNewVersion() {}
282 
291  virtual void getInstanceData( DataOStream& os ) = 0;
292 
302  virtual void applyInstanceData( DataIStream& is ) = 0;
303 
313  virtual void pack( DataOStream& os ) { getInstanceData( os ); }
314 
321  virtual void unpack( DataIStream& is ) { applyInstanceData( is ); }
323 
340  CO_API ObjectOCommand send( NodePtr node, const uint32_t cmd,
341  const uint32_t instanceID = EQ_INSTANCE_ALL );
343 
352  virtual void notifyAttach() {}
353 
362  virtual void notifyAttached() {}
363 
372  CO_API virtual void notifyDetach();
373 
381  virtual void notifyDetached() {}
383 
387  uint32_t getMasterInstanceID() const;
388 
390  NodePtr getMasterNode();
391 
393  CO_API void removeSlave( NodePtr node, const uint32_t instanceID );
394  CO_API void removeSlaves( NodePtr node );
395  void setMasterNode( NodePtr node );
396 
397  void addInstanceDatas( const ObjectDataIStreamDeque&, const uint128_t&);
398 
409  void setupChangeManager( const Object::ChangeType type,
410  const bool master, LocalNodePtr localNode,
411  const uint32_t masterInstanceID );
412 
414  CO_API virtual void attach( const UUID& id,
415  const uint32_t instanceID );
420  CO_API virtual void detach();
421 
423  void transfer( Object* from );
424 
425  void applyMapData( const uint128_t& version );
426  void sendInstanceData( Nodes& nodes );
427 
428 
429 protected:
431  CO_API Object();
432 
434  CO_API Object( const Object& );
435 
437  const Object& operator = ( const Object& ) { return *this; }
438 
439 private:
440  detail::Object* const impl_;
441  void _setChangeManager( ObjectCMPtr cm );
442 
443  ObjectCMPtr _getChangeManager();
444  friend class ObjectStore;
445 
446  LB_TS_VAR( _thread );
447 };
448 
450 CO_API std::ostream& operator << ( std::ostream&, const Object& );
451 
453 CO_API std::ostream& operator << ( std::ostream&,const Object::ChangeType&);
454 }
455 
456 namespace lunchbox
457 {
458 template<> inline void byteswap( co::Object::ChangeType& value )
459 { byteswap( reinterpret_cast< uint32_t& >( value )); }
460 }
461 #endif // CO_OBJECT_H
CO_API bool isMaster() const
non-versioned, unbuffered, static object.
Definition: object.h:52
CO_API uint32_t getInstanceID() const
CO_API bool isAttached() const
virtual void pack(DataOStream &os)
Serialize the modifications since the last call to commit().
Definition: object.h:313
const Object & operator=(const Object &)
NOP assignment operator.
Definition: object.h:437
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:38
use only instance data
Definition: object.h:53
virtual ChangeType getChangeType() const
Definition: object.h:103
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:84
A class for sending commands and data to local &amp; external objects.
virtual CO_API void notifyDetach()
Notify that this object will be deregistered or unmapped.
virtual bool isDirty() const
Return if this object needs a commit.
Definition: object.h:149
CO_API LocalNodePtr getLocalNode()
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
virtual CO_API uint128_t commit(const uint32_t incarnation=CO_COMMIT_NEXT)
Commit a new version of this object.
CO_API Object()
Construct a new distributed object.
virtual CO_API uint32_t chooseCompressor() const
Return the compressor to be used for data transmission.
CO_API uint128_t getVersion() const
CO_API ObjectOCommand send(NodePtr node, const uint32_t cmd, const uint32_t instanceID=EQ_INSTANCE_ALL)
Send a command with optional data to object instance(s) on another node.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:80
use pack/unpack delta
Definition: object.h:54
virtual void notifyAttach()
Notify that this object will be registered or mapped.
Definition: object.h:352
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:40
virtual uint64_t getMaxVersions() const
Limit the number of queued versions on slave instances.
Definition: object.h:123
virtual void notifyDetached()
Notify that this object has been deregistered or unmapped.
Definition: object.h:381
virtual CO_API uint128_t sync(const uint128_t &version=VERSION_HEAD)
Sync to a given version.
A distributed object.
Definition: object.h:45
virtual CO_API ~Object()
Destruct the distributed object.
CO_API uint128_t getHeadVersion() const
CO_API void setAutoObsolete(const uint32_t count)
Automatically obsolete old versions.
CO_API uint32_t getAutoObsolete() const
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:46
virtual void getInstanceData(DataOStream &os)=0
Serialize all instance information of this distributed object.
virtual void applyInstanceData(DataIStream &is)=0
Deserialize the instance data.
versioned, but don&#39;t retain versions
Definition: object.h:55
virtual void notifyAttached()
Notify that this object has been registered or mapped.
Definition: object.h:362
std::vector< NodePtr > Nodes
A vector of NodePtr&#39;s.
Definition: types.h:98
CO_API void setID(const UUID &identifier)
Set the object&#39;s unique identifier.
virtual void notifyNewVersion()
Notification that a new version was received by a master object.
Definition: object.h:280
virtual CO_API void notifyNewHeadVersion(const uint128_t &version)
Notification that a new head version was received by a slave object.
CO_API const UUID & getID() const
virtual void unpack(DataIStream &is)
Deserialize a change.
Definition: object.h:321
CO_API void push(const uint128_t &groupID, const uint128_t &objectType, const Nodes &nodes)
Push the instance data of the object to the given nodes.