timer.xml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  4. <book id="timer" xmlns:xi="http://www.w3.org/2001/XInclude">
  5. <bookinfo>
  6. <title>timer module</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Tomas</firstname>
  10. <surname>Mandys</surname>
  11. <affiliation><orgname>Iptel.org</orgname></affiliation>
  12. <address>
  13. <email>tomas dot mandys at iptel dot org</email>
  14. </address>
  15. </author>
  16. </authorgroup>
  17. <copyright>
  18. <year>2007</year>
  19. <holder>iptelorg GmbH</holder>
  20. </copyright>
  21. </bookinfo>
  22. <toc></toc>
  23. <chapter>
  24. <title>Admin Guide</title>
  25. <section id="timer.overview">
  26. <title>Overview</title>
  27. <para>
  28. The module supports triggering specific route block on timer.
  29. </para>
  30. </section>
  31. <section id="timer.dep">
  32. <title>Dependencies</title>
  33. <para>
  34. none
  35. </para>
  36. </section>
  37. <section id="timer.syntax">
  38. <title>ABNF syntax</title>
  39. <programlisting>
  40. timer_id = alphanum
  41. slow_fast = "slow" | "fast"
  42. declare_timer_syntax = timer_id "=" (route#|route_name) "," interval "," slow_fast "," ["enable"]
  43. enable_disable = "0" | "1"
  44. </programlisting>
  45. </section>
  46. <section id="timer.parameters">
  47. <title>Parameters</title>
  48. <section id="timer.p.declare_timer">
  49. <title><varname>declare_timer</varname> (string)</title>
  50. <para>
  51. Declares timer route which will be called in specific interval.
  52. </para>
  53. <para>
  54. The format is:
  55. </para>
  56. <programlisting>
  57. declare_timer = declare_timer_syntax
  58. </programlisting>
  59. <para>
  60. <emphasis>timer_id</emphasis> is timer identifier, <emphasis>route</emphasis> is handler to be called when
  61. timer is triggered, <emphasis>interval</emphasis> is timer interval in milliseconds, <emphasis>slow_fast</emphasis>
  62. determines if handler will be hooked in slow or fast timer queue, fast timer handler returns
  63. as quickly as possible, slow timer handler may spend longer time, see ser/doc/timers.txt documentation. Use <emphasis>enable</emphasis>
  64. to enable timer when ser is starting, otherwise use <function>timer_enable</function> to start it later.
  65. </para>
  66. <example>
  67. <title>Example <varname>declare_timer</varname></title>
  68. <programlisting>
  69. ...
  70. modparam("timer", "declare_timer", "MY_TIMER=MY_TIMER_ROUTE,10,slow,enable");
  71. ...
  72. </programlisting>
  73. </example>
  74. </section>
  75. </section>
  76. <section id="timer.functions">
  77. <title>Functions</title>
  78. <section id="timer.p.timer_enable">
  79. <title>
  80. <function>timer_enable(timer_id, enable_disable)</function>
  81. </title>
  82. <para>
  83. Enable/disable timer route specified by <varname>timer_id</varname>. Because of timer core API the callback
  84. is not disabled immediately but is removed from handler by itself not to decrease performance.
  85. Disabling and enabling in sequence may be tricky.
  86. <emphasis>timer_id</emphasis> references to timer declared by <varname>declare_timer</varname>.
  87. </para>
  88. <example>
  89. <title><function>timer_enable</function> usage</title>
  90. <programlisting>
  91. ...
  92. timer_enable("MY_TIMER", 1);
  93. ...
  94. </programlisting>
  95. </example>
  96. </section>
  97. <section id="timer.timer.timer_id.enabled">
  98. <title>
  99. <function>@timer.timer.timer_id.enabled</function>
  100. </title>
  101. <para>
  102. Return true ("1") if timer specified by <varname>timer_id</varname> is enabled,
  103. otherwise returns false ("0").
  104. </para>
  105. <example>
  106. <title><function>timer.timer.timer_id.enabled</function> usage</title>
  107. <programlisting>
  108. if (@timer.timer.MY_TIMER.enabled == "1") {
  109. ....
  110. }
  111. </programlisting>
  112. </example>
  113. </section>
  114. <section id="timer.executed">
  115. <title>
  116. <function>@timer.executed</function>
  117. </title>
  118. <para>
  119. Returns name of timer which has been executed, i.e. non empty value is returned only
  120. when handler is being processed.
  121. </para>
  122. <example>
  123. <title><function>timer.executed</function> usage</title>
  124. <programlisting>
  125. if (@timer.executed != "") {
  126. # timer is being handled
  127. ....
  128. }
  129. </programlisting>
  130. </example>
  131. </section>
  132. </section>
  133. <section id="timer.examples">
  134. <title>Examples</title>
  135. <example>
  136. <title>timer common example</title>
  137. <programlisting>
  138. loadmodule "modules/xprint/xprint.so"
  139. loadmodule "modules/timer/timer.so"
  140. modparam("timer", "declare_timer", "tmr1=ONTIMER,1000");
  141. modparam("timer", "declare_timer", "tmr2=ONTIMER2,2000,slow,enable");
  142. route["print"] {
  143. xplog("L_INFO", "fired: %@timer.executed\n");
  144. }
  145. route["ONTIMER"] {
  146. # do something
  147. route("print");}
  148. route["ONTIMER2"] {
  149. # do something
  150. timer_enable("tmr1", 0);
  151. route("print");
  152. }
  153. </programlisting>
  154. </example>
  155. <example>
  156. <title>Using timer module for testing a functionality</title>
  157. <para>
  158. The timer module may be used to test a functionality being developed and
  159. not requiring real request.A developer may put tested code in route section
  160. which is called once after ser starts.
  161. </para>
  162. <programlisting>
  163. loadmodule "timer";
  164. loadmodule "xprint";
  165. modparam("timer", "declare_timer", "TIMER_TEST=TEST,100,,enable");
  166. route {
  167. xplog("L_E","main route");
  168. }
  169. route[TEST] {
  170. timer_enable("TIMER_TEST", "0");
  171. xplog("L_E","test start\n");
  172. # add here tested functionality
  173. xplog("L_E","test end\n");
  174. }
  175. </programlisting>
  176. </example>
  177. </section>
  178. </chapter>
  179. </book>