BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
PipeHotplugMonitor.h
1 #pragma once
2 
3 #include <list>
4 #include <set>
5 #include <string>
6 
7 #include <Poco/AtomicCounter.h>
8 #include <Poco/Event.h>
9 #include <Poco/Timespan.h>
10 
11 #include "loop/StoppableRunnable.h"
12 #include "hotplug/AbstractHotplugMonitor.h"
13 
14 namespace BeeeOn {
15 
16 class FdInputStream;
17 
42  public StoppableRunnable,
43  public AbstractHotplugMonitor {
44 public:
47 
48  void run() override;
49  void stop() override;
50 
56  void setPipePath(const std::string &path);
57 
64  void setPollTimeout(const Poco::Timespan &timeout);
65 
66 protected:
70  int openPipe();
71 
75  void pollForEvents(FdInputStream &input);
76 
81  bool processEvent(FdInputStream &input);
82 
87  bool parseLine(const std::string &line, std::string &key, std::string &value) const;
88 
93  void fillEvent(HotplugEvent &event, const std::string &key, const std::string &value) const;
94 
99  bool skipEvent(FdInputStream &input) const;
100  void fireEvent(const HotplugEvent &event, const std::string &action);
101 
102 private:
103  std::string m_pipePath;
104  Poco::Event m_waitPipe;
105  Poco::Timespan m_pollTimeout;
106  Poco::AtomicCounter m_stop;
107 };
108 
109 }
void stop() override
Definition: PipeHotplugMonitor.cpp:263
bool processEvent(FdInputStream &input)
Definition: PipeHotplugMonitor.cpp:89
void setPollTimeout(const Poco::Timespan &timeout)
Definition: PipeHotplugMonitor.cpp:274
bool parseLine(const std::string &line, std::string &key, std::string &value) const
Definition: PipeHotplugMonitor.cpp:43
void setPipePath(const std::string &path)
Definition: PipeHotplugMonitor.cpp:269
Definition: FdStream.h:57
Definition: AbstractHotplugMonitor.h:13
Definition: HotplugEvent.h:10
void pollForEvents(FdInputStream &input)
Definition: PipeHotplugMonitor.cpp:204
Definition: StoppableRunnable.h:8
int openPipe()
Definition: PipeHotplugMonitor.cpp:187
Definition: PipeHotplugMonitor.h:41
void fillEvent(HotplugEvent &event, const std::string &key, const std::string &value) const
Definition: PipeHotplugMonitor.cpp:56
bool skipEvent(FdInputStream &input) const
Definition: PipeHotplugMonitor.cpp:72