6 #include <Poco/Clock.h>
7 #include <Poco/SharedPtr.h>
8 #include <Poco/Timespan.h>
10 #include "core/CommandSender.h"
11 #include "core/DeviceStatusHandler.h"
12 #include "loop/StoppableRunnable.h"
13 #include "loop/StopControl.h"
14 #include "util/Loggable.h"
29 typedef Poco::SharedPtr<DeviceStatusFetcher> Ptr;
71 typedef Poco::AutoPtr<PrefixAnswer> Ptr;
117 bool shouldRepeat(
const Poco::Timespan &repeatTimeout)
const;
120 Poco::Clock m_lastRequested;
155 const PrefixAnswer::Ptr answer)
const;
167 PrefixAnswer::Ptr answer,
168 std::set<DeviceStatusHandler::Ptr> handler);
176 std::set<DeviceID> &paired,
177 const std::vector<DeviceID> &received,
182 Poco::Timespan m_idleDuration;
183 Poco::Timespan m_waitTimeout;
184 Poco::Timespan m_repeatTimeout;
185 std::map<DevicePrefix, std::set<DeviceStatusHandler::Ptr>> m_handlers;
186 std::map<DevicePrefix, PrefixStatus> m_status;
std::set< DeviceStatusHandler::Ptr > matchHandlers(const PrefixAnswer::Ptr answer) const
Definition: DeviceStatusFetcher.cpp:191
Definition: AnswerQueue.h:22
To simplify Answer management, include the prefix of the connected ServerDeviceListCommand inside the...
Definition: DeviceStatusFetcher.h:69
void collectPaired(std::set< DeviceID > &paired, const std::vector< DeviceID > &received, const DevicePrefix &prefix) const
Process paired devices as given in a single Answer result. Only devices matching the given prefix wou...
Definition: DeviceStatusFetcher.cpp:338
FetchStatus
Denote certain situations of the status fetching.
Definition: DeviceStatusFetcher.h:128
void setIdleDuration(const Poco::Timespan &duration)
Set duration how long to sleep while there is nothing to do.
Definition: DeviceStatusFetcher.cpp:82
void registerHandler(DeviceStatusHandler::Ptr handler)
Register the given device status handler. The DeviceStatusFetcher would request a remote pairing regi...
Definition: DeviceStatusFetcher.cpp:106
bool needsRequest() const
Definition: DeviceStatusFetcher.cpp:58
void setRepeatTimeout(const Poco::Timespan &timeout)
Set timeout to wait until a request is re-issued after its unsuccessful finish (Answer was not fully ...
Definition: DeviceStatusFetcher.cpp:98
void startRequest()
Update the status of an associated prefix that the request for the associated prefix has been initiat...
Definition: DeviceStatusFetcher.cpp:44
void deliverResponse(bool successful)
Update the status of an associated prefix that an appropriate response has been delivered. The parameter denotes whether the response has been fully successful or not. This influences whether the request would be repeated.
Definition: DeviceStatusFetcher.cpp:51
DeviceStatusFetcher is responsible for fetching pairing state of devices for the registered status ha...
Definition: DeviceStatusFetcher.h:24
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void clearHandlers()
Unregister all registered device status handlers.
Definition: DeviceStatusFetcher.cpp:115
Definition: CommandSender.h:20
Definition: Loggable.h:19
void stop() override
Definition: DeviceStatusFetcher.cpp:363
bool shouldRepeat(const Poco::Timespan &repeatTimeout) const
When the response was not fully successful, the request should be repeated. However, we do not want to DoS the remote server. Thus, the repeated requested would be performed after the given repeat timeout. The method returns true only, if the last response was not fully successful and the timeout exceeded sice the last request.
Definition: DeviceStatusFetcher.cpp:63
FetchStatus fetchUndone()
Determine status handlers for which no fully successful request was made and dispatch ServerDeviceLis...
Definition: DeviceStatusFetcher.cpp:120
Definition: StoppableRunnable.h:8
void processAnswer(PrefixAnswer::Ptr answer, std::set< DeviceStatusHandler::Ptr > handler)
Process results of the given answer and the matching status handler. When any of the results is unsuc...
Definition: DeviceStatusFetcher.cpp:275
Definition: DeviceStatusFetcher.h:83
PrefixAnswer::Ptr handleDirtyAnswer(Answer::Ptr answer)
Check status of the given answer and if it is not pending and castable to PrefixAnswer, it performs cast and returns it.
Definition: DeviceStatusFetcher.cpp:161
void setWaitTimeout(const Poco::Timespan &timeout)
Set timeout for AnswerQueue::wait() call.
Definition: DeviceStatusFetcher.cpp:90