Collage  1.7.0
High-performance C++ library for developing object-oriented distributed applications.
object.h
1 
2 /* Copyright (c) 2005-2017, 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 
29 namespace co
30 {
31 namespace detail
32 {
33 class Object;
34 }
35 class ObjectCM;
36 typedef lunchbox::RefPtr<ObjectCM> ObjectCMPtr;
37 
38 #define CO_COMMIT_NEXT LB_UNDEFINED_UINT32
39 
40 
47 class Object : public Dispatcher
48 {
49 public:
52  {
53  NONE,
57  UNBUFFERED
58  };
59 
61  CO_API virtual ~Object();
62 
69  CO_API bool isAttached() const;
70 
72  CO_API LocalNodePtr getLocalNode();
73 
84  CO_API void setID(const uint128_t& identifier);
85 
87  CO_API const uint128_t& getID() const;
88 
90  CO_API uint32_t getInstanceID() const;
91 
93  CO_API bool isBuffered() const;
94 
99  CO_API bool isMaster() const;
101 
105  virtual ChangeType getChangeType() const { return STATIC; }
124  virtual uint64_t getMaxVersions() const
125  {
126  return std::numeric_limits<uint64_t>::max();
127  }
128 
138  CO_API virtual CompressorInfo chooseCompressor() const;
139 
152  virtual bool isDirty() const { return true; }
171  CO_API void push(const uint128_t& groupID, const uint128_t& objectType,
172  const Nodes& nodes);
173 
207  CO_API virtual uint128_t commit(
208  const uint32_t incarnation = CO_COMMIT_NEXT);
209 
219  CO_API void setAutoObsolete(const uint32_t count);
220 
222  CO_API uint32_t getAutoObsolete() const;
223 
254  CO_API virtual uint128_t sync(const uint128_t& version = VERSION_HEAD);
255 
257  CO_API uint128_t getHeadVersion() const;
258 
260  CO_API uint128_t getVersion() const;
261 
275  CO_API virtual void notifyNewHeadVersion(const uint128_t& version);
276 
282  virtual void notifyNewVersion() {}
284 
293  virtual void getInstanceData(DataOStream& os LB_UNUSED) {}
303  virtual void applyInstanceData(DataIStream& is LB_UNUSED) {}
313  virtual void pack(DataOStream& os) { getInstanceData(os); }
320  virtual void unpack(DataIStream& is) { applyInstanceData(is); }
322 
339  CO_API ObjectOCommand send(NodePtr node, const uint32_t cmd,
340  const uint32_t instanceID = CO_INSTANCE_ALL);
342 
351  virtual void notifyAttach() {}
360  virtual void notifyAttached() {}
369  CO_API virtual void notifyDetach();
370 
378  virtual void notifyDetached() {}
380 
384  uint32_t getMasterInstanceID() const;
385 
387  CO_API NodePtr getMasterNode();
388 
390  CO_API void removeSlave(NodePtr node, const uint32_t instanceID);
391  CO_API void removeSlaves(NodePtr node);
392  void setMasterNode(NodePtr node);
393 
394  void addInstanceDatas(const ObjectDataIStreamDeque&, const uint128_t&);
395 
406  void setupChangeManager(const Object::ChangeType type, const bool master,
407  LocalNodePtr localNode,
408  const uint32_t masterInstanceID);
409 
411  CO_API virtual void attach(const uint128_t& id, const uint32_t instanceID);
416  CO_API virtual void detach();
417 
419  void transfer(Object* from);
420 
421  void applyMapData(const uint128_t& version);
422  void sendInstanceData(const Nodes& nodes);
423 
424 
425 protected:
427  CO_API Object();
428 
430  Object& operator=(const Object&) { return *this; }
432  CO_API explicit Object(const Object&);
433 
434 private:
435  detail::Object* const impl_;
436  void _setChangeManager(ObjectCMPtr cm);
437 
438  ObjectCMPtr _getChangeManager();
439  friend class ObjectStore;
440 
441  LB_TS_VAR(_thread);
442 };
443 
445 CO_API std::ostream& operator<<(std::ostream&, const Object&);
446 
448 CO_API std::ostream& operator<<(std::ostream&, const Object::ChangeType&);
449 }
450 
451 #endif // CO_OBJECT_H
virtual void notifyAttach()
Notify that this object will be registered or mapped.
Definition: object.h:351
virtual void notifyAttached()
Notify that this object has been registered or mapped.
Definition: object.h:360
A distributed object.
Definition: object.h:47
A class for sending commands and data to local & external objects.
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:89
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:51
virtual ChangeType getChangeType() const
Definition: object.h:105
virtual void notifyDetached()
Notify that this object has been deregistered or unmapped.
Definition: object.h:378
virtual void pack(DataOStream &os)
Serialize the modifications since the last call to commit().
Definition: object.h:313
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:56
Object-oriented network library.
Definition: barrier.h:27
use only instance data
Definition: object.h:55
non-versioned, unbuffered, static object.
Definition: object.h:54
virtual void notifyNewVersion()
Notification that a new version was received by a master object.
Definition: object.h:282
virtual uint64_t getMaxVersions() const
Limit the number of queued versions on slave instances.
Definition: object.h:124
virtual void getInstanceData(DataOStream &os)
Serialize all instance information of this distributed object.
Definition: object.h:293
std::vector< NodePtr > Nodes
A vector of NodePtr&#39;s.
Definition: types.h:103
virtual bool isDirty() const
Return if this object needs a commit.
Definition: object.h:152
Defines version macros and class for library Collage.
use pack/unpack delta
Definition: object.h:56
Object & operator=(const Object &)
NOP assignment operator.
Definition: object.h:430
virtual void applyInstanceData(DataIStream &is)
Deserialize the instance data.
Definition: object.h:303
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:45
virtual void unpack(DataIStream &is)
Deserialize a change.
Definition: object.h:320
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:85
A class providing command dispatch functionality to networked objects.
Definition: dispatcher.h:41