FREEDM DGI
IProtocol.hpp
Go to the documentation of this file.
1 
24 #ifndef IPROTOCOL_HPP
25 #define IPROTOCOL_HPP
26 
27 #include "CGlobalConfiguration.hpp"
28 #include <memory>
29 #include <set>
30 
31 #include <boost/asio.hpp>
32 #include <boost/enable_shared_from_this.hpp>
33 #include <boost/noncopyable.hpp>
34 
35 namespace freedm {
36  namespace broker {
37 
38 class ModuleMessage;
39 class ProtocolMessage;
40 class ProtocolMessageWindow;
41 
43 class IProtocol
44  : private boost::noncopyable,
45  public boost::enable_shared_from_this<IProtocol>
46 {
47  public:
49  virtual ~IProtocol() { };
51  virtual void Send(const ModuleMessage& msg) = 0;
53  virtual void ReceiveACK(const ProtocolMessage& msg) = 0;
55  virtual bool Receive(const ProtocolMessage& msg) = 0;
57  virtual void OnReceive() = 0;
59  virtual void SendACK(const ProtocolMessage& msg) = 0;
61  virtual void Stop() = 0;
63  virtual void ChangePhase(bool) { };
65  bool GetStopped() { return m_stopped; };
67  void SetStopped(bool v) { m_stopped = v; };
69  boost::asio::ip::udp::socket& GetSocket();
71  void SetReliability(int r);
73  int GetReliability() const;
75  std::string GetUUID() const;
76  protected:
78  IProtocol(std::string uuid, boost::asio::ip::udp::endpoint endpoint);
80  virtual void WriteCallback(const boost::system::error_code&) { }
82  virtual void Write(ProtocolMessageWindow& msg);
83  private:
85  boost::asio::ip::udp::endpoint m_endpoint;
86 
88  std::string m_uuid;
89 
91  bool m_stopped;
92 
95 };
96 
97  }
98 }
99 
100 #endif
101 
A connection protocol.
Definition: IProtocol.hpp:43
std::string GetUUID() const
Gets the uuid:
Definition: IProtocol.cpp:129
boost::asio::ip::udp::socket & GetSocket()
Get a socket connected to a single peer DGI.
virtual void OnReceive()=0
Peforms an actions after finishing looking through a sliding window.
IProtocol(std::string uuid, boost::asio::ip::udp::endpoint endpoint)
Initializes the protocol with the underlying connection.
Definition: IProtocol.cpp:48
virtual ~IProtocol()
Destroy all humans.
Definition: IProtocol.hpp:49
bool m_stopped
Tracker for the stoppedness of the connection.
Definition: IProtocol.hpp:91
virtual void Stop()=0
Handles Stopping the timers etc.
virtual void ChangePhase(bool)
Handles the change phase even.
Definition: IProtocol.hpp:63
virtual void SendACK(const ProtocolMessage &msg)=0
Handles Writing an ack for the input message to the channel.
virtual bool Receive(const ProtocolMessage &msg)=0
Function that determines if a message should dispatched.
int m_reliability
The reliability of the connection (FOR -DCUSTOMNETWORK)
Definition: IProtocol.hpp:94
virtual void Send(const ModuleMessage &msg)=0
Public write to channel function.
void SetReliability(int r)
Set the connection reliability for DCUSTOMNETWORK.
Definition: IProtocol.cpp:144
General FREEDM Namespace.
Definition: CBroker.cpp:53
void SetStopped(bool v)
Handles setting the stopped variable.
Definition: IProtocol.hpp:67
int GetReliability() const
Get the connection reliability for DCUSTOMNETWORK.
Definition: IProtocol.cpp:158
virtual void WriteCallback(const boost::system::error_code &)
Callback for when a write completes.
Definition: IProtocol.hpp:80
boost::asio::ip::udp::endpoint m_endpoint
Datagram socket connected to a single peer DGI.
Definition: IProtocol.hpp:85
virtual void ReceiveACK(const ProtocolMessage &msg)=0
Public facing function that handles marking ACKS.
bool GetStopped()
Handles checking to see if the connection is stopped.
Definition: IProtocol.hpp:65
std::string m_uuid
The UUID of the remote endpoint for the connection.
Definition: IProtocol.hpp:88
virtual void Write(ProtocolMessageWindow &msg)
Handles writing the message to the underlying connection.
Definition: IProtocol.cpp:74