BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
DongleDeviceManager.h
1 #pragma once
2 
3 #include <Poco/Event.h>
4 #include <Poco/Mutex.h>
5 #include <Poco/Timespan.h>
6 
7 #include "core/DeviceManager.h"
8 #include "hotplug/HotplugListener.h"
9 
10 namespace BeeeOn {
11 
12 class FailDetector;
13 
15 public:
17  const std::initializer_list<std::type_index> &acceptable = {});
18 
19  void run() override;
20  void stop() override;
21 
22  void onAdd(const HotplugEvent &e) override;
23  void onRemove(const HotplugEvent &e) override;
24 
29  void setAttemptsCount(const int count);
30 
38  void setRetryTimeout(const Poco::Timespan &timeout);
39 
40 protected:
48  virtual std::string dongleMatch(const HotplugEvent &e) = 0;
49 
59  virtual void dongleAvailable() = 0;
60 
70  virtual bool dongleMissing();
71 
77  virtual void dongleFailed(const FailDetector &dongleStatus);
78 
87  virtual void notifyDongleRemoved();
88 
94  std::string dongleName(bool failWhenMissing = true) const;
95 
101  Poco::Event &event();
102 
103 private:
104  mutable Poco::FastMutex m_lock;
105  Poco::Event m_event;
106  std::string m_dongleName;
107  unsigned int m_attemptsCount;
108  Poco::Timespan m_retryTimeout;
109 };
110 
111 }
Definition: FailDetector.h:8
Definition: HotplugListener.h:9
void setAttemptsCount(const int count)
Definition: DongleDeviceManager.cpp:20
virtual void dongleAvailable()=0
virtual void dongleFailed(const FailDetector &dongleStatus)
Definition: DongleDeviceManager.cpp:41
Poco::Event & event()
Definition: DongleDeviceManager.cpp:70
virtual void notifyDongleRemoved()
The default implementation does nothing.
Definition: DongleDeviceManager.cpp:56
std::string dongleName(bool failWhenMissing=true) const
Definition: DongleDeviceManager.cpp:60
Definition: DeviceManager.h:48
Definition: HotplugEvent.h:10
Definition: DongleDeviceManager.h:14
virtual bool dongleMissing()
Definition: DongleDeviceManager.cpp:36
void stop() override
Definition: DongleDeviceManager.cpp:176
virtual std::string dongleMatch(const HotplugEvent &e)=0
void setRetryTimeout(const Poco::Timespan &timeout)
Definition: DongleDeviceManager.cpp:28
DevicePrefix prefix() const override
Definition: DeviceManager.cpp:33