FREEDM DGI
StateCollection.hpp
Go to the documentation of this file.
1 
24 #ifndef CSTATECOLLECTION_HPP_
25 #define CSTATECOLLECTION_HPP_
26 
27 #include "PeerSets.hpp"
28 #include "IDGIModule.hpp"
29 #include "CPeerNode.hpp"
30 #include "messages/ModuleMessage.pb.h"
31 
32 #include <map>
33 #include <memory>
34 #include <vector>
35 
36 #include <boost/shared_ptr.hpp>
37 #include <boost/property_tree/ptree.hpp>
38 
39 namespace freedm
40 {
41 
42 namespace broker
43 {
44 
45 namespace sc
46 {
47 
48 using boost::property_tree::ptree;
49 
59 
60 class SCAgent
61  : public IDGIModule
62 {
63  public:
65  SCAgent();
66 
67  private:
68  //Marker structure
69  typedef std::pair< std::string, int > StateVersion;
70 
71  //Handler
73  void HandleAccept(CPeerNode peer);
74  void HandlePeerList(const gm::PeerListMessage& msg, CPeerNode peer);
75  void HandleRequest(const RequestMessage& msg, CPeerNode peer);
76  void HandleMarker(const MarkerMessage& msg, CPeerNode peer);
77  void HandleState(const StateMessage& msg, CPeerNode peer);
79  void HandleIncomingMessage(boost::shared_ptr<const ModuleMessage> msg, CPeerNode peer);
80 
81  //Internal
83  void Initiate();
85  void TakeSnapshot(const std::vector<std::string>& devicelist);
87  void SendStateBack();
89  void StateResponse();
91  void SaveForward(StateVersion latest, const MarkerMessage& msg);
92 
93  //Peer set operations
97  CPeerNode GetPeer(std::string uuid);
98 
100  static ModuleMessage PrepareForSending(
101  const StateCollectionMessage& message, std::string recipient = "sc");
102 
104  std::multimap<StateVersion, StateMessage> collectstate;
105  std::multimap<StateVersion, StateMessage>::iterator it;
106 
108  unsigned int m_countstate;
110  unsigned int m_countmarker;
112  unsigned int m_countdone;
113 
115  std::string m_scleader;
116 
119 
121  std::string m_module;
122 
123  //For multidevices state collection the following variables have to be changed
124  std::vector<std::string> m_device;
125 
127  StateVersion m_curversion;
129  StateMessage m_curstate;
130 
133 };
134 
135 } // namespace sc
136 
137 } // namespace broker
138 
139 } // namespace freedm
140 
141 #endif
142 
143 
StateVersion m_curversion
current version of marker
Definition: StateCollection.hpp:127
unsigned int m_countmarker
count number of marker
Definition: StateCollection.hpp:110
void HandleState(const StateMessage &msg, CPeerNode peer)
Definition: StateCollection.cpp:770
CPeerNode AddPeer(CPeerNode peer)
Add a peer to peer set from a pointer to a peer node object.
Definition: StateCollection.cpp:806
PeerSet m_AllPeers
all known peers
Definition: StateCollection.hpp:132
unsigned int m_countdone
count number of "Done" messages
Definition: StateCollection.hpp:112
Base interface for agents/broker modules.
Definition: CPeerNode.hpp:37
Definition: StateCollection.hpp:60
void Initiate()
Initiator starts state collection.
Definition: StateCollection.cpp:193
void HandleMarker(const MarkerMessage &msg, CPeerNode peer)
Definition: StateCollection.cpp:668
std::multimap< StateVersion, StateMessage > collectstate
collect states container and its iterator
Definition: StateCollection.hpp:104
void TakeSnapshot(const std::vector< std::string > &devicelist)
Save local state.
Definition: StateCollection.cpp:387
std::pair< std::string, int > StateVersion
Definition: StateCollection.hpp:69
SCAgent()
Constructor.
Definition: StateCollection.cpp:108
void StateResponse()
Initiator sends collected states back to the request module.
Definition: StateCollection.cpp:263
std::multimap< StateVersion, StateMessage >::iterator it
Definition: StateCollection.hpp:105
StateMessage m_curstate
current state
Definition: StateCollection.hpp:129
void HandleRequest(const RequestMessage &msg, CPeerNode peer)
Definition: StateCollection.cpp:622
static ModuleMessage PrepareForSending(const StateCollectionMessage &message, std::string recipient="sc")
Wraps a StateCollectionMessage in a ModuleMessage.
Definition: StateCollection.cpp:847
An interface for an object which can handle recieving incoming messages.
Definition: IDGIModule.hpp:36
unsigned int m_countstate
count number of states
Definition: StateCollection.hpp:108
void SaveForward(StateVersion latest, const MarkerMessage &msg)
Peer save local state and forward maker.
Definition: StateCollection.cpp:481
CPeerNode GetPeer(std::string uuid)
Get a pointer to a peer from UUID.
Definition: StateCollection.cpp:822
std::string m_module
module that request state collection
Definition: StateCollection.hpp:121
General FREEDM Namespace.
Definition: CBroker.cpp:53
void SendStateBack()
Peer sends collected states back to the initiator.
Definition: StateCollection.cpp:431
void HandleAccept(CPeerNode peer)
Handle receiving messages.
Definition: StateCollection.cpp:539
bool m_NotifyToSave
flag to indicate save channel message
Definition: StateCollection.hpp:118
std::vector< std::string > m_device
Definition: StateCollection.hpp:124
void HandlePeerList(const gm::PeerListMessage &msg, CPeerNode peer)
Definition: StateCollection.cpp:570
std::map< std::string, CPeerNode > PeerSet
Provides a PeerSet type for a module templated on T.
Definition: PeerSets.hpp:35
std::string m_scleader
save leader
Definition: StateCollection.hpp:115
void HandleIncomingMessage(boost::shared_ptr< const ModuleMessage > msg, CPeerNode peer)
Handles received messages.
Definition: StateCollection.cpp:124