35 |
/** |
/** |
36 |
* Implementation of the event interface. |
* Implementation of the event interface. |
37 |
* |
* |
38 |
* NOTE1: Some event handlers are placed as functions in this file. In |
* NOTE: Some event handlers are placed as functions in this file. In |
39 |
* the future and if there is a need for more flexibility; It is easy |
* the future and if there is a need for more flexibility; It is easy |
40 |
* to setup event handlers as callback functions and register them in |
* to setup event handlers as callback functions and register them in |
41 |
* this class. Every event handler will have this signature: |
* this class. Every event handler will have this signature: |
42 |
* |
* |
43 |
* void handle_xxx_events(Event_T E); |
* void handle_xxx_event(Event_T E); |
|
* |
|
|
* NOTE2: It's possible to do the call to handle_event() in a new |
|
|
* thread to make the event handling non-sequential and more |
|
|
* responsive. We have to double check the thread-safeness of the code |
|
|
* first though. |
|
44 |
* |
* |
45 |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
* @author Jan-Henrik Haukeland, <hauk@tildeslash.com> |
46 |
* @version \$Id$ |
* @version \$Id$ |
80 |
static void handle_stop(Event_T E); |
static void handle_stop(Event_T E); |
81 |
static void handle_start(Event_T E); |
static void handle_start(Event_T E); |
82 |
static void handle_restart(Event_T E); |
static void handle_restart(Event_T E); |
83 |
|
static void handle_timeout(Event_T E); |
84 |
|
static void handle_checksum(Event_T E); |
85 |
|
|
86 |
static void swap_message(Event_T E, char *new_message, ...); |
static void swap_message(Event_T E, char *new_message, ...); |
87 |
|
|
102 |
ASSERT(source); |
ASSERT(source); |
103 |
|
|
104 |
NEW(e); |
NEW(e); |
|
|
|
105 |
e->id= id; |
e->id= id; |
106 |
e->message= NULL; |
e->message= NULL; |
107 |
e->source= source; |
e->source= source; |
113 |
va_end(ap); |
va_end(ap); |
114 |
} |
} |
115 |
|
|
116 |
|
/* |
117 |
|
* NOTE: It's possible to do the call to handle_event() below in a |
118 |
|
* new thread to make the event handling non-sequential and more |
119 |
|
* responsive. We have to double check the thread-safeness of the |
120 |
|
* code first though. |
121 |
|
*/ |
122 |
handle_event(e); |
handle_event(e); |
123 |
|
|
124 |
} |
} |
131 |
void Event_free(Event_T *E) { |
void Event_free(Event_T *E) { |
132 |
|
|
133 |
ASSERT(E && *E); |
ASSERT(E && *E); |
134 |
|
free((*E)->message); |
|
if((*E)->message) |
|
|
free((*E)->message); |
|
135 |
free(*E); |
free(*E); |
136 |
(*E)= NULL; |
(*E)= NULL; |
137 |
|
|
219 |
ASSERT(E); |
ASSERT(E); |
220 |
|
|
221 |
switch(E->id) { |
switch(E->id) { |
|
case EVENT_START: handle_start(E); break; |
|
222 |
case EVENT_STOP: handle_stop(E); break; |
case EVENT_STOP: handle_stop(E); break; |
223 |
|
case EVENT_START: handle_start(E); break; |
224 |
case EVENT_RESTART: handle_restart(E); break; |
case EVENT_RESTART: handle_restart(E); break; |
225 |
|
case EVENT_TIMEOUT: handle_timeout(E); break; |
226 |
|
case EVENT_CHECKSUM: handle_checksum(E); break; |
227 |
} |
} |
228 |
|
|
229 |
if(E->id != EVENT_NULL) { |
if(E->id != EVENT_NULL) { |
230 |
handle_alert_event(E); |
handle_alert_event(E); |
231 |
/* TODO: handle_exec_event(E); */ |
/* TODO: handle_exec_event(E); */ |
232 |
} |
} |
233 |
|
|
234 |
|
if(E->message) { |
235 |
|
log("%s", E->message); |
236 |
|
} |
237 |
|
|
238 |
Event_free(&E); |
Event_free(&E); |
239 |
|
|
240 |
} |
} |
300 |
} |
} |
301 |
|
|
302 |
|
|
303 |
|
static void handle_timeout(Event_T E) { |
304 |
|
|
305 |
|
LOCK(Run.mutex) |
306 |
|
E->source->do_monitor= FALSE; |
307 |
|
END_LOCK; |
308 |
|
|
309 |
|
|
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
|
static void handle_checksum(Event_T E) { |
314 |
|
|
315 |
|
LOCK(Run.mutex) |
316 |
|
E->source->do_monitor= FALSE; |
317 |
|
E->source->has_checksum_error= TRUE; |
318 |
|
END_LOCK; |
319 |
|
|
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
|
|
324 |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
325 |
|
|
326 |
|
|