- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,201 +0,0 @@ |
1 |
-/* |
|
2 |
- * timer related functions (public interface) |
|
3 |
- * |
|
4 |
- * Copyright (C) 2001-2003 FhG Fokus |
|
5 |
- * |
|
6 |
- * This file is part of Kamailio, a free SIP server. |
|
7 |
- * |
|
8 |
- * Kamailio is free software; you can redistribute it and/or modify |
|
9 |
- * it under the terms of the GNU General Public License as published by |
|
10 |
- * the Free Software Foundation; either version 2 of the License, or |
|
11 |
- * (at your option) any later version |
|
12 |
- * |
|
13 |
- * Kamailio is distributed in the hope that it will be useful, |
|
14 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
- * GNU General Public License for more details. |
|
17 |
- * |
|
18 |
- * You should have received a copy of the GNU General Public License |
|
19 |
- * along with this program; if not, write to the Free Software |
|
20 |
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
21 |
- */ |
|
22 |
-/** |
|
23 |
- * @file |
|
24 |
- * @brief Kamailio core :: timer related functions (public interface) |
|
25 |
- * @ingroup core |
|
26 |
- * |
|
27 |
- * Module: \ref core |
|
28 |
- * |
|
29 |
- * - \ref TimerDoc |
|
30 |
- */ |
|
31 |
- |
|
32 |
- |
|
33 |
-/** |
|
34 |
- * @page TimerDoc Kamailio's timer documentation |
|
35 |
- * @verbinclude timers.txt |
|
36 |
- * |
|
37 |
- */ |
|
38 |
- |
|
39 |
- |
|
40 |
- |
|
41 |
-#ifndef timer_h |
|
42 |
-#define timer_h |
|
43 |
- |
|
44 |
-#define USE_SLOW_TIMER /* use another process to run the timer handlers |
|
45 |
- * marked "slow" */ |
|
46 |
-/*#define TIMER_DEBUG -- compile with -DTIMER_DEBUG*/ |
|
47 |
- |
|
48 |
-#include "clist.h" |
|
49 |
-#include "dprint.h" |
|
50 |
-#include "timer_ticks.h" |
|
51 |
- |
|
52 |
-#ifdef USE_SLOW_TIMER |
|
53 |
-#include <sys/types.h> |
|
54 |
- |
|
55 |
-typedef unsigned short slow_idx_t; /* type fot the slow index */ |
|
56 |
-extern pid_t slow_timer_pid; |
|
57 |
-#endif |
|
58 |
- |
|
59 |
- |
|
60 |
- |
|
61 |
- |
|
62 |
- |
|
63 |
-/* deprecated, old, kept for compatibility */ |
|
64 |
-typedef void (timer_function)(unsigned int ticks, void* param); |
|
65 |
-/* deprecated, old, kept for compatibility |
|
66 |
- get_ticks()*TIMER_TICK used to be the time in s |
|
67 |
- for new code, use get_ticks_raw() and one of the macros defined in |
|
68 |
- timer_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
|
69 |
-#define TIMER_TICK 1 /* 1 s, kept for compatibility */ |
|
70 |
- |
|
71 |
-/*function prototype to execute on mili-second based basic timers */ |
|
72 |
-typedef void (utimer_function)(unsigned int uticks, void* param); |
|
73 |
- |
|
74 |
-struct timer_ln; /* forward decl */ |
|
75 |
-/* new |
|
76 |
- * params: |
|
77 |
- * - handle pointer to the corresponding struct timer_ln |
|
78 |
- * return: 0 if the timer is one shot, new expire interval if not, -1 |
|
79 |
- * if periodic |
|
80 |
- * e.g.: - a periodic timer would return: (ticks_t)(-1) or |
|
81 |
- * ((struct timer_ln*)handle)->initial_timeout |
|
82 |
- * - a timer which wants to expire again in x ms would return: |
|
83 |
- * (x * TICKS_HZ + 999)/1000 |
|
84 |
- */ |
|
85 |
-typedef ticks_t (timer_handler_f)(ticks_t t, struct timer_ln* tl, |
|
86 |
- void* data); |
|
87 |
- |
|
88 |
- |
|
89 |
-/* timer flags */ |
|
90 |
-#define F_TIMER_FAST 1 |
|
91 |
-#define F_TIMER_ON_SLOW_LIST 0x100 |
|
92 |
-#define F_TIMER_ACTIVE 0x200 /* timer is running or has run and expired |
|
93 |
- * (one shot) */ |
|
94 |
-#ifdef TIMER_DEBUG |
|
95 |
-#define F_TIMER_DELETED 0x400 |
|
96 |
-#endif |
|
97 |
- |
|
98 |
-struct timer_ln{ /* timer_link already used in tm */ |
|
99 |
- struct timer_ln* next; |
|
100 |
- struct timer_ln* prev; |
|
101 |
- ticks_t expire; |
|
102 |
- ticks_t initial_timeout; |
|
103 |
- void* data; |
|
104 |
- timer_handler_f* f; |
|
105 |
- volatile unsigned short flags; |
|
106 |
-#ifdef USE_SLOW_TIMER |
|
107 |
- volatile slow_idx_t slow_idx; |
|
108 |
-#else |
|
109 |
- unsigned short reserved; |
|
110 |
-#endif |
|
111 |
-#ifdef TIMER_DEBUG |
|
112 |
- unsigned int expires_no; /* timer handler calls */ |
|
113 |
- const char* add_file; |
|
114 |
- const char* add_func; |
|
115 |
- unsigned add_line; |
|
116 |
- unsigned add_calls; |
|
117 |
- const char* del_file; |
|
118 |
- const char* del_func; |
|
119 |
- unsigned del_line; |
|
120 |
- unsigned int del_calls; |
|
121 |
- unsigned int init; /* how many times was init/re-init */ |
|
122 |
-#endif |
|
123 |
-}; |
|
124 |
- |
|
125 |
- |
|
126 |
- |
|
127 |
-void timer_main(void); /* timer main loop, never exists */ |
|
128 |
- |
|
129 |
- |
|
130 |
-int init_timer(void); |
|
131 |
-int arm_timer(void); |
|
132 |
-void destroy_timer(void); |
|
133 |
- |
|
134 |
-#ifdef USE_SLOW_TIMER |
|
135 |
-int arm_slow_timer(void); |
|
136 |
-void slow_timer_main(void); |
|
137 |
-#endif |
|
138 |
- |
|
139 |
- |
|
140 |
-struct timer_ln* timer_alloc(void); |
|
141 |
-void timer_free(struct timer_ln* t); |
|
142 |
- |
|
143 |
-#ifdef TIMER_DEBUG |
|
144 |
-/* use for a deleted/expired timer that you want to add again */ |
|
145 |
-#define timer_reinit(tl) \ |
|
146 |
- do{ \ |
|
147 |
- (tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
|
148 |
- F_TIMER_ACTIVE));\ |
|
149 |
- (tl)->init++; \ |
|
150 |
- }while(0) |
|
151 |
-#else |
|
152 |
-/* use for a deleted/expired timer that you want to add again */ |
|
153 |
-#define timer_reinit(tl) \ |
|
154 |
- (tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
|
155 |
- F_TIMER_ACTIVE)) |
|
156 |
-#endif |
|
157 |
- |
|
158 |
-#define timer_init(tl, fun, param, flgs) \ |
|
159 |
- do{ \ |
|
160 |
- memset((tl), 0, sizeof(struct timer_ln)); \ |
|
161 |
- (tl)->f=(fun); \ |
|
162 |
- (tl)->data=(param); \ |
|
163 |
- (tl)->flags=(flgs); \ |
|
164 |
- timer_reinit(tl); \ |
|
165 |
- }while(0) |
|
166 |
- |
|
167 |
-#ifdef TIMER_DEBUG |
|
168 |
-int timer_add_safe(struct timer_ln *tl, ticks_t delta, |
|
169 |
- const char*, const char*, unsigned); |
|
170 |
-int timer_del_safe(struct timer_ln *tl, |
|
171 |
- const char*, const char*, unsigned); |
|
172 |
-#define timer_add(tl, d) \ |
|
173 |
- timer_add_safe((tl), (d), __FILE__, __FUNCTION__, __LINE__) |
|
174 |
-#define timer_del(tl) \ |
|
175 |
- timer_del_safe((tl), __FILE__, __FUNCTION__, __LINE__) |
|
176 |
-#else |
|
177 |
-int timer_add_safe(struct timer_ln *tl, ticks_t delta); |
|
178 |
-int timer_del_safe(struct timer_ln *tl); |
|
179 |
-#define timer_add timer_add_safe |
|
180 |
-#define timer_del timer_del_safe |
|
181 |
-#endif |
|
182 |
- |
|
183 |
-void timer_allow_del(void); |
|
184 |
- |
|
185 |
-/* old timer compatibility functions & structure */ |
|
186 |
- |
|
187 |
-struct sr_timer{ |
|
188 |
- struct timer_ln tl; |
|
189 |
- int id; |
|
190 |
- timer_function* timer_f; |
|
191 |
- void* t_param; |
|
192 |
-}; |
|
193 |
- |
|
194 |
- |
|
195 |
-/*register a periodic timer; |
|
196 |
- * ret: <0 on error*/ |
|
197 |
-int register_timer(timer_function f, void* param, unsigned int interval); |
|
198 |
-ticks_t get_ticks(void); |
|
199 |
-ticks_t get_ticks_raw(void); |
|
200 |
- |
|
201 |
-#endif |
... | ... |
@@ -15,8 +15,8 @@ |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 | 17 |
* |
18 |
- * You should have received a copy of the GNU General Public License |
|
19 |
- * along with this program; if not, write to the Free Software |
|
18 |
+ * You should have received a copy of the GNU General Public License |
|
19 |
+ * along with this program; if not, write to the Free Software |
|
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 |
*/ |
22 | 22 |
/** |
... | ... |
@@ -41,8 +41,8 @@ |
41 | 41 |
#ifndef timer_h |
42 | 42 |
#define timer_h |
43 | 43 |
|
44 |
-#define USE_SLOW_TIMER /* use another process to run the timer handlers |
|
45 |
- marked "slow" */ |
|
44 |
+#define USE_SLOW_TIMER /* use another process to run the timer handlers |
|
45 |
+ * marked "slow" */ |
|
46 | 46 |
/*#define TIMER_DEBUG -- compile with -DTIMER_DEBUG*/ |
47 | 47 |
|
48 | 48 |
#include "clist.h" |
... | ... |
@@ -62,7 +62,7 @@ extern pid_t slow_timer_pid; |
62 | 62 |
|
63 | 63 |
/* deprecated, old, kept for compatibility */ |
64 | 64 |
typedef void (timer_function)(unsigned int ticks, void* param); |
65 |
-/* deprecated, old, kept for compatibility |
|
65 |
+/* deprecated, old, kept for compatibility |
|
66 | 66 |
get_ticks()*TIMER_TICK used to be the time in s |
67 | 67 |
for new code, use get_ticks_raw() and one of the macros defined in |
68 | 68 |
timer_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
... | ... |
@@ -72,7 +72,7 @@ typedef void (timer_function)(unsigned int ticks, void* param); |
72 | 72 |
typedef void (utimer_function)(unsigned int uticks, void* param); |
73 | 73 |
|
74 | 74 |
struct timer_ln; /* forward decl */ |
75 |
-/* new |
|
75 |
+/* new |
|
76 | 76 |
* params: |
77 | 77 |
* - handle pointer to the corresponding struct timer_ln |
78 | 78 |
* return: 0 if the timer is one shot, new expire interval if not, -1 |
... | ... |
@@ -89,19 +89,19 @@ typedef ticks_t (timer_handler_f)(ticks_t t, struct timer_ln* tl, |
89 | 89 |
/* timer flags */ |
90 | 90 |
#define F_TIMER_FAST 1 |
91 | 91 |
#define F_TIMER_ON_SLOW_LIST 0x100 |
92 |
-#define F_TIMER_ACTIVE 0x200 /* timer is running or has run and expired |
|
93 |
- (one shot) */ |
|
92 |
+#define F_TIMER_ACTIVE 0x200 /* timer is running or has run and expired |
|
93 |
+ * (one shot) */ |
|
94 | 94 |
#ifdef TIMER_DEBUG |
95 |
-#define F_TIMER_DELETED 0x400 |
|
95 |
+#define F_TIMER_DELETED 0x400 |
|
96 | 96 |
#endif |
97 | 97 |
|
98 | 98 |
struct timer_ln{ /* timer_link already used in tm */ |
99 | 99 |
struct timer_ln* next; |
100 | 100 |
struct timer_ln* prev; |
101 |
- ticks_t expire; |
|
101 |
+ ticks_t expire; |
|
102 | 102 |
ticks_t initial_timeout; |
103 | 103 |
void* data; |
104 |
- timer_handler_f* f; |
|
104 |
+ timer_handler_f* f; |
|
105 | 105 |
volatile unsigned short flags; |
106 | 106 |
#ifdef USE_SLOW_TIMER |
107 | 107 |
volatile slow_idx_t slow_idx; |
... | ... |
@@ -145,14 +145,14 @@ void timer_free(struct timer_ln* t); |
145 | 145 |
#define timer_reinit(tl) \ |
146 | 146 |
do{ \ |
147 | 147 |
(tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
148 |
- F_TIMER_ACTIVE));\ |
|
148 |
+ F_TIMER_ACTIVE));\ |
|
149 | 149 |
(tl)->init++; \ |
150 | 150 |
}while(0) |
151 | 151 |
#else |
152 | 152 |
/* use for a deleted/expired timer that you want to add again */ |
153 | 153 |
#define timer_reinit(tl) \ |
154 | 154 |
(tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
155 |
- F_TIMER_ACTIVE)) |
|
155 |
+ F_TIMER_ACTIVE)) |
|
156 | 156 |
#endif |
157 | 157 |
|
158 | 158 |
#define timer_init(tl, fun, param, flgs) \ |
... | ... |
@@ -165,7 +165,7 @@ void timer_free(struct timer_ln* t); |
165 | 165 |
}while(0) |
166 | 166 |
|
167 | 167 |
#ifdef TIMER_DEBUG |
168 |
-int timer_add_safe(struct timer_ln *tl, ticks_t delta, |
|
168 |
+int timer_add_safe(struct timer_ln *tl, ticks_t delta, |
|
169 | 169 |
const char*, const char*, unsigned); |
170 | 170 |
int timer_del_safe(struct timer_ln *tl, |
171 | 171 |
const char*, const char*, unsigned); |
... | ... |
@@ -1,19 +1,16 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 |
- * |
|
5 | 2 |
* timer related functions (public interface) |
6 | 3 |
* |
7 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
8 | 5 |
* |
9 |
- * This file is part of SIP-router, a free SIP server. |
|
6 |
+ * This file is part of Kamailio, a free SIP server. |
|
10 | 7 |
* |
11 |
- * SIP-router is free software; you can redistribute it and/or modify |
|
8 |
+ * Kamailio is free software; you can redistribute it and/or modify |
|
12 | 9 |
* it under the terms of the GNU General Public License as published by |
13 | 10 |
* the Free Software Foundation; either version 2 of the License, or |
14 | 11 |
* (at your option) any later version |
15 | 12 |
* |
16 |
- * SIP-router is distributed in the hope that it will be useful, |
|
13 |
+ * Kamailio is distributed in the hope that it will be useful, |
|
17 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | 16 |
* GNU General Public License for more details. |
... | ... |
@@ -22,14 +19,9 @@ |
22 | 19 |
* along with this program; if not, write to the Free Software |
23 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
24 | 21 |
*/ |
25 |
-/* History: |
|
26 |
- * -------- |
|
27 |
- * 2005-07-27 complete re-design/re-implementation (andrei) |
|
28 |
- */ |
|
29 |
- |
|
30 | 22 |
/** |
31 | 23 |
* @file |
32 |
- * @brief SIP-router core :: timer related functions (public interface) |
|
24 |
+ * @brief Kamailio core :: timer related functions (public interface) |
|
33 | 25 |
* @ingroup core |
34 | 26 |
* |
35 | 27 |
* Module: \ref core |
... | ... |
@@ -20,7 +20,7 @@ |
20 | 20 |
* |
21 | 21 |
* You should have received a copy of the GNU General Public License |
22 | 22 |
* along with this program; if not, write to the Free Software |
23 |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
24 | 24 |
*/ |
25 | 25 |
/* History: |
26 | 26 |
* -------- |
In C language, a declaration in the form int f(); is equivalent to int f(...);, thus being able to accept an indefinit number of parameters. With the -Wstrict-prototypes GCC options, these declarations are reported as "function declaration isn’t a prototype".
On some cases, this may trick the compiler into generating unoptimized code (like preparing to handle variadic argument list).
In all cases having a declaration int f() and a definition inf f(int) is missleading, even if standard compliant.
This is still Work in Progress. (maybe adding the -Wstrict-prototypes option to default is desireable)
... | ... |
@@ -132,20 +132,20 @@ struct timer_ln{ /* timer_link already used in tm */ |
132 | 132 |
|
133 | 133 |
|
134 | 134 |
|
135 |
-void timer_main(); /* timer main loop, never exists */ |
|
135 |
+void timer_main(void); /* timer main loop, never exists */ |
|
136 | 136 |
|
137 | 137 |
|
138 |
-int init_timer(); |
|
139 |
-int arm_timer(); |
|
140 |
-void destroy_timer(); |
|
138 |
+int init_timer(void); |
|
139 |
+int arm_timer(void); |
|
140 |
+void destroy_timer(void); |
|
141 | 141 |
|
142 | 142 |
#ifdef USE_SLOW_TIMER |
143 |
-int arm_slow_timer(); |
|
144 |
-void slow_timer_main(); |
|
143 |
+int arm_slow_timer(void); |
|
144 |
+void slow_timer_main(void); |
|
145 | 145 |
#endif |
146 | 146 |
|
147 | 147 |
|
148 |
-struct timer_ln* timer_alloc(); |
|
148 |
+struct timer_ln* timer_alloc(void); |
|
149 | 149 |
void timer_free(struct timer_ln* t); |
150 | 150 |
|
151 | 151 |
#ifdef TIMER_DEBUG |
... | ... |
@@ -203,7 +203,7 @@ struct sr_timer{ |
203 | 203 |
/*register a periodic timer; |
204 | 204 |
* ret: <0 on error*/ |
205 | 205 |
int register_timer(timer_function f, void* param, unsigned int interval); |
206 |
-ticks_t get_ticks(); |
|
207 |
-ticks_t get_ticks_raw(); |
|
206 |
+ticks_t get_ticks(void); |
|
207 |
+ticks_t get_ticks_raw(void); |
|
208 | 208 |
|
209 | 209 |
#endif |
- renamed second-based timer functions from dummy to basic
... | ... |
@@ -76,6 +76,8 @@ typedef void (timer_function)(unsigned int ticks, void* param); |
76 | 76 |
timer_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
77 | 77 |
#define TIMER_TICK 1 /* 1 s, kept for compatibility */ |
78 | 78 |
|
79 |
+/*function prototype to execute on mili-second based basic timers */ |
|
80 |
+typedef void (utimer_function)(unsigned int uticks, void* param); |
|
79 | 81 |
|
80 | 82 |
struct timer_ln; /* forward decl */ |
81 | 83 |
/* new |
... | ... |
@@ -73,7 +73,7 @@ typedef void (timer_function)(unsigned int ticks, void* param); |
73 | 73 |
/* deprecated, old, kept for compatibility |
74 | 74 |
get_ticks()*TIMER_TICK used to be the time in s |
75 | 75 |
for new code, use get_ticks_raw() and one of the macros defined in |
76 |
- time_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
|
76 |
+ timer_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
|
77 | 77 |
#define TIMER_TICK 1 /* 1 s, kept for compatibility */ |
78 | 78 |
|
79 | 79 |
|
- changing from \ and ! to javadoc format
- adding new doxygen file headers
... | ... |
@@ -6,19 +6,14 @@ |
6 | 6 |
* |
7 | 7 |
* Copyright (C) 2001-2003 FhG Fokus |
8 | 8 |
* |
9 |
- * This file is part of ser, a free SIP server. |
|
9 |
+ * This file is part of SIP-router, a free SIP server. |
|
10 | 10 |
* |
11 |
- * ser is free software; you can redistribute it and/or modify |
|
11 |
+ * SIP-router is free software; you can redistribute it and/or modify |
|
12 | 12 |
* it under the terms of the GNU General Public License as published by |
13 | 13 |
* the Free Software Foundation; either version 2 of the License, or |
14 | 14 |
* (at your option) any later version |
15 | 15 |
* |
16 |
- * For a license to use the ser software under conditions |
|
17 |
- * other than those described here, or to purchase support for this |
|
18 |
- * software, please contact iptel.org by e-mail at the following addresses: |
|
19 |
- * info@iptel.org |
|
20 |
- * |
|
21 |
- * ser is distributed in the hope that it will be useful, |
|
16 |
+ * SIP-router is distributed in the hope that it will be useful, |
|
22 | 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 | 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 | 19 |
* GNU General Public License for more details. |
... | ... |
@@ -29,7 +29,24 @@ |
29 | 29 |
*/ |
30 | 30 |
/* History: |
31 | 31 |
* -------- |
32 |
- * 2005-07-27 complete re-design/re-implemnetation (andrei) |
|
32 |
+ * 2005-07-27 complete re-design/re-implementation (andrei) |
|
33 |
+ */ |
|
34 |
+ |
|
35 |
+/** |
|
36 |
+ * @file |
|
37 |
+ * @brief SIP-router core :: timer related functions (public interface) |
|
38 |
+ * @ingroup core |
|
39 |
+ * |
|
40 |
+ * Module: \ref core |
|
41 |
+ * |
|
42 |
+ * - \ref TimerDoc |
|
43 |
+ */ |
|
44 |
+ |
|
45 |
+ |
|
46 |
+/** |
|
47 |
+ * @page TimerDoc SIP-router's timer documentation |
|
48 |
+ * @verbinclude timers.txt |
|
49 |
+ * |
|
33 | 50 |
*/ |
34 | 51 |
|
35 | 52 |
|
... | ... |
@@ -161,7 +161,7 @@ void timer_free(struct timer_ln* t); |
161 | 161 |
#ifdef TIMER_DEBUG |
162 | 162 |
int timer_add_safe(struct timer_ln *tl, ticks_t delta, |
163 | 163 |
const char*, const char*, unsigned); |
164 |
-void timer_del_safe(struct timer_ln *tl, |
|
164 |
+int timer_del_safe(struct timer_ln *tl, |
|
165 | 165 |
const char*, const char*, unsigned); |
166 | 166 |
#define timer_add(tl, d) \ |
167 | 167 |
timer_add_safe((tl), (d), __FILE__, __FUNCTION__, __LINE__) |
... | ... |
@@ -169,7 +169,7 @@ void timer_del_safe(struct timer_ln *tl, |
169 | 169 |
timer_del_safe((tl), __FILE__, __FUNCTION__, __LINE__) |
170 | 170 |
#else |
171 | 171 |
int timer_add_safe(struct timer_ln *tl, ticks_t delta); |
172 |
-void timer_del_safe(struct timer_ln *tl); |
|
172 |
+int timer_del_safe(struct timer_ln *tl); |
|
173 | 173 |
#define timer_add timer_add_safe |
174 | 174 |
#define timer_del timer_del_safe |
175 | 175 |
#endif |
... | ... |
@@ -43,6 +43,7 @@ |
43 | 43 |
|
44 | 44 |
#include "clist.h" |
45 | 45 |
#include "dprint.h" |
46 |
+#include "timer_ticks.h" |
|
46 | 47 |
|
47 | 48 |
#ifdef USE_SLOW_TIMER |
48 | 49 |
#include <sys/types.h> |
... | ... |
@@ -51,8 +52,6 @@ typedef unsigned short slow_idx_t; /* type fot the slow index */ |
51 | 52 |
extern pid_t slow_timer_pid; |
52 | 53 |
#endif |
53 | 54 |
|
54 |
-typedef unsigned int ticks_t;/* type used to keep the ticks (must be 32 bits)*/ |
|
55 |
-typedef signed int s_ticks_t; /* signed ticks type */ |
|
56 | 55 |
|
57 | 56 |
|
58 | 57 |
|
... | ... |
@@ -2,7 +2,7 @@ |
2 | 2 |
* $Id$ |
3 | 3 |
* |
4 | 4 |
* |
5 |
- * timer related functions |
|
5 |
+ * timer related functions (public interface) |
|
6 | 6 |
* |
7 | 7 |
* Copyright (C) 2001-2003 FhG Fokus |
8 | 8 |
* |
... | ... |
@@ -27,38 +27,168 @@ |
27 | 27 |
* along with this program; if not, write to the Free Software |
28 | 28 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 | 29 |
*/ |
30 |
+/* History: |
|
31 |
+ * -------- |
|
32 |
+ * 2005-07-27 complete re-design/re-implemnetation (andrei) |
|
33 |
+ */ |
|
30 | 34 |
|
31 | 35 |
|
32 | 36 |
|
33 | 37 |
#ifndef timer_h |
34 | 38 |
#define timer_h |
35 | 39 |
|
40 |
+#define USE_SLOW_TIMER /* use another process to run the timer handlers |
|
41 |
+ marked "slow" */ |
|
42 |
+/*#define TIMER_DEBUG -- compile with -DTIMER_DEBUG*/ |
|
43 |
+ |
|
44 |
+#include "clist.h" |
|
45 |
+#include "dprint.h" |
|
46 |
+ |
|
47 |
+#ifdef USE_SLOW_TIMER |
|
48 |
+#include <sys/types.h> |
|
49 |
+ |
|
50 |
+typedef unsigned short slow_idx_t; /* type fot the slow index */ |
|
51 |
+extern pid_t slow_timer_pid; |
|
52 |
+#endif |
|
53 |
+ |
|
54 |
+typedef unsigned int ticks_t;/* type used to keep the ticks (must be 32 bits)*/ |
|
55 |
+typedef signed int s_ticks_t; /* signed ticks type */ |
|
56 |
+ |
|
57 |
+ |
|
58 |
+ |
|
59 |
+ |
|
60 |
+/* deprecated, old, kept for compatibility */ |
|
36 | 61 |
typedef void (timer_function)(unsigned int ticks, void* param); |
62 |
+/* deprecated, old, kept for compatibility |
|
63 |
+ get_ticks()*TIMER_TICK used to be the time in s |
|
64 |
+ for new code, use get_ticks_raw() and one of the macros defined in |
|
65 |
+ time_ticks.h (.e.g TICKS_TO_S(tick) to convert to s or ms )*/ |
|
66 |
+#define TIMER_TICK 1 /* 1 s, kept for compatibility */ |
|
37 | 67 |
|
38 | 68 |
|
39 |
-struct sr_timer{ |
|
40 |
- int id; |
|
41 |
- timer_function* timer_f; |
|
42 |
- void* t_param; |
|
43 |
- unsigned int interval; |
|
44 |
- |
|
45 |
- unsigned int expires; |
|
46 |
- |
|
47 |
- struct sr_timer* next; |
|
48 |
-}; |
|
69 |
+struct timer_ln; /* forward decl */ |
|
70 |
+/* new |
|
71 |
+ * params: |
|
72 |
+ * - handle pointer to the corresponding struct timer_ln |
|
73 |
+ * return: 0 if the timer is one shot, new expire interval if not, -1 |
|
74 |
+ * if periodic |
|
75 |
+ * e.g.: - a periodic timer would return: (ticks_t)(-1) or |
|
76 |
+ * ((struct timer_ln*)handle)->initial_timeout |
|
77 |
+ * - a timer which wants to expire again in x ms would return: |
|
78 |
+ * (x * TICKS_HZ + 999)/1000 |
|
79 |
+ */ |
|
80 |
+typedef ticks_t (timer_handler_f)(ticks_t t, struct timer_ln* tl, |
|
81 |
+ void* data); |
|
82 |
+ |
|
49 | 83 |
|
84 |
+/* timer flags */ |
|
85 |
+#define F_TIMER_FAST 1 |
|
86 |
+#define F_TIMER_ON_SLOW_LIST 0x100 |
|
87 |
+#define F_TIMER_ACTIVE 0x200 /* timer is running or has run and expired |
|
88 |
+ (one shot) */ |
|
89 |
+#ifdef TIMER_DEBUG |
|
90 |
+#define F_TIMER_DELETED 0x400 |
|
91 |
+#endif |
|
92 |
+ |
|
93 |
+struct timer_ln{ /* timer_link already used in tm */ |
|
94 |
+ struct timer_ln* next; |
|
95 |
+ struct timer_ln* prev; |
|
96 |
+ ticks_t expire; |
|
97 |
+ ticks_t initial_timeout; |
|
98 |
+ void* data; |
|
99 |
+ timer_handler_f* f; |
|
100 |
+ volatile unsigned short flags; |
|
101 |
+#ifdef USE_SLOW_TIMER |
|
102 |
+ volatile slow_idx_t slow_idx; |
|
103 |
+#else |
|
104 |
+ unsigned short reserved; |
|
105 |
+#endif |
|
106 |
+#ifdef TIMER_DEBUG |
|
107 |
+ unsigned int expires_no; /* timer handler calls */ |
|
108 |
+ const char* add_file; |
|
109 |
+ const char* add_func; |
|
110 |
+ unsigned add_line; |
|
111 |
+ unsigned add_calls; |
|
112 |
+ const char* del_file; |
|
113 |
+ const char* del_func; |
|
114 |
+ unsigned del_line; |
|
115 |
+ unsigned int del_calls; |
|
116 |
+ unsigned int init; /* how many times was init/re-init */ |
|
117 |
+#endif |
|
118 |
+}; |
|
50 | 119 |
|
51 | 120 |
|
52 |
-extern struct sr_timer* timer_list; |
|
53 | 121 |
|
122 |
+void timer_main(); /* timer main loop, never exists */ |
|
54 | 123 |
|
55 | 124 |
|
56 | 125 |
int init_timer(); |
126 |
+int arm_timer(); |
|
57 | 127 |
void destroy_timer(); |
128 |
+ |
|
129 |
+#ifdef USE_SLOW_TIMER |
|
130 |
+int arm_slow_timer(); |
|
131 |
+void slow_timer_main(); |
|
132 |
+#endif |
|
133 |
+ |
|
134 |
+ |
|
135 |
+struct timer_ln* timer_alloc(); |
|
136 |
+void timer_free(struct timer_ln* t); |
|
137 |
+ |
|
138 |
+#ifdef TIMER_DEBUG |
|
139 |
+/* use for a deleted/expired timer that you want to add again */ |
|
140 |
+#define timer_reinit(tl) \ |
|
141 |
+ do{ \ |
|
142 |
+ (tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
|
143 |
+ F_TIMER_ACTIVE));\ |
|
144 |
+ (tl)->init++; \ |
|
145 |
+ }while(0) |
|
146 |
+#else |
|
147 |
+/* use for a deleted/expired timer that you want to add again */ |
|
148 |
+#define timer_reinit(tl) \ |
|
149 |
+ (tl)->flags&=~((unsigned short)(F_TIMER_ON_SLOW_LIST | \ |
|
150 |
+ F_TIMER_ACTIVE)) |
|
151 |
+#endif |
|
152 |
+ |
|
153 |
+#define timer_init(tl, fun, param, flgs) \ |
|
154 |
+ do{ \ |
|
155 |
+ memset((tl), 0, sizeof(struct timer_ln)); \ |
|
156 |
+ (tl)->f=(fun); \ |
|
157 |
+ (tl)->data=(param); \ |
|
158 |
+ (tl)->flags=(flgs); \ |
|
159 |
+ timer_reinit(tl); \ |
|
160 |
+ }while(0) |
|
161 |
+ |
|
162 |
+#ifdef TIMER_DEBUG |
|
163 |
+int timer_add_safe(struct timer_ln *tl, ticks_t delta, |
|
164 |
+ const char*, const char*, unsigned); |
|
165 |
+void timer_del_safe(struct timer_ln *tl, |
|
166 |
+ const char*, const char*, unsigned); |
|
167 |
+#define timer_add(tl, d) \ |
|
168 |
+ timer_add_safe((tl), (d), __FILE__, __FUNCTION__, __LINE__) |
|
169 |
+#define timer_del(tl) \ |
|
170 |
+ timer_del_safe((tl), __FILE__, __FUNCTION__, __LINE__) |
|
171 |
+#else |
|
172 |
+int timer_add_safe(struct timer_ln *tl, ticks_t delta); |
|
173 |
+void timer_del_safe(struct timer_ln *tl); |
|
174 |
+#define timer_add timer_add_safe |
|
175 |
+#define timer_del timer_del_safe |
|
176 |
+#endif |
|
177 |
+ |
|
178 |
+/* old timer compatibility functions & structure */ |
|
179 |
+ |
|
180 |
+struct sr_timer{ |
|
181 |
+ struct timer_ln tl; |
|
182 |
+ int id; |
|
183 |
+ timer_function* timer_f; |
|
184 |
+ void* t_param; |
|
185 |
+}; |
|
186 |
+ |
|
187 |
+ |
|
58 | 188 |
/*register a periodic timer; |
59 | 189 |
* ret: <0 on error*/ |
60 | 190 |
int register_timer(timer_function f, void* param, unsigned int interval); |
61 |
-unsigned int get_ticks(); |
|
62 |
-void timer_ticker(); |
|
191 |
+ticks_t get_ticks(); |
|
192 |
+ticks_t get_ticks_raw(); |
|
63 | 193 |
|
64 | 194 |
#endif |
... | ... |
@@ -4,7 +4,7 @@ |
4 | 4 |
* |
5 | 5 |
* timer related functions |
6 | 6 |
* |
7 |
- * Copyright (C) 2001-2003 Fhg Fokus |
|
7 |
+ * Copyright (C) 2001-2003 FhG Fokus |
|
8 | 8 |
* |
9 | 9 |
* This file is part of ser, a free SIP server. |
10 | 10 |
* |
... | ... |
@@ -56,7 +56,7 @@ extern struct sr_timer* timer_list; |
56 | 56 |
int init_timer(); |
57 | 57 |
void destroy_timer(); |
58 | 58 |
/*register a periodic timer; |
59 |
- * ret: <0 on errror*/ |
|
59 |
+ * ret: <0 on error*/ |
|
60 | 60 |
int register_timer(timer_function f, void* param, unsigned int interval); |
61 | 61 |
unsigned int get_ticks(); |
62 | 62 |
void timer_ticker(); |
... | ... |
@@ -3,9 +3,33 @@ |
3 | 3 |
* |
4 | 4 |
* |
5 | 5 |
* timer related functions |
6 |
+ * |
|
7 |
+ * Copyright (C) 2001-2003 Fhg Fokus |
|
8 |
+ * |
|
9 |
+ * This file is part of ser, a free SIP server. |
|
10 |
+ * |
|
11 |
+ * ser is free software; you can redistribute it and/or modify |
|
12 |
+ * it under the terms of the GNU General Public License as published by |
|
13 |
+ * the Free Software Foundation; either version 2 of the License, or |
|
14 |
+ * (at your option) any later version |
|
15 |
+ * |
|
16 |
+ * For a license to use the ser software under conditions |
|
17 |
+ * other than those described here, or to purchase support for this |
|
18 |
+ * software, please contact iptel.org by e-mail at the following addresses: |
|
19 |
+ * info@iptel.org |
|
20 |
+ * |
|
21 |
+ * ser is distributed in the hope that it will be useful, |
|
22 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24 |
+ * GNU General Public License for more details. |
|
25 |
+ * |
|
26 |
+ * You should have received a copy of the GNU General Public License |
|
27 |
+ * along with this program; if not, write to the Free Software |
|
28 |
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
6 | 29 |
*/ |
7 | 30 |
|
8 | 31 |
|
32 |
+ |
|
9 | 33 |
#ifndef timer_h |
10 | 34 |
#define timer_h |
11 | 35 |
|
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,37 @@ |
1 |
+/* |
|
2 |
+ * $Id$ |
|
3 |
+ * |
|
4 |
+ * |
|
5 |
+ * timer related functions |
|
6 |
+ */ |
|
7 |
+ |
|
8 |
+ |
|
9 |
+#ifndef timer_h |
|
10 |
+#define timer_h |
|
11 |
+ |
|
12 |
+typedef void (timer_function)(unsigned int ticks, void* param); |
|
13 |
+ |
|
14 |
+ |
|
15 |
+struct sr_timer{ |
|
16 |
+ int id; |
|
17 |
+ timer_function* timer_f; |
|
18 |
+ void* t_param; |
|
19 |
+ unsigned int interval; |
|
20 |
+ |
|
21 |
+ unsigned int expires; |
|
22 |
+ |
|
23 |
+ struct sr_timer* next; |
|
24 |
+}; |
|
25 |
+ |
|
26 |
+ |
|
27 |
+ |
|
28 |
+extern struct sr_timer* timer_list; |
|
29 |
+ |
|
30 |
+ |
|
31 |
+ |
|
32 |
+/*register a periodic timer; |
|
33 |
+ * ret: <0 on errror*/ |
|
34 |
+int register_timer(timer_function f, void* param, unsigned int interval); |
|
35 |
+void timer_ticker(); |
|
36 |
+ |
|
37 |
+#endif |