430 |
new_state = STATE_NONE; |
new_state = STATE_NONE; |
431 |
|
|
432 |
if (new_state != STATE_NONE) |
if (new_state != STATE_NONE) |
433 |
state = new_state; |
{ |
434 |
|
util_run_events (state, new_state); |
435 |
|
state = new_state; |
436 |
|
} |
437 |
|
|
438 |
return status; |
return status; |
439 |
} |
} |
440 |
|
|
1202 |
list_do (atexit_list, atexit_run, 0); |
list_do (atexit_list, atexit_run, 0); |
1203 |
} |
} |
1204 |
|
|
1205 |
|
struct state_event { |
1206 |
|
int old_state; |
1207 |
|
int new_state; |
1208 |
|
list_action_t *action; |
1209 |
|
void *data; |
1210 |
|
}; |
1211 |
|
|
1212 |
|
static list_t event_list; |
1213 |
|
|
1214 |
|
void |
1215 |
|
util_register_event (int old_state, int new_state, |
1216 |
|
list_action_t *action, void *data) |
1217 |
|
{ |
1218 |
|
struct state_event *evp = malloc (sizeof (*evp)); |
1219 |
|
if (!evp) |
1220 |
|
imap4d_bye (ERR_NO_MEM); |
1221 |
|
evp->old_state = old_state; |
1222 |
|
evp->new_state = new_state; |
1223 |
|
evp->action = action; |
1224 |
|
evp->data = data; |
1225 |
|
if (!event_list) |
1226 |
|
list_create (&event_list); |
1227 |
|
list_append (event_list, (void*)evp); |
1228 |
|
} |
1229 |
|
|
1230 |
|
void |
1231 |
|
util_event_remove (void *id) |
1232 |
|
{ |
1233 |
|
list_remove (event_list, id); |
1234 |
|
} |
1235 |
|
|
1236 |
|
static int |
1237 |
|
event_exec (void *item, void *data) |
1238 |
|
{ |
1239 |
|
struct state_event *ev = data, *elem = item; |
1240 |
|
|
1241 |
|
if (ev->old_state == elem->old_state && ev->new_state == elem->new_state) |
1242 |
|
return elem->action (item, elem->data); |
1243 |
|
return 0; |
1244 |
|
} |
1245 |
|
|
1246 |
|
void |
1247 |
|
util_run_events (int old_state, int new_state) |
1248 |
|
{ |
1249 |
|
if (event_list) |
1250 |
|
{ |
1251 |
|
struct state_event ev; |
1252 |
|
|
1253 |
|
ev.old_state = old_state; |
1254 |
|
ev.new_state = new_state; |
1255 |
|
list_do (event_list, event_exec, &ev); |
1256 |
|
} |
1257 |
|
} |
1258 |
|
|