1 |
|
|
/** |
2 |
|
|
* @file ConditionConfig.hpp |
3 |
|
|
* @brief Header file for blink1_control::config::ConditionConfig |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
#pragma once |
7 |
|
|
|
8 |
|
|
#include <ostream> |
9 |
|
|
#include <string> |
10 |
|
|
#include <vector> |
11 |
|
|
|
12 |
|
|
namespace blink1_control::config { |
13 |
|
|
|
14 |
|
|
/** |
15 |
|
|
* Configuration for conditions |
16 |
|
|
* |
17 |
|
|
* A condition is basically just a situation that can trigger |
18 |
|
|
* an LED pattern to play. |
19 |
|
|
* |
20 |
|
|
* Currently 2 types: ConditionConfig::Type::ProcessMonitor |
21 |
|
|
* and ConditionConfig::Type::Rollup. Each is individually documented |
22 |
|
|
*/ |
23 |
|
|
struct ConditionConfig { |
24 |
|
|
|
25 |
|
|
/** |
26 |
|
|
* Represents the Type of a condition. The Type basically decides |
27 |
|
|
* how to turn states in the system into patterns for the LED |
28 |
|
|
*/ |
29 |
|
|
enum class Type { |
30 |
|
|
/** |
31 |
|
|
* This condition will run a process periodically and |
32 |
|
|
* check the return value of the process. Will trigger |
33 |
|
|
* different patterns for a "pass" state vs a "fail" |
34 |
|
|
* state. The pass and fail states also go to the |
35 |
|
|
* Rollup type |
36 |
|
|
*/ |
37 |
|
|
ProcessMonitor, |
38 |
|
|
|
39 |
|
|
/** |
40 |
|
|
* A Rollup of other types basically takes the component |
41 |
|
|
* conditions and combines them. If they are all passed, |
42 |
|
|
* then the Rollup is passed. If one is failed, then the |
43 |
|
|
* Rollup is failed. |
44 |
|
|
*/ |
45 |
|
|
Rollup |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
/** |
49 |
|
|
* The Type of this condition |
50 |
|
|
*/ |
51 |
|
|
Type type; |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* The name of this condition |
55 |
|
|
*/ |
56 |
|
|
std::string name; |
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
* The list of patterns that can get activated based on the state of the condition |
60 |
|
|
*/ |
61 |
|
|
std::vector<std::string> patterns; |
62 |
|
|
|
63 |
|
10 |
virtual ~ConditionConfig() = default; |
64 |
|
|
|
65 |
|
|
/** |
66 |
|
|
* Output operator |
67 |
|
|
* |
68 |
|
|
* @param os Output stream |
69 |
|
|
* @param configType ConditionConfig::Type to output |
70 |
|
|
*/ |
71 |
|
|
friend std::ostream& operator<<(std::ostream& os, blink1_control::config::ConditionConfig::Type& configType) { |
72 |
|
|
switch (configType) { |
73 |
|
|
case blink1_control::config::ConditionConfig::Type::ProcessMonitor: |
74 |
|
|
os << "ProcessMonitor"; |
75 |
|
|
break; |
76 |
|
|
case blink1_control::config::ConditionConfig::Type::Rollup: |
77 |
|
|
os << "Rollup"; |
78 |
|
|
break; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
return os; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
/** |
85 |
|
|
* Output operator |
86 |
|
|
* |
87 |
|
|
* @param os Output stream |
88 |
|
|
* @param config Config to output |
89 |
|
|
*/ |
90 |
|
|
friend std::ostream& operator<<(std::ostream& os, blink1_control::config::ConditionConfig& config) { |
91 |
|
|
os << "{type: " << config.type << ", name: " << config.name << ", patterns: {"; |
92 |
|
|
bool first = true; |
93 |
|
|
for (auto& pattern : config.patterns) { |
94 |
|
|
if (first) { |
95 |
|
|
first = false; |
96 |
|
|
} else { |
97 |
|
|
os << ", "; |
98 |
|
|
} |
99 |
|
|
os << pattern; |
100 |
|
|
} |
101 |
|
|
os << "}}"; |
102 |
|
|
|
103 |
|
|
return os; |
104 |
|
|
} |
105 |
|
|
}; |
106 |
|
|
} |