core: fix warnings/eliminate unused variables
[sip-router] / events.c
1 /**
2  * $Id$
3  *
4  * Copyright (C) 2009 SIP-Router.org
5  *
6  * This file is part of Extensible SIP Router, a free SIP server.
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20
21 /*!
22  * \file
23  * \brief SIP-router core :: 
24  * \ingroup core
25  * Module: \ref core
26  */
27
28 #include "dprint.h"
29 #include "mem/mem.h"
30 #include "events.h"
31
32 static sr_event_cb_t _sr_events_list;
33 static int _sr_events_inited = 0;
34
35 /**
36  *
37  */
38 void sr_event_cb_init(void)
39 {
40         if(_sr_events_inited == 0)
41         {
42                 memset(&_sr_events_list, 0, sizeof(sr_event_cb_t));
43                 _sr_events_inited = 1;
44         }
45 }
46
47 /**
48  *
49  */
50 int sr_event_register_cb(int type, sr_event_cb_f f)
51 {
52         sr_event_cb_init();
53         switch(type) {
54                 case SREV_NET_DATA_IN:
55                                 if(_sr_events_list.net_data_in==0)
56                                         _sr_events_list.net_data_in = f;
57                                 else return -1;
58                         break;
59                 case SREV_NET_DATA_OUT:
60                                 if(_sr_events_list.net_data_out==0)
61                                         _sr_events_list.net_data_out = f;
62                                 else return -1;
63                         break;
64                 case SREV_CORE_STATS:
65                                 if(_sr_events_list.core_stats==0)
66                                         _sr_events_list.core_stats = f;
67                                 else return -1;
68                         break;
69                 case SREV_CFG_RUN_ACTION:
70                                 if(_sr_events_list.run_action==0)
71                                         _sr_events_list.run_action = f;
72                                 else return -1;
73                         break;
74                 case SREV_PKG_SET_USED:
75                                 if(_sr_events_list.pkg_set_used==0)
76                                         _sr_events_list.pkg_set_used = f;
77                                 else return -1;
78                         break;
79                 case SREV_PKG_SET_REAL_USED:
80                                 if(_sr_events_list.pkg_set_real_used==0)
81                                         _sr_events_list.pkg_set_real_used = f;
82                                 else return -1;
83                         break;
84                 default:
85                         return -1;
86         }
87         return 0;
88 }
89
90 /**
91  *
92  */
93 int sr_event_exec(int type, void *data)
94 {
95         int ret;
96 #ifdef EXTRA_DEBUG
97         str *p;
98 #endif /* EXTRA_DEBUG */
99         switch(type) {
100                 case SREV_NET_DATA_IN:
101                                 if(unlikely(_sr_events_list.net_data_in!=0))
102                                 {
103 #ifdef EXTRA_DEBUG
104                                         p = (str*)data;
105                                         LM_DBG("PRE-IN ++++++++++++++++++++++++++++++++\n"
106                                                         "%.*s\n+++++\n", p->len, p->s);
107 #endif /* EXTRA_DEBUG */
108                                         ret = _sr_events_list.net_data_in(data);
109 #ifdef EXTRA_DEBUG
110                                         LM_DBG("POST-IN ++++++++++++++++++++++++++++++++\n"
111                                                         "%.*s\n+++++\n", p->len, p->s);
112 #endif /* EXTRA_DEBUG */
113                                         return ret;
114                                 } else return 1;
115                         break;
116                 case SREV_NET_DATA_OUT:
117                                 if(unlikely(_sr_events_list.net_data_out!=0))
118                                 {
119 #ifdef EXTRA_DEBUG
120                                         p = (str*)data;
121                                         LM_DBG("PRE-OUT ++++++++++++++++++++\n"
122                                                         "%.*s\n+++++++++++++++++++\n", p->len, p->s);
123 #endif /* EXTRA_DEBUG */
124                                         ret = _sr_events_list.net_data_out(data);
125 #ifdef EXTRA_DEBUG
126                                         LM_DBG("POST-OUT ++++++++++++++++++++\n"
127                                                         "%.*s\n+++++++++++++++++++\n", p->len, p->s);
128 #endif /* EXTRA_DEBUG */
129                                         return ret;
130                                 } else return 1;
131                         break;
132                 case SREV_CORE_STATS:
133                                 if(unlikely(_sr_events_list.core_stats!=0))
134                                 {
135                                         ret = _sr_events_list.core_stats(data);
136                                         return ret;
137                                 } else return 1;
138                         break;
139                 case SREV_CFG_RUN_ACTION:
140                                 if(unlikely(_sr_events_list.run_action!=0))
141                                 {
142                                         ret = _sr_events_list.run_action(data);
143                                         return ret;
144                                 } else return 1;
145                 case SREV_PKG_SET_USED:
146                                 if(unlikely(_sr_events_list.pkg_set_used!=0))
147                                 {
148                                         ret = _sr_events_list.pkg_set_used(data);
149                                         return ret;
150                                 } else return 1;
151                 case SREV_PKG_SET_REAL_USED:
152                                 if(unlikely(_sr_events_list.pkg_set_real_used!=0))
153                                 {
154                                         ret = _sr_events_list.pkg_set_real_used(data);
155                                         return ret;
156                                 } else return 1;
157                 default:
158                         return -1;
159         }
160 }
161
162 /**
163  *
164  */
165 int sr_event_enabled(int type)
166 {
167         switch(type) {
168                 case SREV_NET_DATA_IN:
169                                 return (_sr_events_list.net_data_in!=0)?1:0;
170                 case SREV_NET_DATA_OUT:
171                                 return (_sr_events_list.net_data_out!=0)?1:0;
172                 case SREV_CORE_STATS:
173                                 return (_sr_events_list.core_stats!=0)?1:0;
174                 case SREV_CFG_RUN_ACTION:
175                                 return (_sr_events_list.run_action!=0)?1:0;
176                 case SREV_PKG_SET_USED:
177                                 return (_sr_events_list.pkg_set_used!=0)?1:0;
178                 case SREV_PKG_SET_REAL_USED:
179                                 return (_sr_events_list.pkg_set_real_used!=0)?1:0;
180         }
181         return 0;
182 }
183