BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
DevicePoller is a scheduler for PollableDevice instances. Any number of devices can be scheduled for regular polling of their state. Each device can be scheduled according to its refresh time and later cancelled from being polled. More...
#include <DevicePoller.h>
Public Types | |
typedef Poco::SharedPtr < DevicePoller > | Ptr |
Public Types inherited from BeeeOn::StoppableRunnable | |
typedef Poco::SharedPtr < StoppableRunnable > | Ptr |
Public Member Functions | |
void | setDistributor (Distributor::Ptr distributor) |
void | setPollExecutor (AsyncExecutor::Ptr executor) |
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. More... | |
void | schedule (PollableDevice::Ptr device, const Poco::Clock &now={}) |
Schedule the given device relatively to the given time reference (usually meaning now). An already scheduled device is not rescheduled or updated in anyway. | |
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. | |
void | run () override |
Poll devices according to the schedule. | |
void | stop () override |
Stop polling of devices. | |
void | cleanup () |
Remove all scheduled devices (kind of reset). | |
Protected Member Functions | |
void | reschedule (PollableDevice::Ptr device, const Poco::Clock &now={}) |
Reschedule device after its PollableDevice::poll() method has been called. Only active devices are rescheduled. | |
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. | |
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. | |
void | doPoll (PollableDevice::Ptr device) |
Invoke the PollableDevice::poll() method via the configured m_pollExecutor. Thus, the poll() is usually called asynchronously and it can be parallelized with other devices. | |
Static Protected Member Functions | |
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. More... | |
DevicePoller is a scheduler for PollableDevice instances. Any number of devices can be scheduled for regular polling of their state. Each device can be scheduled according to its refresh time and later cancelled from being polled.
|
staticprotected |
Get refresh time of the device and check whether it is usable for regular polling. If it is not, throw an exception.
Poco::IllegalStateException | when the refresh time is not usable |
void DevicePoller::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.
The threshold can also be negative which allows to report devices that poll() almost as long as their refresh time.