timer_proc.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2009 iptelorg GmbH
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /*
  17. * History:
  18. * --------
  19. * 2009-03-10 initial version (andrei)
  20. */
  21. /**
  22. * @file
  23. * @brief SIP-router core :: timer_proc.h - separate process timers
  24. *
  25. * (unrelated to the main fast and slow timers)
  26. * @ingroup core
  27. * Module: @ref core
  28. */
  29. #ifndef __timer_proc_h
  30. #define __timer_proc_h
  31. #include "local_timer.h"
  32. /**
  33. * \brief update internal counters for running new basic sec. timers
  34. * @param timers number of basic timer processes
  35. * @return 0 on success; -1 on error
  36. */
  37. int register_basic_timers(int timers);
  38. #define register_dummy_timers register_basic_timers
  39. #define register_basic_utimers register_basic_utimers
  40. /**
  41. * \brief Forks a separate simple sleep() periodic timer
  42. *
  43. * Forks a very basic periodic timer process, that just sleep()s for
  44. * the specified interval and then calls the timer function.
  45. * The new "basic timer" process execution start immediately, the sleep()
  46. * is called first (so the first call to the timer function will happen
  47. * \<interval\> seconds after the call to fork_basic_timer)
  48. * @param child_id @see fork_process()
  49. * @param desc @see fork_process()
  50. * @param make_sock @see fork_process()
  51. * @param f timer function/callback
  52. * @param param parameter passed to the timer function
  53. * @param interval interval in seconds.
  54. * @return pid of the new process on success, -1 on error
  55. * (doesn't return anything in the child process)
  56. */
  57. int fork_basic_timer(int child_id, char* desc, int make_sock,
  58. timer_function* f, void* param, int interval);
  59. #define fork_dummy_timer fork_basic_timer
  60. /**
  61. * \brief Forks a separate simple milisecond-sleep() periodic timer
  62. *
  63. * Forks a very basic periodic timer process, that just ms-sleep()s for
  64. * the specified interval and then calls the timer function.
  65. * The new "basic timer" process execution start immediately, the ms-sleep()
  66. * is called first (so the first call to the timer function will happen
  67. * \<interval\> seconds after the call to fork_basic_utimer)
  68. * @param child_id @see fork_process()
  69. * @param desc @see fork_process()
  70. * @param make_sock @see fork_process()
  71. * @param f timer function/callback
  72. * @param param parameter passed to the timer function
  73. * @param uinterval interval in mili-seconds.
  74. * @return pid of the new process on success, -1 on error
  75. * (doesn't return anything in the child process)
  76. */
  77. int fork_basic_utimer(int child_id, char* desc, int make_sock,
  78. timer_function* f, void* param, int uinterval);
  79. /**
  80. * \brief Forks a timer process based on the local timer
  81. *
  82. * Forks a separate timer process running a local_timer.h type of timer
  83. * A pointer to the local_timer handle (allocated in shared memory) is
  84. * returned in lt_h. It can be used to add/delete more timers at runtime
  85. * (via local_timer_add()/local_timer_del() a.s.o).
  86. * If timers are added from separate processes, some form of locking must be
  87. * used (all the calls to local_timer* must be enclosed by locks if it
  88. * cannot be guaranteed that they cannot execute in the same time)
  89. * The timer "engine" must be run manually from the child process. For
  90. * example a very simple local timer process that just runs a single
  91. * periodic timer can be started in the following way:
  92. * struct local_timer* lt_h;
  93. *
  94. * pid=fork_local_timer_process(...., &lt_h);
  95. * if (pid==0){
  96. * timer_init(&my_timer, my_timer_f, 0, 0);
  97. * local_timer_add(&lt_h, &my_timer, S_TO_TICKS(10), get_ticks_raw());
  98. * while(1) { sleep(1); local_timer_run(lt, get_ticks_raw()); }
  99. * }
  100. *
  101. * @param child_id @see fork_process()
  102. * @param desc @see fork_process()
  103. * @param make_sock @see fork_process()
  104. * @param lt_h local_timer handler
  105. * @return pid to the parent, 0 to the child, -1 if error.
  106. */
  107. int fork_local_timer_process(int child_id, char* desc, int make_sock,
  108. struct local_timer** lt_h);
  109. /**
  110. * sync timers
  111. */
  112. int register_sync_timers(int timers);
  113. int fork_sync_timer(int child_id, char* desc, int make_sock,
  114. timer_function* f, void* param, int interval);
  115. int fork_sync_utimer(int child_id, char* desc, int make_sock,
  116. utimer_function* f, void* param, int uinterval);
  117. #endif /*__timer_proc_h*/
  118. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */