BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
FailDetector.h
1 #pragma once
2 
3 #include <Poco/Timespan.h>
4 #include <Poco/Timestamp.h>
5 
6 namespace BeeeOn {
7 
8 class FailDetector {
9 public:
10  const static int TRESHOLD_UNLIMITED = 0;
11 
16  FailDetector(const unsigned int failsTreshold = TRESHOLD_UNLIMITED);
17 
18  ~FailDetector();
19 
23  void fail();
24 
28  void success();
29 
34  bool isGoingToFail() const;
35 
39  bool isFailed() const;
40 
44  Poco::Timestamp timeOfLastFail() const;
45 
52  bool lastFailBefore(const Poco::Timespan &timeout) const;
53 
58  Poco::Timestamp timeOfFailure() const;
59 
67  bool failedBefore(const Poco::Timespan &timeout) const;
68 
69 private:
70  unsigned int m_fails;
71  unsigned int m_failsTreshold;
72  Poco::Timestamp m_timeOfLastFail;
73  Poco::Timestamp m_timeOfFailure;
74 };
75 
76 }
Definition: FailDetector.h:8
bool isFailed() const
Definition: FailDetector.cpp:36
Poco::Timestamp timeOfFailure() const
Definition: FailDetector.cpp:51
bool isGoingToFail() const
Definition: FailDetector.cpp:31
Poco::Timestamp timeOfLastFail() const
Definition: FailDetector.cpp:41
bool lastFailBefore(const Poco::Timespan &timeout) const
Definition: FailDetector.cpp:46
FailDetector(const unsigned int failsTreshold=TRESHOLD_UNLIMITED)
Definition: FailDetector.cpp:6
void fail()
Definition: FailDetector.cpp:16
void success()
Definition: FailDetector.cpp:26
bool failedBefore(const Poco::Timespan &timeout) const
Definition: FailDetector.cpp:56