6 #include <Poco/Clock.h>
7 #include <Poco/Event.h>
8 #include <Poco/Mutex.h>
9 #include <Poco/Timespan.h>
11 #include "loop/StoppableRunnable.h"
12 #include "loop/StopControl.h"
13 #include "server/GWSConnector.h"
14 #include "server/GWSListener.h"
15 #include "util/Loggable.h"
37 void setConnector(GWSConnector::Ptr connector);
50 void onTrySend(
const GWMessage::Ptr message)
override;
60 void onSent(
const GWMessage::Ptr message)
override;
62 void onResponse(
const GWResponse::Ptr response)
override;
63 void onAck(
const GWAck::Ptr ack)
override;
68 void onOther(
const GWMessage::Ptr message)
override;
71 typedef std::multimap<Poco::Clock, GWMessage::Ptr> WaitingList;
78 WaitingList::const_iterator
resendOrGet(
const Poco::Clock &now);
93 bool resendable(
const GWMessage::Ptr message)
const;
103 GWSConnector::Ptr m_connector;
104 Poco::Timespan m_resendTimeout;
105 WaitingList m_waiting;
106 std::map<GlobalID, WaitingList::iterator> m_refs;
107 std::set<GlobalID> m_pending;
110 Poco::FastMutex m_lock;
void run() override
Implement scheduler of the waiting messages.
Definition: GWSResender.cpp:39
void onOther(const GWMessage::Ptr message) override
Process GWSensorDataConfirm messages.
Definition: GWSResender.cpp:244
void setResendTimeout(const Poco::Timespan &timeout)
Configure timeout used to delay each resend.
Definition: GWSResender.cpp:31
WaitingList::const_iterator resendOrGet(const Poco::Clock &now)
Resend the oldest message waiting for resend if its timeout has expired.
Definition: GWSResender.cpp:83
void onAck(const GWAck::Ptr ack) override
When an ack is received, this event is fired.
Definition: GWSResender.cpp:201
void onTrySend(const GWMessage::Ptr message) override
Fire when a message is about to be sent to the server. After the send is successful (no network failu...
Definition: GWSResender.cpp:114
void stop() override
Definition: GWSResender.cpp:77
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
bool resendable(const GWMessage::Ptr message) const
Certain messages should be resended when there is no response/ack during the resendTimeout period...
Definition: GWSResender.cpp:250
WaitingList & waiting()
Definition: GWSResender.cpp:109
Definition: Loggable.h:19
void onSent(const GWMessage::Ptr message) override
Put the given message into the waiting list if it is re-sendable. After resendTimeout, such message is send again unless an appropriate response/ack has been delivered.
Definition: GWSResender.cpp:120
Definition: StoppableRunnable.h:8
void findAndDrop(const GWMessage::Ptr message)
Find the given message in the waiting list and remove it. Such message is considered as delivered or ...
Definition: GWSResender.cpp:266
GWSListener provides an interface for delivering of events and messages related to communication with...
Definition: GWSListener.h:19
Sending of messages via a GWSConnector might not be reliable. Messages that have been sent can never ...
Definition: GWSResender.h:30
void onResponse(const GWResponse::Ptr response) override
When a response is received, this event is fired.
Definition: GWSResender.cpp:187