BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
#include <PipeHotplugMonitor.h>
Public Member Functions | |
void | run () override |
void | stop () override |
void | setPipePath (const std::string &path) |
void | setPollTimeout (const Poco::Timespan &timeout) |
Public Member Functions inherited from BeeeOn::AbstractHotplugMonitor | |
void | registerListener (HotplugListener::Ptr listener) |
Protected Member Functions | |
int | openPipe () |
void | pollForEvents (FdInputStream &input) |
bool | processEvent (FdInputStream &input) |
bool | parseLine (const std::string &line, std::string &key, std::string &value) const |
void | fillEvent (HotplugEvent &event, const std::string &key, const std::string &value) const |
bool | skipEvent (FdInputStream &input) const |
void | fireEvent (const HotplugEvent &event, const std::string &action) |
Protected Member Functions inherited from BeeeOn::AbstractHotplugMonitor | |
void | logEvent (const HotplugEvent &event, const std::string &action) const |
void | fireAddEvent (const HotplugEvent &event) |
void | fireRemoveEvent (const HotplugEvent &event) |
void | fireChangeEvent (const HotplugEvent &event) |
void | fireMoveEvent (const HotplugEvent &event) |
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) | |
Additional Inherited Members | |
Public 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) |
The PipeHotplugMonitor can be used to detect device hotplug events independently on the underlying system. It is not bound to any library like udev. It just waits on a given file (named pipe) and reads events.
An event recognized by the PipeHotplugMonitor is a sequence of lines in form KEY=VALUE
. Each event must be finished by an empty line or EOF. There is a set of standard keys (matching the HotplugEvent contents). The unrecognized keys are treated as device properties. Each event must contain key ACTION defining one of: add, remove, change, move.
Example event:
ACTION=add<LF> SUBSYSTEM=tty<LF> NODE=/dev/ttyUSB0<LF> DRIVER=serial_ftdi<LF> <LF|EOF>
|
protected |
Interpret the key-value pair in the context of the HotplugEvent. Set either one of its members or extend properties.
|
protected |
Open the pipe for receiving hotplug events.
|
protected |
Parse a single line and break it to key and value.
|
protected |
Poll and read new events from the input.
|
protected |
Read a single hotplug event from the input.
void PipeHotplugMonitor::setPipePath | ( | const std::string & | path | ) |
Set path to the pipe providing hotplug events. If the pipe does not exist, the PipeHotplugMonitor waits until it is created.
void PipeHotplugMonitor::setPollTimeout | ( | const Poco::Timespan & | timeout | ) |
Poll timeout determines how long to block while polling for new events. Negative value leads to blocking mode. A positive value leads to time-limited blocking and 0 denotes non-blocking. The timeout is expected at least in milliseconds.
|
protected |
Skip all lines until an empty line or EOF is reached.
|
overridevirtual |
Stop the runnable. The call should not block.
Implements BeeeOn::StoppableRunnable.