Collage  1.6.0
High-performance C++ library for developing object-oriented distributed applications.
object.h
1 
2 /* Copyright (c) 2005-2016, Stefan Eilemann <eile@equalizergraphics.com>
3  * 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,
55  UNBUFFERED
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 uint128_t& identifier );
83 
85  CO_API const uint128_t& 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 CompressorInfo 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 LB_UNUSED ) {}
292 
302  virtual void applyInstanceData( DataIStream& is LB_UNUSED ) {}
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 = CO_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  CO_API 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 uint128_t& 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( const Nodes& nodes );
427 
428 
429 protected:
431  CO_API Object();
432 
434  Object& operator = ( const Object& ) { return *this; }
435 
437  CO_API explicit Object( const Object& );
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
virtual void notifyAttach()
Notify that this object will be registered or mapped.
Definition: object.h:352
virtual void notifyAttached()
Notify that this object has been registered or mapped.
Definition: object.h:362
A distributed object.
Definition: object.h:45
A class for sending commands and data to local & external objects.
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:90
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
virtual ChangeType getChangeType() const
Definition: object.h:103
virtual void notifyDetached()
Notify that this object has been deregistered or unmapped.
Definition: object.h:381
virtual void pack(DataOStream &os)
Serialize the modifications since the last call to commit().
Definition: object.h:313
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:86
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
Object-oriented network library.
Definition: barrier.h:27
use only instance data
Definition: object.h:53
non-versioned, unbuffered, static object.
Definition: object.h:52
virtual void notifyNewVersion()
Notification that a new version was received by a master object.
Definition: object.h:280
virtual uint64_t getMaxVersions() const
Limit the number of queued versions on slave instances.
Definition: object.h:123
virtual void getInstanceData(DataOStream &os)
Serialize all instance information of this distributed object.
Definition: object.h:291
virtual bool isDirty() const
Return if this object needs a commit.
Definition: object.h:149
Defines version macros and class for library Collage.
use pack/unpack delta
Definition: object.h:54
virtual void applyInstanceData(DataIStream &is)
Deserialize the instance data.
Definition: object.h:302
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:41
std::vector< NodePtr > Nodes
A vector of NodePtr&#39;s.
Definition: types.h:104
virtual void unpack(DataIStream &is)
Deserialize a change.
Definition: object.h:321
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:38