1
/* $Id: sip_event.h 4154 2012-06-05 10:41:17Z bennylp $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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.
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.
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
20
#ifndef __PJSIP_SIP_EVENT_H__
21
#define __PJSIP_SIP_EVENT_H__
31
* @defgroup PJSIP_EVENT Event
32
* @ingroup PJSIP_CORE_CORE
33
* @brief Representation of events as they are distributed among modules.
43
typedef enum pjsip_event_id_e
45
/** Unidentified event. */
48
/** Timer event, normally only used internally in transaction. */
51
/** Message transmission event. */
54
/** Message received event. */
57
/** Transport error event. */
58
PJSIP_EVENT_TRANSPORT_ERROR,
60
/** Transaction state changed event. */
61
PJSIP_EVENT_TSX_STATE,
63
/** Indicates that the event was triggered by user action. */
70
* This structure describe event descriptor to fully identify a SIP event.
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.
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.
83
/** This is necessary so that we can put events as a list. */
84
PJ_DECL_LIST_MEMBER(struct pjsip_event);
86
/** The event type, can be any value of \b pjsip_event_id_e.
88
pjsip_event_id_e type;
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.
100
pj_timer_entry *entry; /**< The timer entry. */
103
/** Transaction state has changed event. */
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. */
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
125
/** Message transmission event. */
128
pjsip_tx_data *tdata; /**< The transmit data buffer. */
132
/** Transmission error event. */
135
pjsip_tx_data *tdata; /**< The transmit data. */
136
pjsip_transaction *tsx; /**< The transaction. */
139
/** Message arrival event. */
142
pjsip_rx_data *rdata; /**< The receive data buffer. */
148
void *user1; /**< User data 1. */
149
void *user2; /**< User data 2. */
150
void *user3; /**< User data 3. */
151
void *user4; /**< User data 4. */
160
#define PJSIP_EVENT_INIT_TIMER(event,pentry) \
162
(event).type = PJSIP_EVENT_TIMER; \
163
(event).body.timer.entry = pentry; \
167
* Init tsx state event.
169
#define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata,prev) \
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; \
181
#define PJSIP_EVENT_INIT_TX_MSG(event,ptdata) \
183
(event).type = PJSIP_EVENT_TX_MSG; \
184
(event).body.tx_msg.tdata = ptdata; \
190
#define PJSIP_EVENT_INIT_RX_MSG(event,prdata) \
192
(event).type = PJSIP_EVENT_RX_MSG; \
193
(event).body.rx_msg.rdata = prdata; \
197
* Init transport error event.
199
#define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata) \
201
(event).type = PJSIP_EVENT_TRANSPORT_ERROR; \
202
(event).body.tx_error.tsx = ptsx; \
203
(event).body.tx_error.tdata = ptdata; \
209
#define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4) \
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; \
219
* Get the event string from the event ID.
220
* @param e the event ID.
221
* @note defined in sip_util.c
223
PJ_DECL(const char *) pjsip_event_str(pjsip_event_id_e e);
231
#endif /* __PJSIP_SIP_EVENT_H__ */