src: minor update in header file
[transsip.git] / src / notifier.c
blob1c0c8f9f3d47f53676f25b9ce47e6363aa3c611f
1 /*
2 * transsip - the telephony toolkit
3 * By Daniel Borkmann <daniel@transsip.org>
4 * Copyright 2011, 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>
5 * Subject to the GPL, version 2.
6 */
8 #include <stdint.h>
9 #include <errno.h>
11 #include "notifier.h"
12 #include "built_in.h"
14 int register_event_hook(struct event_block **head,
15 struct event_block *block)
17 if (!block || !head)
18 return -EINVAL;
19 if (!block->hook)
20 return -EINVAL;
22 while ((*head) != NULL) {
23 if (block->prio > (*head)->prio)
24 break;
26 head = &((*head)->next);
29 block->next = (*head);
30 (*head) = block;
32 return 0;
35 int register_event_hook_once(struct event_block **head,
36 struct event_block *block)
38 if (!block || !head)
39 return -EINVAL;
40 if (!block->hook)
41 return -EINVAL;
43 while ((*head) != NULL) {
44 if (unlikely(block == (*head)))
45 return -EEXIST;
47 if (block->prio > (*head)->prio)
48 break;
50 head = &((*head)->next);
53 block->next = (*head);
54 (*head) = block;
56 return 0;
59 int unregister_event_hook(struct event_block **head,
60 struct event_block *block)
62 if (!block || !head)
63 return -EINVAL;
65 while ((*head) != NULL) {
66 if (unlikely(block == (*head))) {
67 (*head) = block->next;
68 break;
71 head = &((*head)->next);
74 return 0;
77 int call_event_hooks(struct event_block **head, unsigned long event,
78 const void *arg, int *called)
80 int ret = BLOCK_SUCC_DONE;
81 struct event_block *block = *head, *next_block;
83 if (!head || !arg)
84 return -EINVAL;
85 if (called)
86 (*called) = 0;
88 while (block) {
89 next_block = block->next;
91 ret = block->hook(block, event, arg);
92 if (ret & BLOCK_STOP_CHAIN)
93 break;
95 if(called)
96 (*called)++;
98 block = next_block;
101 return ret;