ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
ChoirSession.h
Go to the documentation of this file.
1 #ifndef ChoirSession_h
2 #define ChoirSession_h
3 
5 #include "MusicData.h"
6 
7 namespace choir {
8 
9 class MusicSheet;
10 class PlaybackState;
11 class NoteAssignmentsMap;
12 
15 {
16 public:
20  ChoirSession(const ZGPeerSettings & peerSettings);
21 
22  // PulseNode interface
23  virtual uint64 GetPulseTime(const PulseArgs & args);
24  virtual void Pulse(const PulseArgs & args);
25 
32  void SendMessageToGUI(const ConstMessageRef & msg, bool allowReviewTrigger, bool force = false);
33 
38  void SetReviewResults(uint64 allNotesAtLastReview);
39 
40 protected:
41  // ZGDatabasePeerSession interface
42  IDatabaseObjectRef CreateDatabaseObject(uint32 whichDatabase);
43 
44  // ZGPeerSession interface
45  virtual void PeerHasComeOnline(const ZGPeerID & peerID, const ConstMessageRef & peerInfo);
46  virtual void PeerHasGoneOffline(const ZGPeerID & peerID, const ConstMessageRef & peerInfo);
47  virtual void SeniorPeerChanged(const ZGPeerID & oldSeniorPeerID, const ZGPeerID & newSeniorPeerID);
48 
54  virtual void MessageReceivedFromSession(AbstractReflectSession & from, const MessageRef & msg, void * userData);
55 
56 private:
57  bool IsStrategyReviewMaybeNecessary() const;
58  status_t SendPeerOnlineOfflineMessageToGUI(uint32 whatCode, const ZGPeerID & id, const ConstMessageRef & optPeerInfo);
59  ConstMessageRef GenerateLatenciesMessage() const;
60 
61  MusicSheet & GetMusicSheet();
62  PlaybackState & GetPlaybackState();
63  NoteAssignmentsMap & GetNoteAssignmentsMap();
64 
65  const MusicSheet & GetMusicSheet() const;
66  const PlaybackState & GetPlaybackState() const;
67  const NoteAssignmentsMap & GetNoteAssignmentsMap() const;
68 
69  bool _requestAssignmentStrategyReviewPending;
70  uint64 _allNotesAtLastReview;
71  Hashtable<ZGPeerID, ConstMessageRef> _peersAtLastReview;
72 
73  uint64 _nextSendLatenciesTime;
74 };
75 DECLARE_REFTYPES(ChoirSession);
76 
77 }; // end namespace choir
78 
79 #endif
This immutable class holds various read-only settings that will be used to define the peer's behavior...
void SendMessageToGUI(const ConstMessageRef &msg, bool allowReviewTrigger, bool force=false)
Sends the specified message to the GUI thread so the GUI will update its visible state to match ours...
This object holds the state of how the currently-in-memory Music sheet should be performed over time...
Definition: PlaybackState.h:9
virtual void PeerHasGoneOffline(const ZGPeerID &peerID, const ConstMessageRef &peerInfo)
Called when a peer has left our group.
This is a convenience class; it is the same as a ZGPeerSession except that it also knows how to creat...
virtual void PeerHasComeOnline(const ZGPeerID &peerID, const ConstMessageRef &peerInfo)
Called when a new peer has joined our group.
virtual void Pulse(const PulseArgs &args)
Called at (approximately) the time specified by GetPulseTime().
ChoirSession(const ZGPeerSettings &peerSettings)
Constructor.
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
Definition: ZGPeerID.h:18
virtual void MessageReceivedFromSession(AbstractReflectSession &from, const MessageRef &msg, void *userData)
Called when a Message object has been received from a fellow session on the same ReflectServer.
virtual uint64 GetPulseTime(const PulseArgs &args)
Returns the time (in microseconds, using the timebase of GetRunTime64()) when Pulse() should next be ...
virtual void SeniorPeerChanged(const ZGPeerID &oldSeniorPeerID, const ZGPeerID &newSeniorPeerID)
Called when the senior peer of our peer group has changed.
MusicSheet
Definition: MusicSheet.h:107
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
void SetReviewResults(uint64 allNotesAtLastReview)
Called to set what the results of the last notes-assignments review was.
This object is the in-memory representation of a song, as a collection of notes over time...
Definition: MusicSheet.h:9
This is the class that that the Choir demo uses to implement its data-replication functionality...
Definition: ChoirSession.h:14
This object specifies which peers should be playing which notes.
IDatabaseObjectRef CreateDatabaseObject(uint32 whichDatabase)
This will be called as part of the startup sequence.