src: rename file from *-* to *_*
[transsip-mirror.git] / src / notifier.c
blob0795fe53df564146bc043a5a079cebe4956aa577
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 * Swiss federal institute of technology (ETH Zurich)
6 * Subject to the GPL, version 2.
7 */
9 #include <stdint.h>
10 #include <errno.h>
12 #include "notifier.h"
13 #include "built_in.h"
15 int register_event_hook(struct event_block **head,
16 struct event_block *block)
18 if (!block || !head)
19 return -EINVAL;
20 if (!block->hook)
21 return -EINVAL;
23 while ((*head) != NULL) {
24 if (block->prio > (*head)->prio)
25 break;
27 head = &((*head)->next);
30 block->next = (*head);
31 (*head) = block;
33 return 0;
36 int register_event_hook_once(struct event_block **head,
37 struct event_block *block)
39 if (!block || !head)
40 return -EINVAL;
41 if (!block->hook)
42 return -EINVAL;
44 while ((*head) != NULL) {
45 if (unlikely(block == (*head)))
46 return -EEXIST;
48 if (block->prio > (*head)->prio)
49 break;
51 head = &((*head)->next);
54 block->next = (*head);
55 (*head) = block;
57 return 0;
60 int unregister_event_hook(struct event_block **head,
61 struct event_block *block)
63 if (!block || !head)
64 return -EINVAL;
66 while ((*head) != NULL) {
67 if (unlikely(block == (*head))) {
68 (*head) = block->next;
69 break;
72 head = &((*head)->next);
75 return 0;
78 int call_event_hooks(struct event_block **head, unsigned long event,
79 const void *arg, int *called)
81 int ret = BLOCK_SUCC_DONE;
82 struct event_block *block = *head, *next_block;
84 if (!head || !arg)
85 return -EINVAL;
86 if (called)
87 (*called) = 0;
89 while (block) {
90 next_block = block->next;
92 ret = block->hook(block, event, arg);
93 if (ret & BLOCK_STOP_CHAIN)
94 break;
96 if(called)
97 (*called)++;
99 block = next_block;
102 return ret;