~ubuntu-branches/ubuntu/raring/sflphone/raring

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject/pjsip/include/pjsip/sip_event.h

  • Committer: Package Import Robot
  • Author(s): Francois Marier
  • Date: 2011-11-25 13:24:12 UTC
  • mfrom: (4.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20111125132412-dc4qvhyosk74cd42
Tags: 1.0.1-4
Don't assume that arch:all packages will get built (closes: #649726)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: sip_event.h 3553 2011-05-05 06:14:19Z nanang $ */
 
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
 
 
38
 
 
39
/** 
 
40
 * Event IDs.
 
41
 */
 
42
typedef enum pjsip_event_id_e
 
43
{
 
44
    /** Unidentified event. */
 
45
    PJSIP_EVENT_UNKNOWN,
 
46
 
 
47
    /** Timer event, normally only used internally in transaction. */
 
48
    PJSIP_EVENT_TIMER,
 
49
 
 
50
    /** Message transmission event. */
 
51
    PJSIP_EVENT_TX_MSG,
 
52
 
 
53
    /** Message received event. */
 
54
    PJSIP_EVENT_RX_MSG,
 
55
 
 
56
    /** Transport error event. */
 
57
    PJSIP_EVENT_TRANSPORT_ERROR,
 
58
 
 
59
    /** Transaction state changed event. */
 
60
    PJSIP_EVENT_TSX_STATE,
 
61
 
 
62
    /** Indicates that the event was triggered by user action. */
 
63
    PJSIP_EVENT_USER
 
64
 
 
65
} pjsip_event_id_e;
 
66
 
 
67
 
 
68
/**
 
69
 * This structure describe event descriptor to fully identify a SIP event.
 
70
 *
 
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.
 
75
 *
 
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.
 
79
 */
 
80
struct pjsip_event
 
81
{
 
82
    /** This is necessary so that we can put events as a list. */
 
83
    PJ_DECL_LIST_MEMBER(struct pjsip_event);
 
84
 
 
85
    /** The event type, can be any value of \b pjsip_event_id_e.
 
86
     */
 
87
    pjsip_event_id_e type;
 
88
 
 
89
    /**
 
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.
 
93
     */
 
94
    union
 
95
    {
 
96
        /** Timer event. */
 
97
        struct
 
98
        {
 
99
            pj_timer_entry *entry;      /**< The timer entry.           */
 
100
        } timer;
 
101
 
 
102
        /** Transaction state has changed event. */
 
103
        struct
 
104
        {
 
105
            union
 
106
            {
 
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.              */
 
112
            } src;
 
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
 
120
                                         *      - PJSIP_EVENT_USER
 
121
                                         */
 
122
        } tsx_state;
 
123
 
 
124
        /** Message transmission event. */
 
125
        struct
 
126
        {
 
127
            pjsip_tx_data       *tdata; /**< The transmit data buffer.  */
 
128
 
 
129
        } tx_msg;
 
130
 
 
131
        /** Transmission error event. */
 
132
        struct
 
133
        {
 
134
            pjsip_tx_data       *tdata; /**< The transmit data.         */
 
135
            pjsip_transaction   *tsx;   /**< The transaction.           */
 
136
        } tx_error;
 
137
 
 
138
        /** Message arrival event. */
 
139
        struct
 
140
        {
 
141
            pjsip_rx_data       *rdata; /**< The receive data buffer.   */
 
142
        } rx_msg;
 
143
 
 
144
        /** User event. */
 
145
        struct
 
146
        {
 
147
            void                *user1; /**< User data 1.               */
 
148
            void                *user2; /**< User data 2.               */
 
149
            void                *user3; /**< User data 3.               */
 
150
            void                *user4; /**< User data 4.               */
 
151
        } user;
 
152
 
 
153
    } body;
 
154
};
 
155
 
 
156
/**
 
157
 * Init timer event.
 
158
 */
 
159
#define PJSIP_EVENT_INIT_TIMER(event,pentry)            \
 
160
        do { \
 
161
            (event).type = PJSIP_EVENT_TIMER;           \
 
162
            (event).body.timer.entry = pentry;          \
 
163
        } while (0)
 
164
 
 
165
/**
 
166
 * Init tsx state event.
 
167
 */
 
168
#define PJSIP_EVENT_INIT_TSX_STATE(event,ptsx,ptype,pdata,prev)   \
 
169
        do { \
 
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;       \
 
175
        } while (0)
 
176
 
 
177
/**
 
178
 * Init tx msg event.
 
179
 */
 
180
#define PJSIP_EVENT_INIT_TX_MSG(event,ptdata)   \
 
181
        do { \
 
182
            (event).type = PJSIP_EVENT_TX_MSG;          \
 
183
            (event).body.tx_msg.tdata = ptdata;         \
 
184
        } while (0)
 
185
 
 
186
/**
 
187
 * Init rx msg event.
 
188
 */
 
189
#define PJSIP_EVENT_INIT_RX_MSG(event,prdata)   \
 
190
        do { \
 
191
            (event).type = PJSIP_EVENT_RX_MSG;          \
 
192
            (event).body.rx_msg.rdata = prdata;         \
 
193
        } while (0)
 
194
 
 
195
/**
 
196
 * Init transport error event.
 
197
 */
 
198
#define PJSIP_EVENT_INIT_TRANSPORT_ERROR(event,ptsx,ptdata)   \
 
199
        do { \
 
200
            (event).type = PJSIP_EVENT_TRANSPORT_ERROR; \
 
201
            (event).body.tx_error.tsx = ptsx;           \
 
202
            (event).body.tx_error.tdata = ptdata;       \
 
203
        } while (0)
 
204
 
 
205
/**
 
206
 * Init user event.
 
207
 */
 
208
#define PJSIP_EVENT_INIT_USER(event,u1,u2,u3,u4)    \
 
209
        do { \
 
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;     \
 
215
        } while (0)
 
216
 
 
217
/**
 
218
 * Get the event string from the event ID.
 
219
 * @param e the event ID.
 
220
 * @note defined in sip_util.c
 
221
 */
 
222
PJ_DECL(const char *) pjsip_event_str(pjsip_event_id_e e);
 
223
 
 
224
/**
 
225
 * @}
 
226
 */
 
227
 
 
228
PJ_END_DECL
 
229
 
 
230
#endif  /* __PJSIP_SIP_EVENT_H__ */