forked from matth-x/MicroOcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOcppOperationTimeout.h
More file actions
70 lines (61 loc) · 1.7 KB
/
Copy pathOcppOperationTimeout.h
File metadata and controls
70 lines (61 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// matth-x/ArduinoOcpp
// Copyright Matthias Akstaller 2019 - 2022
// MIT License
#ifndef OCPPOPERATIONTIMEOUT_H
#define OCPPOPERATIONTIMEOUT_H
#include <Arduino.h>
#include <functional>
namespace ArduinoOcpp {
using OnTimeoutListener = std::function<void()>;
using OnAbortListener = std::function<void()>;
class Timeout {
private:
OnTimeoutListener onTimeoutListener = [] () {};
OnAbortListener onAbortListener = [] () {};
bool triggered = false;
void trigger();
protected:
Timeout() = default;
public:
void setOnTimeoutListener(OnTimeoutListener onTimeoutListener);
void setOnAbortListener(OnAbortListener onAbortListener);
virtual ~Timeout() = default;
void tick(bool sendingSuccessful);
virtual void timerTick(bool sendingSuccessful) = 0;
void restart();
virtual void timerRestart() = 0;
bool isExceeded();
virtual bool timerIsExceeded() = 0;
};
class FixedTimeout : public Timeout {
private:
ulong TIMEOUT_DURATION;
ulong timeout_start;
bool timeout_active;
public:
FixedTimeout(ulong TIMEOUT_EXPIRE);
void timerTick(bool sendingSuccessful);
void timerRestart();
bool timerIsExceeded();
};
class OfflineSensitiveTimeout : public Timeout {
private:
ulong TIMEOUT_DURATION;
ulong timeout_start;
ulong last_tick;
bool timeout_active;
public:
OfflineSensitiveTimeout(ulong TIMEOUT_EXPIRE);
void timerTick(bool sendingSuccessful);
void timerRestart();
bool timerIsExceeded();
};
class SuppressedTimeout : public Timeout {
public:
SuppressedTimeout() = default;
void timerTick(bool sendingSuccessful) {}
void timerRestart() {}
bool timerIsExceeded() {return false;}
};
} //end namespace ArduinoOcpp
#endif