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