BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
#include <DeviceManager.h>
Public Types | |
typedef Poco::SharedPtr < DeviceManager > | Ptr |
Public Types inherited from BeeeOn::DeviceStatusHandler | |
typedef Poco::SharedPtr < DeviceStatusHandler > | Ptr |
typedef std::map< DeviceID, std::map< ModuleID, double > > | DeviceValues |
Public Types inherited from BeeeOn::StoppableRunnable | |
typedef Poco::SharedPtr < StoppableRunnable > | Ptr |
Public Member Functions | |
DeviceManager (const DevicePrefix &prefix, const std::initializer_list< std::type_index > &acceptable={}) | |
DevicePrefix | prefix () const override |
void | stop () override |
void | setDeviceCache (DeviceCache::Ptr cache) |
void | setDistributor (Poco::SharedPtr< Distributor > distributor) |
bool | accept (const Command::Ptr cmd) override |
void | handle (Command::Ptr cmd, Answer::Ptr answer) override |
void | handleRemoteStatus (const DevicePrefix &prefix, const std::set< DeviceID > &devices, const DeviceStatusHandler::DeviceValues &values) override |
Called when devices from a remote server are fetched and so the pairing status of them can be reconsidered. The default implementation just updates the device cache appropriately. | |
Public Member Functions inherited from BeeeOn::CommandSender | |
void | setCommandDispatcher (CommandDispatcher *dispatcher) |
void | dispatch (Poco::AutoPtr< Command > cmd, Poco::AutoPtr< Answer > answer) |
void | dispatch (Poco::AutoPtr< Command > cmd) |
AnswerQueue & | answerQueue () |
Protected Member Functions | |
std::set< DeviceID > | waitRemoteStatus (const Poco::Timespan &timeout) |
Wait until the remote status is delivered or timeout exceeds. DO NOT USE this method, it is intended as a transition mechanism from calling of the deprecated method deviceList(). More... | |
virtual void | handleGeneric (const Command::Ptr cmd, Result::Ptr result) |
virtual void | handleAccept (const DeviceAcceptCommand::Ptr) |
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we need to make some technology-specific check of the device to be accepted. The default implementation simply marks the given device as paired. | |
virtual AsyncWork::Ptr | startDiscovery (const Poco::Timespan &timeout) |
Starts device discovery process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
void | handleListen (const GatewayListenCommand::Ptr cmd) |
Implements handling of the listen command in a generic way. The method ensures that only 1 thread can execute the discovery process at a time. More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const Poco::Net::IPAddress &address) |
Start searching a device by IP address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const MACAddress &address) |
Start searching a device by MAC address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const uint64_t serialNumber) |
Start searching a device by serial number in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
void | handleSearch (const DeviceSearchCommand::Ptr cmd) |
Implements handling of the search command in a generic way. The method ensures that only 1 thread can exactly the search process at a time. It is also mutual exclusive to the discovery process. | |
virtual AsyncWork< std::set < DeviceID > >::Ptr | startUnpair (const DeviceID &id, const Poco::Timespan &timeout) |
Starts device unpair process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
std::set< DeviceID > | handleUnpair (const DeviceUnpairCommand::Ptr cmd) |
Implements handling of the unpair command in a generic way. The method ensures that only 1 thread can execute the unpair process at a time. More... | |
virtual AsyncWork< double >::Ptr | startSetValue (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) |
Starts set-value operation in a technology specific way. The method is always called inside a critical section and so its implementation does not have to be thread-save nor reentrant (unless it cooperates with other threads itself). More... | |
AsyncWork< double >::Ptr | startSetValueByMode (const DeviceID &id, const ModuleID &module, const double value, const OpMode &mode, const Poco::Timespan &timeout) |
Call an implementation of startSetValue() based on the given operation mode. | |
virtual AsyncWork< double >::Ptr | startSetValueTryHarder (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) |
Default implementation just calls startSetValue(). | |
virtual AsyncWork< double >::Ptr | startSetValueRepeatOnFail (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) |
Default implementation calls startSetValue() again if a Poco::IOException is thrown until timeout exceeds. However, due to asynchronous behaviour, this way of repeating on fail might be inappropriate. | |
void | handleSetValue (const DeviceSetValueCommand::Ptr cmd) |
Implements handling of the set-value command in a generic way. The method ensures that only 1 thread can execute set-value process at a time. If the set-value operation succeeds, it ships the set value. More... | |
void | ship (const SensorData &sensorData) |
DeviceCache::Ptr | deviceCache () const |
CancellableSet & | cancellable () |
Poco::Timespan | checkDelayedOperation (const std::string &opname, const Poco::Clock &started, const Poco::Timespan &duration) const |
When starting an asynchronous operation, it might happen we sleep too long on a lock because the previous operation did not finished yet. This method performs such checks and also tests for global stop request. If everything is in order it just fixes the duration by the time elapsed by waiting. Otherwise, it throws an exception. More... | |
bool | manageUntilFinished (const std::string &opname, AnyAsyncWork::Ptr work, const Poco::Timespan &timeout) |
Manage an AsyncWork after it is started. If it does not finish in the given timeout, it is cancelled explicitly. More... | |
Protected Member Functions inherited from BeeeOn::Loggable | |
void | setupLogger (Poco::Logger *logger=0) const |
Poco::Logger & | logger () const |
Loggable (const ClassInfo &info) | |
Loggable (const std::type_info &info) | |
Protected Attributes | |
StopControl | m_stopControl |
Additional Inherited Members | |
Protected Types inherited from BeeeOn::StoppableRunnable | |
typedef Poco::SharedPtr < StoppableRunnable > | Ptr |
Static Protected Member Functions inherited from BeeeOn::Loggable | |
static Poco::Logger & | forMethod (const char *name) |
static Poco::Logger & | forClass (const ClassInfo &info) |
static Poco::Logger & | forClass (const std::type_info &info) |
template<typename T > | |
static Poco::Logger & | forInstance (const T *i) |
static void | configureSimple (Poco::Logger &logger, const std::string &level) |
static void | logException (Poco::Logger &logger, const Poco::Message::Priority priority, const Poco::Exception &e, const char *file, size_t line) |
All classes that manage devices should inherit from this abstract class. It provides a common functionality for this purpose.
There is usually a main thread that performs communication with the physical devices and translates the specific device communication protocol into the Command & Answer interface or into SensorData interface.
Communication in the direction to physical devices is served via the CommandHandler interface. By accepting Commands asking for specific tasks, the physical devices can be queried as expected by the server.
|
overridevirtual |
Generic implementation of the CommandHandler::accept() method. If the m_acceptable set is initialized appropriately, this generic implementation can be used directly.
Implements BeeeOn::CommandHandler.
|
protected |
|
protected |
When starting an asynchronous operation, it might happen we sleep too long on a lock because the previous operation did not finished yet. This method performs such checks and also tests for global stop request. If everything is in order it just fixes the duration by the time elapsed by waiting. Otherwise, it throws an exception.
IllegalStateException | when stop has been requested |
|
protected |
|
overridevirtual |
Generic implementation of the CommandHandler::handle() method. It works with respect to the accept() method and handles commands generically if possible. It also catches all exceptions and fails such command executions properly.
To override handle, please use handleGeneric() instead.
Implements BeeeOn::CommandHandler.
|
protectedvirtual |
Generic implementation of the handle(). If any device manager needs to override the handle() method, it is more desirable to override handleGeneric().
Reimplemented in BeeeOn::FitpDeviceManager, BeeeOn::VirtualDeviceManager, and BeeeOn::VPTDeviceManager.
|
protected |
Implements handling of the listen command in a generic way. The method ensures that only 1 thread can execute the discovery process at a time.
It uses the method startDiscovery() to initialize and start a new discovery process. It is guaranteed that the startDiscovery() method is always called exactly once at a time and until it finishes, no other discovery is started. The minimal timeout for the discovery is at least 1 second which is enforced by the implementation.
|
protected |
Implements handling of the set-value command in a generic way. The method ensures that only 1 thread can execute set-value process at a time. If the set-value operation succeeds, it ships the set value.
It uses the method startSetValue() to initialize and start the set-value process. The method startSetValue() is always called exactly once at a time and until it finishes, no the set-value is started.
|
protected |
Implements handling of the unpair command in a generic way. The method ensures that only 1 thread can execute the unpair process at a time.
It uses the method startUnpair() to initialize and start the unpairing process. The method startUnpair() is always called exactly once at a time and until it finishes, no other unpair is started.
|
protected |
Manage an AsyncWork after it is started. If it does not finish in the given timeout, it is cancelled explicitly.
|
overridevirtual |
Implements BeeeOn::DeviceStatusHandler.
|
protected |
Ship data received from a physical device into a collection point.
|
protectedvirtual |
Starts device discovery process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The purpose of this call is to initialize and start the discovery process which might be a non-blocking operation. The caller uses the provided AsyncWork<> instance to wait until it finishes or to cancel it earlier if needed.
Reimplemented in BeeeOn::ZWaveDeviceManager, BeeeOn::JablotronDeviceManager, BeeeOn::BLESmartDeviceManager, BeeeOn::IQRFDeviceManager, BeeeOn::VPTDeviceManager, BeeeOn::BluetoothAvailabilityManager, BeeeOn::PhilipsHueDeviceManager, BeeeOn::PressureSensorManager, BeeeOn::BelkinWemoDeviceManager, BeeeOn::VektivaDeviceManager, BeeeOn::ConradDeviceManager, and BeeeOn::SonoffDeviceManager.
|
protectedvirtual |
Start searching a device by IP address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The purpose of this call is to initialize and start the searching process which might be a non-blocking operation. The caller uses the provided AsyncWork<> instance to wait until it finishes or to cancel it earlier if needed.
|
protectedvirtual |
Start searching a device by MAC address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The purpose of this call is to initialize and start the searching process which might be a non-blocking operation. The caller uses the provided AsyncWork<> instance to wait until it finishes or to cancel it earlier if needed.
|
protectedvirtual |
Start searching a device by serial number in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The purpose of this call is to initialize and start the searching process which might be a non-blocking operation. The caller uses the provided AsyncWork<> instance to wait until it finishes or to cancel it earlier if needed.
Reimplemented in BeeeOn::JablotronDeviceManager.
|
protectedvirtual |
Starts set-value operation in a technology specific way. The method is always called inside a critical section and so its implementation does not have to be thread-save nor reentrant (unless it cooperates with other threads itself).
The set-value process might a be a non-blocking operation. The value set by the set-value is expected as a result of the returned AsyncWork instance.
Reimplemented in BeeeOn::JablotronDeviceManager, BeeeOn::ZWaveDeviceManager, BeeeOn::BLESmartDeviceManager, BeeeOn::PhilipsHueDeviceManager, BeeeOn::BelkinWemoDeviceManager, BeeeOn::VektivaDeviceManager, and BeeeOn::ConradDeviceManager.
|
protectedvirtual |
Starts device unpair process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The unpairing process might be a non-blocking operation. The unpaired devices are provided via the result of the returned AsyncWork instance.
Reimplemented in BeeeOn::JablotronDeviceManager, BeeeOn::ZWaveDeviceManager, BeeeOn::BLESmartDeviceManager, BeeeOn::IQRFDeviceManager, BeeeOn::VPTDeviceManager, BeeeOn::BluetoothAvailabilityManager, BeeeOn::PhilipsHueDeviceManager, BeeeOn::PressureSensorManager, BeeeOn::BelkinWemoDeviceManager, BeeeOn::VektivaDeviceManager, BeeeOn::ConradDeviceManager, and BeeeOn::SonoffDeviceManager.
|
overridevirtual |
A generic stop implementation to be used by most DeviceManager implementations.
Implements BeeeOn::StoppableRunnable.
Reimplemented in BeeeOn::ZWaveDeviceManager, BeeeOn::JablotronDeviceManager, BeeeOn::IQRFDeviceManager, BeeeOn::FitpDeviceManager, BeeeOn::VPTDeviceManager, BeeeOn::PhilipsHueDeviceManager, BeeeOn::VektivaDeviceManager, BeeeOn::PressureSensorManager, BeeeOn::VirtualDeviceManager, BeeeOn::SonoffDeviceManager, and BeeeOn::DongleDeviceManager.
|
protected |
Wait until the remote status is delivered or timeout exceeds. DO NOT USE this method, it is intended as a transition mechanism from calling of the deprecated method deviceList().