Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/hooks.c @ 1623:b008ac166b91
Flags for hook handlers
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Thu, 15 Oct 2009 12:08:53 +0300 |
parents | f9bf561e54d0 |
children | cd67b29e04e3 |
comparison
equal
deleted
inserted
replaced
1622:90ecb027d1e3 | 1623:b008ac166b91 |
---|---|
39 #ifdef MODULES_ENABLE | 39 #ifdef MODULES_ENABLE |
40 #include <glib.h> | 40 #include <glib.h> |
41 | 41 |
42 typedef struct { | 42 typedef struct { |
43 hk_handler_t handler; | 43 hk_handler_t handler; |
44 guint32 flags; | |
44 gpointer userdata; | 45 gpointer userdata; |
45 } hook_list_data_t; | 46 } hook_list_data_t; |
46 | 47 |
47 static GSList *hk_handler_queue = NULL; | 48 static GSList *hk_handler_queue = NULL; |
48 | 49 |
49 void hk_add_handler (hk_handler_t handler, gpointer userdata) | 50 void hk_add_handler (hk_handler_t handler, guint32 flags, gpointer userdata) |
50 { | 51 { |
51 hook_list_data_t *h = g_new (hook_list_data_t, 1); | 52 hook_list_data_t *h = g_new (hook_list_data_t, 1); |
52 h->handler = handler; | 53 h->handler = handler; |
54 h->flags = flags; | |
53 h->userdata = userdata; | 55 h->userdata = userdata; |
54 hk_handler_queue = g_slist_append (hk_handler_queue, h); | 56 hk_handler_queue = g_slist_append (hk_handler_queue, h); |
55 } | 57 } |
56 | 58 |
57 static gint hk_queue_search_cb (hook_list_data_t *a, hook_list_data_t *b) | 59 static gint hk_queue_search_cb (hook_list_data_t *a, hook_list_data_t *b) |
62 return 1; | 64 return 1; |
63 } | 65 } |
64 | 66 |
65 void hk_del_handler (hk_handler_t handler, gpointer userdata) | 67 void hk_del_handler (hk_handler_t handler, gpointer userdata) |
66 { | 68 { |
67 hook_list_data_t h = { handler, userdata }; | 69 hook_list_data_t h = { handler, 0, userdata }; |
68 GSList *el = g_slist_find_custom (hk_handler_queue, &h, (GCompareFunc) hk_queue_search_cb); | 70 GSList *el = g_slist_find_custom (hk_handler_queue, &h, (GCompareFunc) hk_queue_search_cb); |
69 if (el) { | 71 if (el) { |
70 g_free (el->data); | 72 g_free (el->data); |
71 hk_handler_queue = g_slist_delete_link (hk_handler_queue, el); | 73 hk_handler_queue = g_slist_delete_link (hk_handler_queue, el); |
72 } | 74 } |
273 { NULL, NULL }, | 275 { NULL, NULL }, |
274 }; | 276 }; |
275 #endif | 277 #endif |
276 while (h) { | 278 while (h) { |
277 hook_list_data_t *data = h->data; | 279 hook_list_data_t *data = h->data; |
278 (data->handler) (args, data->userdata); | 280 if (data->flags & HOOK_MESSAGE_IN) |
281 (data->handler) (HOOK_MESSAGE_IN, args, data->userdata); | |
279 h = g_slist_next (h); | 282 h = g_slist_next (h); |
280 } | 283 } |
281 } | 284 } |
282 } | 285 } |
283 #endif | 286 #endif |
371 { "message", wmsg }, | 374 { "message", wmsg }, |
372 { NULL, NULL }, | 375 { NULL, NULL }, |
373 }; | 376 }; |
374 while (h) { | 377 while (h) { |
375 hook_list_data_t *data = h->data; | 378 hook_list_data_t *data = h->data; |
376 (data->handler) (args, data->userdata); | 379 if (data->flags & HOOK_MESSAGE_OUT) |
380 (data->handler) (HOOK_MESSAGE_OUT, args, data->userdata); | |
377 h = g_slist_next (h); | 381 h = g_slist_next (h); |
378 } | 382 } |
379 } | 383 } |
380 } | 384 } |
381 #endif | 385 #endif |
468 }; | 472 }; |
469 os[0] = imstatus2char[oldstat]; | 473 os[0] = imstatus2char[oldstat]; |
470 ns[0] = imstatus2char[status]; | 474 ns[0] = imstatus2char[status]; |
471 while (h) { | 475 while (h) { |
472 hook_list_data_t *data = h->data; | 476 hook_list_data_t *data = h->data; |
473 (data->handler) (args, data->userdata); | 477 if (data->flags & HOOK_STATUS_CHANGE) |
478 (data->handler) (HOOK_STATUS_CHANGE, args, data->userdata); | |
474 h = g_slist_next (h); | 479 h = g_slist_next (h); |
475 } | 480 } |
476 } | 481 } |
477 } | 482 } |
478 #endif | 483 #endif |
500 { NULL, NULL }, | 505 { NULL, NULL }, |
501 }; | 506 }; |
502 ns[0] = imstatus2char[new_status]; | 507 ns[0] = imstatus2char[new_status]; |
503 while (h) { | 508 while (h) { |
504 hook_list_data_t *data = h->data; | 509 hook_list_data_t *data = h->data; |
505 (data->handler) (args, data->userdata); | 510 if (data->flags & HOOK_MY_STATUS_CHANGE) |
511 (data->handler) (HOOK_MY_STATUS_CHANGE, args, data->userdata); | |
506 h = g_slist_next (h); | 512 h = g_slist_next (h); |
507 } | 513 } |
508 } | 514 } |
509 } | 515 } |
510 #endif | 516 #endif |
540 { "hook", hookname }, | 546 { "hook", hookname }, |
541 { NULL, NULL }, | 547 { NULL, NULL }, |
542 }; | 548 }; |
543 while (h) { | 549 while (h) { |
544 hook_list_data_t *data = h->data; | 550 hook_list_data_t *data = h->data; |
545 (data->handler) (args, data->userdata); | 551 if (data->flags & HOOK_INTERNAL) |
552 (data->handler) (HOOK_INTERNAL, args, data->userdata); | |
546 h = g_slist_next (h); | 553 h = g_slist_next (h); |
547 } | 554 } |
548 } | 555 } |
549 } | 556 } |
550 #endif | 557 #endif |