mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
events: make event severity explicit
Currently the event type code uses libdivecomputer's flags to differentiate between events. Make this explicit and extract the event severity. The reason is that later we want to be more explicit about showing/ hiding events and thereto we must format the name of events. Moreover, this encapsulates the complexities of extracting the severity in the event code (that used to be in the profile code). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
fdbd076e0d
commit
b98c35ab52
4 changed files with 32 additions and 14 deletions
14
core/event.c
14
core/event.c
|
@ -102,3 +102,17 @@ bool same_event(const struct event *a, const struct event *b)
|
|||
return 0;
|
||||
return !strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
extern enum event_severity get_event_severity(const struct event *ev)
|
||||
{
|
||||
switch (ev->flags & SAMPLE_FLAGS_SEVERITY_MASK) {
|
||||
case SAMPLE_FLAGS_SEVERITY_INFO:
|
||||
return EVENT_SEVERITY_INFO;
|
||||
case SAMPLE_FLAGS_SEVERITY_WARN:
|
||||
return EVENT_SEVERITY_WARN;
|
||||
case SAMPLE_FLAGS_SEVERITY_ALARM:
|
||||
return EVENT_SEVERITY_ALARM;
|
||||
default:
|
||||
return EVENT_SEVERITY_NONE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum event_severity {
|
||||
EVENT_SEVERITY_NONE = 0,
|
||||
EVENT_SEVERITY_INFO,
|
||||
EVENT_SEVERITY_WARN,
|
||||
EVENT_SEVERITY_ALARM
|
||||
};
|
||||
|
||||
/*
|
||||
* Events are currently based straight on what libdivecomputer gives us.
|
||||
* We need to wrap these into our own events at some point to remove some of the limitations.
|
||||
|
@ -46,12 +53,12 @@ extern void free_events(struct event *ev);
|
|||
extern struct event *create_event(unsigned int time, int type, int flags, int value, const char *name);
|
||||
extern struct event *clone_event_rename(const struct event *ev, const char *name);
|
||||
extern bool same_event(const struct event *a, const struct event *b);
|
||||
extern enum event_severity get_event_severity(const struct event *ev);
|
||||
|
||||
/* Since C doesn't have parameter-based overloading, two versions of get_next_event. */
|
||||
extern const struct event *get_next_event(const struct event *event, const char *name);
|
||||
extern struct event *get_next_event_mutable(struct event *event, const char *name);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -9,10 +9,12 @@
|
|||
|
||||
struct event_type {
|
||||
std::string name;
|
||||
int flags;
|
||||
event_severity severity;
|
||||
bool plot;
|
||||
event_type(const struct event *ev)
|
||||
: name(ev->name), flags(ev->flags), plot(true)
|
||||
event_type(const struct event *ev) :
|
||||
name(ev->name),
|
||||
severity(get_event_severity(ev)),
|
||||
plot(true)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -21,7 +23,7 @@ static std::vector<event_type> event_types;
|
|||
|
||||
static bool operator==(const event_type &en1, const event_type &en2)
|
||||
{
|
||||
return en1.name == en2.name && en1.flags == en2.flags;
|
||||
return en1.name == en2.name && en1.severity == en2.severity;
|
||||
}
|
||||
|
||||
extern "C" void clear_event_types()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue