3 #include <Poco/Clock.h>
4 #include <Poco/Mutex.h>
6 #include "core/DeviceCache.h"
7 #include "core/Distributor.h"
8 #include "core/PollableDevice.h"
9 #include "loop/StoppableRunnable.h"
10 #include "loop/StopControl.h"
11 #include "util/AsyncExecutor.h"
12 #include "util/Loggable.h"
24 typedef Poco::SharedPtr<DevicePoller> Ptr;
28 void setDistributor(Distributor::Ptr distributor);
29 void setPollExecutor(AsyncExecutor::Ptr executor);
47 PollableDevice::Ptr device,
48 const Poco::Clock &now = {});
79 static Poco::Timespan
grabRefresh(
const PollableDevice::Ptr device);
86 PollableDevice::Ptr device,
87 const Poco::Clock &now = {});
95 PollableDevice::Ptr device,
96 const Poco::Clock &now = {});
110 void doPoll(PollableDevice::Ptr device);
113 Distributor::Ptr m_distributor;
114 AsyncExecutor::Ptr m_pollExecutor;
115 Poco::Timespan m_warnThreshold;
117 typedef std::multimap<Poco::Clock, PollableDevice::Ptr> Schedule;
119 std::map<DeviceID, Schedule::const_iterator> m_devices;
120 std::set<DeviceID> m_active;
121 Poco::FastMutex m_lock;
void doPoll(PollableDevice::Ptr device)
Invoke the PollableDevice::poll() method via the configured m_pollExecutor. Thus, the poll() is usual...
Definition: DevicePoller.cpp:205
Poco::Timespan pollNextIfOnSchedule(const Poco::Clock &now={})
Check the next device to be polled. If the next device is scheduled into the future, return the time difference. Otherwise return 0 as the device is currently polled.
Definition: DevicePoller.cpp:187
void stop() override
Stop polling of devices.
Definition: DevicePoller.cpp:239
void schedule(PollableDevice::Ptr device, const Poco::Clock &now={})
Schedule the given device relatively to the given time reference (usually meaning now)...
Definition: DevicePoller.cpp:52
void cancel(const DeviceID &id)
Cancel the device of the given ID if exists. If the device is currently being polled, it would not be interrupted but its will not be rescheduled.
Definition: DevicePoller.cpp:91
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void cleanup()
Remove all scheduled devices (kind of reset).
Definition: DevicePoller.cpp:244
DevicePoller is a scheduler for PollableDevice instances. Any number of devices can be scheduled for ...
Definition: DevicePoller.h:22
Definition: Loggable.h:19
void setWarnThreshold(const Poco::Timespan &threshold)
Configure time threshold that would enable to fire a warning about a too slow device. Polling of device should take longer (or much longer) than its refresh time.
Definition: DevicePoller.cpp:34
void reschedule(PollableDevice::Ptr device, const Poco::Clock &now={})
Reschedule device after its PollableDevice::poll() method has been called. Only active devices are re...
Definition: DevicePoller.cpp:112
void doSchedule(PollableDevice::Ptr device, const Poco::Clock &now={})
Do the actual scheduling - registration into m_devices, and m_schedule containers. If the devices is already scheduled, its previous record is just updated. Not thread-safe.
Definition: DevicePoller.cpp:73
Definition: StoppableRunnable.h:8
Definition: DeviceID.h:17
static Poco::Timespan grabRefresh(const PollableDevice::Ptr device)
Get refresh time of the device and check whether it is usable for regular polling. If it is not, throw an exception.
Definition: DevicePoller.cpp:39
void run() override
Poll devices according to the schedule.
Definition: DevicePoller.cpp:138