ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
IDatabaseObject.h
Go to the documentation of this file.
1 #ifndef IDatabaseObject_h
2 #define IDatabaseObject_h
3 
4 #include "util/RefCount.h"
6 #include "zg/ZGNameSpace.h"
7 
8 namespace zg
9 {
10 
12 
14 class IDatabaseObject : public RefCountable, public INetworkTimeProvider
15 {
16 public:
18  IDatabaseObject() : _session(NULL) {/* empty */}
19 
21  virtual ~IDatabaseObject() {/* empty */}
22 
24  virtual void SetToDefaultState() = 0;
25 
30  virtual status_t SetFromArchive(const ConstMessageRef & archive) = 0;
31 
36  virtual status_t SaveToArchive(const MessageRef & archive) const = 0;
37 
45  virtual uint32 GetCurrentChecksum() const = 0;
46 
53  virtual uint32 CalculateChecksum() const = 0;
54 
64  virtual ConstMessageRef SeniorUpdate(const ConstMessageRef & seniorDoMsg) = 0;
65 
71  virtual status_t JuniorUpdate(const ConstMessageRef & juniorDoMsg) = 0;
72 
78  virtual String ToString() const = 0;
79 
86 
88  const ZGDatabasePeerSession * GetDatabasePeerSession() const {return _session;}
89 
90 protected:
96  const IDatabaseObject * GetDatabaseObject(uint32 whichDatabase) const;
97 
102  bool IsPeerOnline(const ZGPeerID & pid) const;
103 
107  const Hashtable<ZGPeerID, ConstMessageRef> & GetOnlinePeers() const;
108 
110  virtual uint64 GetNetworkTime64() const;
111 
115  virtual uint64 GetRunTime64ForNetworkTime64(uint64 networkTime64TimeStamp) const;
116 
120  virtual uint64 GetNetworkTime64ForRunTime64(uint64 runTime64TimeStamp) const;
121 
125  virtual int64 GetToNetworkTimeOffset() const;
126 
127 private:
128  friend class ZGDatabasePeerSession;
129 
130  ZGDatabasePeerSession * _session;
131 };
132 DECLARE_REFTYPES(IDatabaseObject);
133 
134 }; // end namespace zg
135 
136 #endif
This is an abstract interface for an object that can provide us with network-clock-time values...
An interface for an object that represents the full contents of a ZG database.
const ZGDatabasePeerSession * GetDatabasePeerSession() const
As above, but returns a const/read-only pointer.
const Hashtable< ZGPeerID, ConstMessageRef > & GetOnlinePeers() const
Returns a table of the currently online peers (and their attributes), or an empty table if we have no...
virtual uint64 GetNetworkTime64ForRunTime64(uint64 runTime64TimeStamp) const
Returns the network time corresponding to a given local time, or 0 if we have no ZGDatabasePeerSessio...
virtual uint32 CalculateChecksum() const =0
This method should be implemented to recalculate the database's current checksum from scratch...
virtual status_t SaveToArchive(const MessageRef &archive) const =0
Should be implemented to save this object's entire state into (archive).
virtual ConstMessageRef SeniorUpdate(const ConstMessageRef &seniorDoMsg)=0
Should update this object's state using the passed-in senior-do-Message (whose semantics are left up ...
This is a convenience class; it is the same as a ZGPeerSession except that it also knows how to creat...
virtual void SetToDefaultState()=0
Should be implemented to set this object to its default/just-default-constructed state.
The zg namespace contains the public API of the ZG library.
virtual uint64 GetRunTime64ForNetworkTime64(uint64 networkTime64TimeStamp) const
Returns the local time corresponding to a given network time, or 0 if we have no ZGDatabasePeerSessio...
IDatabaseObject()
Default Constructor.
virtual status_t JuniorUpdate(const ConstMessageRef &juniorDoMsg)=0
Should update this object's state using the passed-in junior-do-Messsage (that was previously returne...
virtual status_t SetFromArchive(const ConstMessageRef &archive)=0
Should be implemented to replace this object's entire state with the state contained in (archive) ...
virtual ~IDatabaseObject()
Destructor.
virtual int64 GetToNetworkTimeOffset() const
Returns the number of microseconds that should be added to a GetRunTime64() value to turn it into a G...
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
Definition: ZGPeerID.h:18
virtual uint64 GetNetworkTime64() const
Returns the current network time, or 0 if we have no ZGDatabasePeerSession.
virtual String ToString() const =0
Should return this object's state as a human-readable string.
bool IsPeerOnline(const ZGPeerID &pid) const
Returns true iff the peer with the specified ID is currently on line.
virtual uint32 GetCurrentChecksum() const =0
Should return the current checksum of this object.
const IDatabaseObject * GetDatabaseObject(uint32 whichDatabase) const
Returns a read-only pointer to the specified IDatabaseObject held by our ZGDatabasePeerSession, or NULL if we don't have a ZGDatabasePeerSession or if the specified database doesn't exist.
ZGDatabasePeerSession * GetDatabasePeerSession()
Returns a pointer to the ZGDatabasePeerSession object that created us, or NULL if this object was not...