sip_event.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJSIP_SIP_EVENT_H__
  20. #define __PJSIP_SIP_EVENT_H__
  21. /**
  22. * @file sip_event.h
  23. * @brief SIP Event
  24. */
  25. PJ_BEGIN_DECL
  26. /**
  27. * @defgroup PJSIP_EVENT Event
  28. * @ingroup PJSIP_CORE_CORE
  29. * @brief Representation of events as they are distributed among modules.
  30. * @{
  31. */
  32. #include <pj/types.h>
  33. #include <pj/timer.h>
  34. /**
  35. * Event IDs.
  36. */
  37. typedef enum pjsip_event_id_e
  38. {
  39. /** Unidentified event. */
  40. PJSIP_EVENT_UNKNOWN,
  41. /** Timer event, normally only used internally in transaction. */
  42. PJSIP_EVENT_TIMER,
  43. /** Message transmission event. */
  44. PJSIP_EVENT_TX_MSG,
  45. /** Message received event. */
  46. PJSIP_EVENT_RX_MSG,
  47. /** Transport error event. */
  48. PJSIP_EVENT_TRANSPORT_ERROR,
  49. /** Transaction state changed event. */
  50. PJSIP_EVENT_TSX_STATE,
  51. /** Indicates that the event was triggered by user action. */
  52. PJSIP_EVENT_USER
  53. } pjsip_event_id_e;
  54. /**
  55. * This structure describe event descriptor to fully identify a SIP event.
  56. *
  57. * Events are the only way for a lower layer object to inform something
  58. * to higher layer objects. Normally this is achieved by means of callback,
  59. * i.e. the higher layer objects register a callback to handle the event on
  60. * the lower layer objects.
  61. *
  62. * This event descriptor is used for example by transactions, to inform
  63. * endpoint about events, and by transports, to inform endpoint about
  64. * unexpected transport error.
  65. */
  66. struct pjsip_event
  67. {
  68. /** This is necessary so that we can put events as a list. */
  69. PJ_DECL_LIST_MEMBER(struct pjsip_event);
  70. /** The event type, can be any value of \b pjsip_event_id_e.
  71. */
  72. pjsip_event_id_e type;
  73. /**
  74. * The event body as union, which fields depends on the event type.
  75. * By convention, the first member of each struct in the union must be
  76. * the pointer which is relevant to the event.
  77. */
  78. union
  79. {
  80. /** Timer event. */
  81. struct
  82. {
  83. pj_timer_entry *entry; /**< The timer entry. */
  84. } timer;
  85. /** Transaction state has changed event. */
  86. struct
  87. {
  88. union
  89. {
  90. pjsip_rx_data *rdata; /**< The incoming message. */
  91. pjsip_tx_data *tdata; /**< The outgoing message. */
  92. pj_timer_entry *timer; /**< The timer. */
  93. pj_status_t status;/**< Transport error status. */
  94. void *data; /**< Generic data. */
  95. } src;
  96. pjsip_transaction *tsx; /**< The transaction. */
  97. int prev_state; /**< Previous state. */
  98. pjsip_event_id_e type; /**< Type of event source:
  99. * - PJSIP_EVENT_TX_MSG
  100. * - PJSIP_EVENT_RX_MSG,
  101. * - PJSIP_EVENT_TRANSPORT_ERROR
  102. * - PJSIP_EVENT_TIMER
  103. * - PJSIP_EVENT_USER
  104. */
  105. } tsx_state;
  106. /** Message transmission event. */
  107. struct
  108. {
  109. pjsip_tx_data *tdata; /**< The transmit data buffer. */
  110. } tx_msg;
  111. /** Transmission error event. */
  112. struct
  113. {
  114. pjsip_tx_data *tdata; /**< The transmit data. */
  115. pjsip_transaction *tsx; /**< The transaction. */
  116. } tx_error;
  117. /** Message arrival event. */
  118. struct
  119. {
  120. pjsip_rx_data *rdata; /**< The receive data buffer. */
  121. } rx_msg;
  122. /** User event. */
  123. struct
  124. {
  125. void *user1; /**< User data 1. */
  126. void *user2; /**< User data 2. */
  127. void *user3; /**< User data 3. */
  128. void *user4; /**< User data 4. */
  129. } user;
  130. } body;
  131. };
  132. /**
  133. * Init timer event.
  134. */
  135. #define PJSIP_EVENT_INIT_TIMER(event,pentry) \
  136. do { \
  137. (event).type = PJSIP_EVENT_TIMER; \
  138. (event).body.timer.entry = pentry; \
  139. } while (0)
  140. /**
  141. * Init tsx state event.
  142. */
  143. #define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata,prev) \
  144. do { \
  145. (event).type = PJSIP_EVENT_TSX_STATE; \
  146. (event).body.tsx_state.tsx = ptsx; \
  147. (event).body.tsx_state.type = ptype; \
  148. (event).body.tsx_state.src.data = pdata; \
  149. (event).body.tsx_state.prev_state = prev; \
  150. } while (0)
  151. /**
  152. * Init tx msg event.
  153. */
  154. #define PJSIP_EVENT_INIT_TX_MSG(event,ptdata) \
  155. do { \
  156. (event).type = PJSIP_EVENT_TX_MSG; \
  157. (event).body.tx_msg.tdata = ptdata; \
  158. } while (0)
  159. /**
  160. * Init rx msg event.
  161. */
  162. #define PJSIP_EVENT_INIT_RX_MSG(event,prdata) \
  163. do { \
  164. (event).type = PJSIP_EVENT_RX_MSG; \
  165. (event).body.rx_msg.rdata = prdata; \
  166. } while (0)
  167. /**
  168. * Init transport error event.
  169. */
  170. #define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata) \
  171. do { \
  172. (event).type = PJSIP_EVENT_TRANSPORT_ERROR; \
  173. (event).body.tx_error.tsx = ptsx; \
  174. (event).body.tx_error.tdata = ptdata; \
  175. } while (0)
  176. /**
  177. * Init user event.
  178. */
  179. #define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4) \
  180. do { \
  181. (event).type = PJSIP_EVENT_USER; \
  182. (event).body.user.user1 = (void*)u1; \
  183. (event).body.user.user2 = (void*)u2; \
  184. (event).body.user.user3 = (void*)u3; \
  185. (event).body.user.user4 = (void*)u4; \
  186. } while (0)
  187. /**
  188. * Get the event string from the event ID.
  189. * @param e the event ID.
  190. * @note defined in sip_util.c
  191. */
  192. PJ_DECL(const char *) pjsip_event_str(pjsip_event_id_e e);
  193. /**
  194. * @}
  195. */
  196. PJ_END_DECL
  197. #endif /* __PJSIP_SIP_EVENT_H__ */