-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
116 lines (92 loc) · 2.2 KB
/
common.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstdint>
#include <string>
#include <exception>
#include <stdexcept>
#include <thread>
#include <chrono>
namespace common {
const unsigned long GIGA{1000000000UL};
class LightSetting {
public:
LightSetting() : LightSetting(0, 0, 0) {
}
LightSetting(uint8_t r, uint8_t g, uint8_t b) :
r(r),
g(g),
b(b) {
}
uint8_t r{0};
uint8_t g{0};
uint8_t b{0};
};
bool operator==(const LightSetting& lhs, const LightSetting& rhs);
bool operator!=(const LightSetting& lhs, const LightSetting& rhs);
const common::LightSetting RED{255, 0, 0};
const common::LightSetting GREEN{0, 255, 0};
class RgbLight {
public:
virtual ~RgbLight() {}
virtual void set(LightSetting value) = 0;
virtual LightSetting get() = 0;
};
struct BeeperTone {
BeeperTone(uint16_t duration_ms, uint16_t frequency_hz) :
duration_ms(duration_ms),
frequency_hz(frequency_hz) {
}
BeeperTone() : BeeperTone(0, 0) {
}
uint16_t duration_ms{0};
uint16_t frequency_hz{0};
};
bool operator==(const BeeperTone& lhs, const BeeperTone& rhs);
bool operator!=(const BeeperTone& lhs, const BeeperTone& rhs);
class Beeper {
public:
virtual ~Beeper() {}
virtual void setVolume(uint8_t volume) = 0;
virtual uint8_t getVolume() = 0;
virtual void playTone(const BeeperTone& tone) = 0;
};
enum class BuildResult {
OK,
BROKEN,
DONTKNOW
};
class Signalizer {
public:
Signalizer(Beeper& beeper, RgbLight& rgbLight);
void update(BuildResult buildResult);
private:
Beeper& beeper;
RgbLight& rgbLight;
};
class BuildResultParser {
virtual BuildResult parseMsg(const std::string& msg) = 0;
};
class JenkinsBuildResultParser : public BuildResultParser {
public:
BuildResult parseMsg(const std::string& msg) override;
};
class KeyValueStore {
public:
virtual ~KeyValueStore() {}
virtual void set(const std::string& key, const std::string& value) = 0;
virtual std::string get(const std::string& key) = 0;
};
class StateSaver {
public:
StateSaver(KeyValueStore& store, RgbLight& rgbLight);
void saveCurrentLightSetting();
void restoreLightSetting();
private:
uint8_t convert(const std::string& str);
private:
KeyValueStore& store;
RgbLight& rgbLight;
};
} // namespace common