server/src/kernel/event.h

68 lines
1.9 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
#ifndef EVENT_H
#define EVENT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <util/variant.h>
2010-08-08 10:06:34 +02:00
struct attrib;
struct trigger;
struct storage;
struct gamedata;
2011-03-07 08:02:35 +01:00
typedef struct trigger_type {
const char *name;
void(*initialize) (struct trigger *);
void(*finalize) (struct trigger *);
int(*handle) (struct trigger *, void *);
void(*write) (const struct trigger *, struct storage * store);
int(*read) (struct trigger *, struct gamedata * store);
2011-03-07 08:02:35 +01:00
struct trigger_type *next;
} trigger_type;
2011-03-07 08:02:35 +01:00
trigger_type *tt_find(const char *name);
void tt_register(trigger_type * ttype);
2011-03-07 08:02:35 +01:00
typedef struct trigger {
struct trigger_type *type;
struct trigger *next;
2011-03-07 08:02:35 +01:00
variant data;
} trigger;
2011-03-07 08:02:35 +01:00
typedef struct event_arg {
const char *type;
variant data;
} event_arg;
2011-03-07 08:02:35 +01:00
trigger *t_new(trigger_type * ttype);
void t_free(trigger * t);
void t_add(trigger ** tlist, trigger * t);
/** add and handle triggers **/
2010-08-08 10:06:34 +02:00
/* add a trigger to a list of attributes */
void add_trigger(struct attrib **ap, const char *eventname,
2011-03-07 08:02:35 +01:00
struct trigger *t);
void remove_triggers(struct attrib **ap, const char *eventname,
const trigger_type * tt);
struct trigger **get_triggers(struct attrib *ap,
const char *eventname);
/* calls handle() for each of these. e.g. used in timeout */
void handle_event(struct attrib *attribs, const char *eventname,
void *data);
/* functions for making complex triggers: */
void free_triggers(trigger * triggers); /* release all these triggers */
void write_triggers(struct storage *store, const trigger * t);
int read_triggers(struct gamedata *data, trigger ** tp);
int handle_triggers(trigger ** triggers, void *data);
extern struct attrib_type at_eventhandler;
2010-08-08 10:06:34 +02:00
#ifdef __cplusplus
}
#endif
#endif