Statistics
| Branch: | Tag: | Revision:

sssimulator / EventScheduler / action_event.c @ af271552

History | View | Annotate | Download (925 Bytes)

1
/*
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
void action_event_init(struct action_event *ae, action_event_func_t t)
20
{
21
        ae->time = -1;
22
        ae->trigger = t;
23
        ae->destroy = NULL;
24
}
25

    
26
struct action_event * action_event_new(action_event_func_t t)
27
{
28
        struct action_event * ae;
29

    
30
        ae = (struct action_event *) malloc(sizeof(struct action_event));
31
        action_event_init(ae, t);
32

    
33
        return ae;
34
}
35

    
36
void action_event_destroy(struct action_event ** ev)
37
{
38
        if (ev && (*ev) && (*ev)->destroy != NULL)
39
                        (*ev)->destroy(ev);
40
        if (ev && (*ev)) {
41
                free(*ev);
42
                *ev = NULL;
43
        }
44
}
45

    
46
int action_event_trigger(struct action_event * ev)
47
{
48
        if (ev && ev->trigger)
49
                return ev->trigger(ev);
50
        return -1;
51
}