1
/* $Id: sip_event.h 3553 2011-05-05 06:14:19Z nanang $ */
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.
42
typedef enum pjsip_event_id_e
44
/** Unidentified event. */
47
/** Timer event, normally only used internally in transaction. */
50
/** Message transmission event. */
53
/** Message received event. */
56
/** Transport error event. */
57
PJSIP_EVENT_TRANSPORT_ERROR,
59
/** Transaction state changed event. */
60
PJSIP_EVENT_TSX_STATE,
62
/** Indicates that the event was triggered by user action. */
69
* This structure describe event descriptor to fully identify a SIP event.
71
* Events are the only way for a lower layer object to inform something
72
* to higher layer objects. Normally this is achieved by means of callback,
73
* i.e. the higher layer objects register a callback to handle the event on
74
* the lower layer objects.
76
* This event descriptor is used for example by transactions, to inform
77
* endpoint about events, and by transports, to inform endpoint about
78
* unexpected transport error.
82
/** This is necessary so that we can put events as a list. */
83
PJ_DECL_LIST_MEMBER(struct pjsip_event);
85
/** The event type, can be any value of \b pjsip_event_id_e.
87
pjsip_event_id_e type;
90
* The event body as union, which fields depends on the event type.
91
* By convention, the first member of each struct in the union must be
92
* the pointer which is relevant to the event.
99
pj_timer_entry *entry; /**< The timer entry. */
102
/** Transaction state has changed event. */
107
pjsip_rx_data *rdata; /**< The incoming message. */
108
pjsip_tx_data *tdata; /**< The outgoing message. */
109
pj_timer_entry *timer; /**< The timer. */
110
pj_status_t status;/**< Transport error status. */
111
void *data; /**< Generic data. */
113
pjsip_transaction *tsx; /**< The transaction. */
114
int prev_state; /**< Previous state. */
115
pjsip_event_id_e type; /**< Type of event source:
116
* - PJSIP_EVENT_TX_MSG
117
* - PJSIP_EVENT_RX_MSG,
118
* - PJSIP_EVENT_TRANSPORT_ERROR
119
* - PJSIP_EVENT_TIMER
124
/** Message transmission event. */
127
pjsip_tx_data *tdata; /**< The transmit data buffer. */
131
/** Transmission error event. */
134
pjsip_tx_data *tdata; /**< The transmit data. */
135
pjsip_transaction *tsx; /**< The transaction. */
138
/** Message arrival event. */
141
pjsip_rx_data *rdata; /**< The receive data buffer. */
147
void *user1; /**< User data 1. */
148
void *user2; /**< User data 2. */
149
void *user3; /**< User data 3. */
150
void *user4; /**< User data 4. */
159
#define PJSIP_EVENT_INIT_TIMER(event,pentry) \
161
(event).type = PJSIP_EVENT_TIMER; \
162
(event).body.timer.entry = pentry; \
166
* Init tsx state event.
168
#define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata,prev) \
170
(event).type = PJSIP_EVENT_TSX_STATE; \
171
(event).body.tsx_state.tsx = ptsx; \
172
(event).body.tsx_state.type = ptype; \
173
(event).body.tsx_state.src.data = pdata; \
174
(event).body.tsx_state.prev_state = prev; \
180
#define PJSIP_EVENT_INIT_TX_MSG(event,ptdata) \
182
(event).type = PJSIP_EVENT_TX_MSG; \
183
(event).body.tx_msg.tdata = ptdata; \
189
#define PJSIP_EVENT_INIT_RX_MSG(event,prdata) \
191
(event).type = PJSIP_EVENT_RX_MSG; \
192
(event).body.rx_msg.rdata = prdata; \
196
* Init transport error event.
198
#define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata) \
200
(event).type = PJSIP_EVENT_TRANSPORT_ERROR; \
201
(event).body.tx_error.tsx = ptsx; \
202
(event).body.tx_error.tdata = ptdata; \
208
#define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4) \
210
(event).type = PJSIP_EVENT_USER; \
211
(event).body.user.user1 = (void*)u1; \
212
(event).body.user.user2 = (void*)u2; \
213
(event).body.user.user3 = (void*)u3; \
214
(event).body.user.user4 = (void*)u4; \
218
* Get the event string from the event ID.
219
* @param e the event ID.
220
* @note defined in sip_util.c
222
PJ_DECL(const char *) pjsip_event_str(pjsip_event_id_e e);
230
#endif /* __PJSIP_SIP_EVENT_H__ */