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:
Berthold Stoeger 2024-02-14 21:29:48 +01:00 committed by Dirk Hohndel
parent 6ad7e577f1
commit 4422dbb52b
4 changed files with 32 additions and 14 deletions

View file

@ -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;
}
}