timer.xml 5.4 KB

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