File: timer.xml

package info (click to toggle)
kamailio 4.2.0-2%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 56,276 kB
  • sloc: ansic: 552,836; xml: 166,484; sh: 8,659; makefile: 7,676; sql: 6,235; perl: 3,487; yacc: 3,428; python: 1,457; cpp: 1,219; php: 1,047; java: 449; pascal: 194; cs: 40; awk: 27
file content (218 lines) | stat: -rw-r--r-- 5,458 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" 
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<book id="timer" xmlns:xi="http://www.w3.org/2001/XInclude">
    <bookinfo>
        <title>timer module</title>
	<authorgroup>
	    <author>
		<firstname>Tomas</firstname>
		<surname>Mandys</surname>
		<affiliation><orgname>Iptel.org</orgname></affiliation>
		<address>
		    <email>tomas dot mandys at iptel dot org</email>
		</address>
	    </author>
	</authorgroup>
	<copyright>
	    <year>2007</year>
	    <holder>iptelorg GmbH</holder>
	</copyright>

    </bookinfo>
    <toc></toc>

    <chapter>
	<title>Admin Guide</title>
    <section id="timer.overview">
		<title>Overview</title>
		<para>
		The module supports triggering specific route block on timer.
		</para>
    </section>

	<section id="timer.dep">
		<title>Dependencies</title>
				   
		<para>
		none
		</para>
	</section>

	<section id="timer.syntax">
		<title>ABNF syntax</title>
		<programlisting>
	timer_id = alphanum
	slow_fast = "slow" | "fast"
	declare_timer_syntax = timer_id "=" (route#|route_name) "," interval "," slow_fast "," ["enable"]
	enable_disable = "0" | "1"

		</programlisting>
	</section>

	<section id="timer.parameters">

		<title>Parameters</title>

		<section id="timer.p.declare_timer">
			<title><varname>declare_timer</varname> (string)</title>
			<para>
			Declares timer route which will be called in specific interval.
			</para>
			<para>
			The format is:
			</para>
			<programlisting>
			declare_timer = declare_timer_syntax
			</programlisting>
			<para>
			<emphasis>timer_id</emphasis> is timer identifier, <emphasis>route</emphasis> is handler to be called when
			timer is triggered, <emphasis>interval</emphasis> is timer interval in milliseconds, <emphasis>slow_fast</emphasis>
			determines if handler will be hooked in slow or fast timer queue, fast timer handler returns
			as quickly as possible, slow timer handler may spend longer time, see ser/doc/timers.txt documentation. Use <emphasis>enable</emphasis>
			to enable timer when ser is starting, otherwise use <function>timer_enable</function> to start it later.		
			</para>
			<example>
				<title>Example <varname>declare_timer</varname></title>
				<programlisting>
	...
	modparam("timer", "declare_timer", "MY_TIMER=MY_TIMER_ROUTE,10,slow,enable");
	...
				</programlisting>
			</example>
		</section>

	</section>

	<section id="timer.functions">
		<title>Functions</title>

		<section id="timer.p.timer_enable">
			<title>
				<function>timer_enable(timer_id, enable_disable)</function>
			</title>
			<para>
				Enable/disable timer route specified by <varname>timer_id</varname>. Because of timer core API the callback
				is not disabled immediately but is removed from handler by itself not to decrease performance.
				Disabling and enabling in sequence may be tricky.
								  
				<emphasis>timer_id</emphasis> references to timer declared by <varname>declare_timer</varname>.
			</para>

			<example>
				<title><function>timer_enable</function> usage</title>
				<programlisting>
	...
	timer_enable("MY_TIMER", 1);
	...
				</programlisting>
			</example>
		</section>

		<section id="timer.timer.timer_id.enabled">
			<title>
				<function>@timer.timer.timer_id.enabled</function>
			</title>
			<para>
				Return true ("1") if timer specified by <varname>timer_id</varname> is enabled,
				otherwise returns false ("0").
			</para>

			<example>
				<title><function>timer.timer.timer_id.enabled</function> usage</title>
				<programlisting>

	if (@timer.timer.MY_TIMER.enabled == "1") {
	....
	}
				</programlisting>
			</example>
		</section>

		<section id="timer.executed">
			<title>
				<function>@timer.executed</function>
			</title>
			<para>
				Returns name of timer which has been executed, i.e. non empty value is returned only 
				when handler is being processed.
			</para>

			<example>
				<title><function>timer.executed</function> usage</title>
				<programlisting>

	if (@timer.executed != "") {
		# timer is being handled
	....
	}
				</programlisting>
			</example>
		</section>


	</section>

    <section id="timer.examples">
		<title>Examples</title>
		<example>
			<title>timer common example</title>
			<programlisting>
loadmodule "modules/xprint/xprint.so"
loadmodule "modules/timer/timer.so"

modparam("timer", "declare_timer", "tmr1=ONTIMER,1000"); 
modparam("timer", "declare_timer", "tmr2=ONTIMER2,2000,slow,enable");

route["print"] {
	xplog("L_INFO", "fired: %@timer.executed\n");
}

route["ONTIMER"] {
	# do something
	route("print");}


route["ONTIMER2"] {
	# do something
	timer_enable("tmr1", 0);
	route("print");
}

			</programlisting>

		</example>
		<example>
			<title>Using timer module for testing a functionality</title>
			<para>
				The timer module may be used to test a functionality being developed and 
				not requiring real request.A developer may put tested code in route section
				which is called once after ser starts.
			</para>
			<programlisting>
			
loadmodule "timer"; 
loadmodule "xprint";  

modparam("timer", "declare_timer", "TIMER_TEST=TEST,100,,enable"); 

route {  
	xplog("L_E","main route"); 
}  
    
route[TEST] {  
	timer_enable("TIMER_TEST", "0");  
	xplog("L_E","test start\n");    
		
	# add here tested functionality
		
	xplog("L_E","test end\n"); 
}
			</programlisting>

		</example>
	</section>
    </chapter>
</book>