Statistics
| Branch: | Tag: | Revision:

sssimulator / EventScheduler / action_event.c @ master

History | View | Annotate | Download (978 Bytes)

1 af271552 luca
/*
2
 * this is sssim: the simple & stupid simulator
3
 *
4
 *  copyright (c) 2015 luca baldesi
5
 *
6
 *  this is free software; see gpl-3.0.txt
7
 */
8
9
#include"action_event.h"
10
#include"action_event_struct.h"
11
12
double action_event_time(const struct action_event *ev)
13
{
14
        if (ev)
15
                return ev->time;
16
        return -1;
17
}
18
19 bf3d3ebd Luca Baldesi
void action_event_init(struct action_event *ae, action_event_func_t t, action_event_destroy_func_t d)
20 af271552 luca
{
21
        ae->time = -1;
22
        ae->trigger = t;
23 bf3d3ebd Luca Baldesi
        ae->destroy = d;
24
        ae->priority = 0;
25 af271552 luca
}
26
27
struct action_event * action_event_new(action_event_func_t t)
28
{
29
        struct action_event * ae;
30
31
        ae = (struct action_event *) malloc(sizeof(struct action_event));
32 bf3d3ebd Luca Baldesi
        action_event_init(ae, t, NULL);
33 af271552 luca
34
        return ae;
35
}
36
37
void action_event_destroy(struct action_event ** ev)
38
{
39
        if (ev && (*ev) && (*ev)->destroy != NULL)
40
                        (*ev)->destroy(ev);
41
        if (ev && (*ev)) {
42
                free(*ev);
43
                *ev = NULL;
44
        }
45
}
46
47
int action_event_trigger(struct action_event * ev)
48
{
49
        if (ev && ev->trigger)
50
                return ev->trigger(ev);
51
        return -1;
52
}