Haka
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 {
29 } alert_level;
30 
34 typedef enum {
41 
45 typedef enum {
51 
55 struct alert_node {
57  char **list;
58 };
59 
63 struct alert {
64  struct time start_time;
65  struct time end_time;
66  char *description;
69  double confidence_num;
72  char **method_ref;
73  struct alert_node **sources;
74  struct alert_node **targets;
75  size_t alert_ref_count;
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 
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 */
char ** method_ref
Definition: alert.h:72
const char * alert_node_to_str(alert_node_type type)
Definition: alert.c:226
char * method_description
Definition: alert.h:71
struct alert_node ** targets
Definition: alert.h:74
Definition: alert.h:39
alert_node_type type
Definition: alert.h:56
alert_level
Definition: alert.h:21
bool alert_update(uint64 id, const struct alert *alert)
Definition: alert.c:163
char * description
Definition: alert.h:66
Definition: alert.h:47
Definition: alert.h:63
Definition: alert.h:46
uint64 alert(const struct alert *alert)
Definition: alert.c:142
Definition: alert.h:28
alert_completion completion
Definition: alert.h:70
unsigned HAKA_64BIT_TYPE uint64
Definition: types.h:30
Definition: alert.h:37
bool remove_alerter(struct alerter *alerter)
Definition: alert.c:75
Definition: alert.h:23
Definition: alert.h:176
Definition: alert.h:25
void enable_stdout_alert(bool enable)
void remove_all_alerter()
Definition: alert.c:107
Definition: alert.h:22
char ** list
Definition: alert.h:57
alert_level severity
Definition: alert.h:67
const char * alert_completion_to_str(alert_completion completion)
Definition: alert.c:215
Definition: alert.h:26
struct alert_node ** sources
Definition: alert.h:73
Definition: alert.h:24
bool add_alerter(struct alerter *alerter)
Definition: alert.c:55
unsigned char bool
Definition: types.h:17
alert_node_type
Definition: alert.h:45
alert_completion
Definition: alert.h:34
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
Definition: alert.h:55
double confidence_num
Definition: alert.h:69
Definition: time.h:21
uint64 * alert_ref
Definition: alert.h:76
const char * alert_level_to_str(alert_level level)
Definition: alert.c:203
Definition: alert.h:36
size_t alert_ref_count
Definition: alert.h:75
Definition: alert.h:35
alert_level confidence
Definition: alert.h:68
Definition: alert.h:49