Statistics
| Branch: | Tag: | Revision:

sssimulator / EventScheduler / README @ master

History | View | Annotate | Download (2.44 KB)

1 af271552 luca
Simple Scalable Event Scheduler (SSES) is a C language framework for dealing
2
with events.
3
4
The basic event is called "action_event" because it can be associated with a
5
function (event trigger).
6
7
Event can be customized and used in the framework by extending action_event.
8
9
The priority queue is implemented with buffer ring called ord_array.
10
ord_array pop requires constant time while insertion linear time.
11
However the constant in this operation is very small since it is performed
12
a stdlib memmove. Moreover if insertions regard events of deadline greater
13
than any other event, operation time is constant.
14
15
---------------------UML "class" diagram-------------------------------
16
17
+---------------+                            +------------+
18
|event_scheduler|<>------------------------->|action_event|
19
+---------------+                            +------------+
20
       |                                            A
21
       |                                            |
22
       v                                            |
23
  +---------+                                +------------+
24
  |ord_array|                                |<your_event>|        
25
  +---------+                                +------------+
26
27
28
---------------------Basic usage---------------------------------------
29
30
struct event_scheduler * es;
31
struct action_event * ev;
32
33
es = event_scheduler_new(0);  //creation of an event_scheduler
34
ev = action_event_new(your_func);  //creation of an action_event with custom func
35
res = event_scheduler_insert(es,ev,1); //schedule event from 1 time unit from now
36
37
/*....*/
38
39
ev = event_scheduler_pop(es); //get next event in the queue
40
action_event_trigger(ev); //execute custom func
41
action_event_destroy(&ev);
42
43
--------------------Adv usage-------------------------------------------
44
Since most of the time you probably want to associate a state to an event
45
SSES has been designed with extensibility in mind.
46
47
/*your_event.h*/
48 bf3d3ebd Luca Baldesi
#include"action_event.h"
49 af271552 luca
50
struct your_event {
51
	struct action_event base;
52
	int custom_value;
53
}
54
55
struct action_event * your_event_new(int cv)
56
{
57
	struct your_event * ye;
58
	ye = (struct your_event *) malloc(sizeof(struct your_event));
59 bf3d3ebd Luca Baldesi
	action_event_init((struct action_event *) ye, your_special_function, your_destroyer_function);
60 af271552 luca
	ye->custom_value = cv
61
	return (action_event *)ye;
62
}
63
64 bf3d3ebd Luca Baldesi
void your_destroyer_function(struct action_event ** evt)
65
{
66
	struct your_event * ye;
67
	ye = (struct your_event *) *evt;
68
	free(ye);
69
	*evt = NULL;
70
}
71
72
/* definition of your_special_function*/