ZG  "1.00
 All Classes Namespaces Files Functions Variables Enumerator Friends Macros Pages
NoteAssignmentsMap.h
Go to the documentation of this file.
1 #ifndef NoteAssignmentsMap_h
2 #define NoteAssignmentsMap_h
3 
4 #include "MusicData.h"
5 
6 namespace choir {
7 
10 {
11 public:
14 
17 
19  virtual void SetToDefaultState();
20 
22  virtual status_t SetFromArchive(const ConstMessageRef & archive);
23 
25  virtual status_t SaveToArchive(const MessageRef & archive) const;
26 
28  const Hashtable<ZGPeerID, uint64> & GetNoteAssignments() const {return _noteAssignments;}
29 
31  uint64 GetNoteAssignmentsForPeerID(const ZGPeerID & peerID) const {return _noteAssignments[peerID];}
32 
34  status_t SetNoteAssignmentsForPeerID(const ZGPeerID & peerID, uint64 newNotes);
35 
37  void UnassignNote(uint32 noteIdx);
38 
40  uint64 GetAllAssignedNotesChord() const {return _assignedNotes;}
41 
45  void SetAssignmentStrategy(uint32 strategy);
46 
48  uint32 GetAssignmentStrategy() const {return _assignmentStrategy;}
49 
51  virtual uint32 GetCurrentChecksum() const {return _checksum;}
52 
54  virtual uint32 CalculateChecksum() const;
55 
60  virtual ConstMessageRef SeniorUpdate(const ConstMessageRef & seniorDoMsg);
61 
66  virtual status_t JuniorUpdate(const ConstMessageRef & juniorDoMsg);
67 
69  status_t HandleToggleAssignmentMessage(const Message & msg);
70 
72  void PrintToStream() const;
73 
75  virtual String ToString() const;
76 
81  const Hashtable<uint8, uint32> & GetNoteHistogram() const {return _noteHistogram;}
82 
83 private:
84  uint32 CalculateChecksumForPeer(const ZGPeerID & peerID, uint64 chordValue) const {return peerID.CalculateChecksum()+CalculateChecksumForUint64(chordValue);}
85  const ZGPeerID & GetLightestPeer(const Hashtable<ZGPeerID, ConstMessageRef> & onlinePeers, uint32 & retCount) const;
86  const ZGPeerID & GetHeaviestPeer(const Hashtable<ZGPeerID, ConstMessageRef> & onlinePeers, uint32 & retCount) const;
87  void SetToDefaultStateAux();
88  void VerifyRunningChecksum(const char * desc) const; // just for debugging purposes
89  status_t SeniorAutoUpdateAssignments(uint64 allNotesChord, bool & retChangedAnything);
90 
91  // checksummed data
92  Hashtable<ZGPeerID, uint64> _noteAssignments;
93  uint32 _assignmentStrategy; // one of the ASSIGNMENT_STRATEGY_* values
94 
95  // metadata
96  Hashtable<uint8, uint32> _noteHistogram; // how many times each note is assigned to a peer
97  uint64 _assignedNotes; // bit-chord of currently assigned notes (computed from the histogram)
98  uint32 _checksum; // running checksum (so we don't have to recalculate it from scratch each time)
99 };
100 DECLARE_REFTYPES(NoteAssignmentsMap);
101 
102 }; // end namespace choir
103 
104 #endif
status_t HandleToggleAssignmentMessage(const Message &msg)
Updates this object based on the given CHOIR_COMMAND_TOGGLE_ASSIGNMENT Message's contents.
NoteAssignmentsMap()
Constructor.
A slight specialization of the IDatabaseObject class, just so I can add some application-specific hel...
Definition: MusicData.h:74
uint32 GetAssignmentStrategy() const
Returns the assignment strategy the system is using for bell-assignments.
const Hashtable< uint8, uint32 > & GetNoteHistogram() const
Returns a table that shows for each note currently in use, how many peers are currently assigned to p...
virtual String ToString() const
Returns a string representation of this object, for debugging purposes.
uint64 GetAllAssignedNotesChord() const
Returns a bit-chord showing which notes are currently assigned to at least one peer.
void PrintToStream() const
For debugging purposes.
status_t SetNoteAssignmentsForPeerID(const ZGPeerID &peerID, uint64 newNotes)
Sets the notes-chord for the given peer ID to the given value.
virtual ConstMessageRef SeniorUpdate(const ConstMessageRef &seniorDoMsg)
Updates our state as specified in the (seniorDoMsg).
void SetAssignmentStrategy(uint32 strategy)
Set the assignment strategy we want the system to use for bell-assignments.
~NoteAssignmentsMap()
Destructor.
void UnassignNote(uint32 noteIdx)
Un-assigns the specified note from everybody.
A ZGPeerID is a 128-bit integer that uniquely represents a particular peer in a ZG system...
Definition: ZGPeerID.h:18
virtual status_t SaveToArchive(const MessageRef &archive) const
Saves this map's current contents into (archive)
virtual uint32 CalculateChecksum() const
Recalculates our checksum from scratch (expensive!)
virtual status_t SetFromArchive(const ConstMessageRef &archive)
Replaces this map's current contents with the contents from (archive)
virtual status_t JuniorUpdate(const ConstMessageRef &juniorDoMsg)
Updates our state as specified in the (juniorDoMsg).
The choir namespace contains the code specific to the ZGChoir demonstration application.
Definition: ChoirNameSpace.h:7
const Hashtable< ZGPeerID, uint64 > & GetNoteAssignments() const
For a given peer, returns the chord of notes that peer should play.
virtual void SetToDefaultState()
Sets this object to its just-constructed state.
uint64 GetNoteAssignmentsForPeerID(const ZGPeerID &peerID) const
Returns the note-assignments currently specified for the given peer.
This object specifies which peers should be playing which notes.
virtual uint32 GetCurrentChecksum() const
Returns the checksum of this object (which is updated whenever this object's contents change) ...
uint32 CalculateChecksum() const
Returns a 32-bit checksum for this object.
Definition: ZGPeerID.h:104