diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-10-25 09:14:16 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-10-25 13:59:52 -0700 |
commit | 8212acc9925b28ecd546b01047c6a8fc574326ef (patch) | |
tree | f4ce765228f3bb2511a186373eb2b3394b647709 /core/event.h | |
parent | d82a7b8b73c13451f469832d6402303ccf2ee3d3 (diff) | |
download | subsurface-8212acc9925b28ecd546b01047c6a8fc574326ef.tar.gz |
cleanup: break out event-related code into event.[c|h]
In an effort to reduce the size of dive.h and dive.c, break out
the event related functions. Moreover event-names were handled
by the profile-code, collect that also in the new source files.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/event.h')
-rw-r--r-- | core/event.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/core/event.h b/core/event.h new file mode 100644 index 000000000..4c729e3f3 --- /dev/null +++ b/core/event.h @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef EVENT_H +#define EVENT_H + +#include "divemode.h" +#include "gas.h" +#include "units.h" + +#include <libdivecomputer/parser.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * 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. + */ +struct event { + struct event *next; + duration_t time; + int type; + /* This is the annoying libdivecomputer format. */ + int flags, value; + /* .. and this is our "extended" data for some event types */ + union { + enum divemode_t divemode; // for divemode change events + /* + * NOTE! The index may be -1, which means "unknown". In that + * case, the get_cylinder_index() function will give the best + * match with the cylinders in the dive based on gasmix. + */ + struct { // for gas switch events + int index; + struct gasmix mix; + } gas; + }; + bool deleted; + char name[]; +}; + +struct ev_select { + char *ev_name; + bool plot_ev; +}; + +/* collect all event names and whether we display them */ +extern struct ev_select *ev_namelist; +extern int evn_used; + +extern int event_is_gaschange(const struct event *ev); +extern bool event_is_divemodechange(const struct event *ev); +extern struct event *clone_event(const struct event *src_ev); +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 void remember_event(const char *eventname); +extern void clear_events(void); + +/* 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 + +#endif |