Haka: include/haka/alert.h Source File

Haka

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

alert.h
Go to the documentation of this file.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
10 #ifndef HAKA_ALERT_H
11 #define HAKA_ALERT_H
12
13 #include <haka/types.h>
14 #include <haka/time.h>
15 #include <haka/container/list.h>
16
17
21 typedef enum {
22 HAKA_ALERT_LEVEL_NONE,
23 HAKA_ALERT_LOW,
24 HAKA_ALERT_MEDIUM,
25 HAKA_ALERT_HIGH,
26 HAKA_ALERT_NUMERIC,
28 HAKA_ALERT_LEVEL_LAST
29 } alert_level;
30
34 typedef enum {
35 HAKA_ALERT_COMPLETION_NONE,
36 HAKA_ALERT_FAILED,
37 HAKA_ALERT_SUCCESSFUL,
39 HAKA_ALERT_COMPLETION_LAST
40 } alert_completion;
41
45 typedef enum {
46 HAKA_ALERT_NODE_ADDRESS,
47 HAKA_ALERT_NODE_SERVICE,
49 HAKA_ALERT_NODE_LAST
50 } alert_node_type;
51
55 struct alert_node {
56 alert_node_type type;
57 char **list;
58 };
59
63 struct alert {
64 struct time start_time;
65 struct time end_time;
66 char *description;
67 alert_level severity;
68 alert_level confidence;
69 double confidence_num;
70 alert_completion completion;
71 char *method_description;
72 char **method_ref;
73 struct alert_node **sources;
74 struct alert_node **targets;
75 size_t alert_ref_count;
76 uint64 *alert_ref;
77 };
78
86 #define ALERT(name, nsrc, ntgt) \
87 struct alert_node *_sources[nsrc+1] = {0}; \
88 struct alert_node *_targets[ntgt+1] = {0}; \
89 struct alert name = { \
90 sources: nsrc==0 ? NULL : _sources, \
91 targets: ntgt==0 ? NULL : _targets,
92
96 #define ENDALERT };
97
107 #define ALERT_NODE(alert, name, index, type, ...) \
108 struct alert_node _node##name##index = { type }; \
109 alert.name[index] = &_node##name##index; \
110 char *_node##name##index_list[] = { __VA_ARGS__, NULL }; \
111 _node##name##index.list = _node##name##index_list
112
120 #define ALERT_REF(alert, count, ...) \
121 uint64 _alert_ref[count] = { __VA_ARGS__ }; \
122 alert.alert_ref_count = count; \
123 alert.alert_ref = _alert_ref
124
131 #define ALERT_METHOD_REF(alert, ...) \
132 char *_method_ref[] = { __VA_ARGS__, NULL }; \
133 alert.method_ref = _method_ref
134
140 uint64 alert(const struct alert *alert);
141
145 bool alert_update(uint64 id, const struct alert *alert);
146
150 const char *alert_level_to_str(alert_level level);
151
155 const char *alert_completion_to_str(alert_completion completion);
156
160 const char *alert_node_to_str(alert_node_type type);
161
165 const char *alert_tostring(uint64 id, const struct time *time, const struct alert *alert,
166 const char *header, const char *indent, bool color);
167
171 void enable_stdout_alert(bool enable);
172
176 struct alerter {
177 struct list list;
178 void (*destroy)(struct alerter *state);
179 bool (*alert)(struct alerter *state, uint64 id, const struct time *time, const struct alert *alert);
180 bool (*update)(struct alerter *state, uint64 id, const struct time *time, const struct alert *alert);
181 bool mark_for_remove;
182 };
183
187 bool add_alerter(struct alerter *alerter);
188
192 bool remove_alerter(struct alerter *alerter);
193
197 void remove_all_alerter();
198
199 #endif /* HAKA_ALERT_H */
alert::method_ref
char ** method_ref
Definition: alert.h:72
alert_node_to_str
const char * alert_node_to_str(alert_node_type type)
Definition: alert.c:226
alert::method_description
char * method_description
Definition: alert.h:71
alert::targets
struct alert_node ** targets
Definition: alert.h:74
HAKA_ALERT_COMPLETION_LAST
Definition: alert.h:39
types.h
alert_node::type
alert_node_type type
Definition: alert.h:56
alert_level
alert_level
Definition: alert.h:21
alert_update
bool alert_update(uint64 id, const struct alert *alert)
Definition: alert.c:163
alert::description
char * description
Definition: alert.h:66
time.h
HAKA_ALERT_NODE_SERVICE
Definition: alert.h:47
alert
Definition: alert.h:63
HAKA_ALERT_NODE_ADDRESS
Definition: alert.h:46
alert
uint64 alert(const struct alert *alert)
Definition: alert.c:142
HAKA_ALERT_LEVEL_LAST
Definition: alert.h:28
alert::completion
alert_completion completion
Definition: alert.h:70
uint64
unsigned HAKA_64BIT_TYPE uint64
Definition: types.h:30
HAKA_ALERT_SUCCESSFUL
Definition: alert.h:37
remove_alerter
bool remove_alerter(struct alerter *alerter)
Definition: alert.c:75
HAKA_ALERT_LOW
Definition: alert.h:23
alerter
Definition: alert.h:176
HAKA_ALERT_HIGH
Definition: alert.h:25
enable_stdout_alert
void enable_stdout_alert(bool enable)
remove_all_alerter
void remove_all_alerter()
Definition: alert.c:107
HAKA_ALERT_LEVEL_NONE
Definition: alert.h:22
alert_node::list
char ** list
Definition: alert.h:57
alert::severity
alert_level severity
Definition: alert.h:67
alert_completion_to_str
const char * alert_completion_to_str(alert_completion completion)
Definition: alert.c:215
HAKA_ALERT_NUMERIC
Definition: alert.h:26
alert::sources
struct alert_node ** sources
Definition: alert.h:73
HAKA_ALERT_MEDIUM
Definition: alert.h:24
add_alerter
bool add_alerter(struct alerter *alerter)
Definition: alert.c:55
bool
unsigned char bool
Definition: types.h:17
alert_node_type
alert_node_type
Definition: alert.h:45
alert_completion
alert_completion
Definition: alert.h:34
alert_tostring
const char * alert_tostring(uint64 id, const struct time *time, const struct alert *alert, const char *header, const char *indent, bool color)
Definition: alert.c:273
alert_node
Definition: alert.h:55
alert::confidence_num
double confidence_num
Definition: alert.h:69
time
Definition: time.h:21
alert::alert_ref
uint64 * alert_ref
Definition: alert.h:76
alert_level_to_str
const char * alert_level_to_str(alert_level level)
Definition: alert.c:203
HAKA_ALERT_FAILED
Definition: alert.h:36
alert::alert_ref_count
size_t alert_ref_count
Definition: alert.h:75
HAKA_ALERT_COMPLETION_NONE
Definition: alert.h:35
alert::confidence
alert_level confidence
Definition: alert.h:68
HAKA_ALERT_NODE_LAST
Definition: alert.h:49