Debian Codegraph @

Xpjproject/pjsip/include/pjsua2/types.hpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2013 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #ifndef __PJSUA2_TYPES_HPP__
19 #define __PJSUA2_TYPES_HPP__
20
21 #ifdef _MSC_VER
22 # pragma warning( disable : 4290 ) // exception spec ignored
23 # pragma warning( disable : 4512 ) // can't generate assignment op
24 #endif
25
26 /**
27 * @file pjsua2/types.hpp
28 * @brief PJSUA2 Base Types
29 */
30 #include <pjsua2/config.hpp>
31
32 #include <string>
33 #include <vector>
34 #include <map>
35
36 /** PJSUA2 API is inside pj namespace */
37 namespace pj
38 {
39
40 /**
41 * @defgroup PJSUA2_TYPES General Data Structure
42 * @ingroup PJSUA2_DS
43 * @{
44 */
45
46 using std::string;
47 using std::vector;
48
49 /** Array of strings */
50 typedef std::vector<std::string> StringVector;
51
52 /** Array of integers */
53 typedef std::vector<int> IntVector;
54
55 /** Array of bytes */
56 typedef std::vector<unsigned char> ByteVector;
57
58 /** Map string to string */
59 typedef std::map<std::string, std::string> StringToStringMap;
60
61 /**
62 * Type of token, i.e. arbitrary application user data
63 */
64 typedef void *Token;
65
66 /**
67 * Socket address, encoded as string. The socket address contains host
68 * and port number in "host[:port]" format. The host part may contain
69 * hostname, domain name, IPv4 or IPv6 address. For IPv6 address, the
70 * address will be enclosed with square brackets, e.g. "[::1]:5060".
71 */
72 typedef string SocketAddress;
73
74 /** Array of socket address */
75 typedef StringVector SocketAddressVector;
76
77 /**
78 * Transport ID is an integer.
79 */
80 typedef int TransportId;
81
82 /**
83 * Transport handle, corresponds to pjsip_transport instance.
84 */
85 typedef void *TransportHandle;
86
87 /**
88 * Timer entry, corresponds to pj_timer_entry
89 */
90 typedef void *TimerEntry;
91
92 /**
93 * Generic data
94 */
95 typedef void *GenericData;
96
97 /*
98 * Forward declaration of Account and Call to be used
99 * by Endpoint.
100 */
101 class Account;
102 class Call;
103
104
105 /**
106 * Constants
107 */
108 enum
109 {
110 /** Invalid ID, equal to PJSUA_INVALID_ID */
111 INVALID_ID = -1,
112
113 /** Success, equal to PJ_SUCCESS */
114 SUCCESS = 0
115 };
116
117 //////////////////////////////////////////////////////////////////////////////
118
119 /**
120 * This structure contains information about an error that is thrown
121 * as an exception.
122 */
123 struct Error
124 {
125 /** The error code. */
126 pj_status_t status;
127
128 /** The PJSUA API operation that throws the error. */
129 string title;
130
131 /** The error message */
132 string reason;
133
134 /** The PJSUA source file that throws the error */
135 string srcFile;
136
137 /** The line number of PJSUA source file that throws the error */
138 int srcLine;
139
140 /** Build error string. */
141 string info(bool multi_line=false) const;
142
143 /** Default constructor */
144 Error();
145
146 /**
147 * Construct an Error instance from the specified parameters. If
148 * \a prm_reason is empty, it will be filled with the error description
149 * for the status code.
150 */
151 Error(pj_status_t prm_status,
152 const string &prm_title,
153 const string &prm_reason,
154 const string &prm_src_file,
155 int prm_src_line);
156 };
157
158
159 /*
160 * Error utilities.
161 */
162 #if PJSUA2_ERROR_HAS_EXTRA_INFO
163 # define PJSUA2_RAISE_ERROR(status) \
164 PJSUA2_RAISE_ERROR2(status, __FUNCTION__)
165
166 # define PJSUA2_RAISE_ERROR2(status,op) \
167 PJSUA2_RAISE_ERROR3(status, op, string())
168
169 # define PJSUA2_RAISE_ERROR3(status,op,txt) \
170 do { \
171 Error err_ = Error(status, op, txt, __FILE__, __LINE__); \
172 PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
173 throw err_; \
174 } while (0)
175
176 #else
177 /** Raise Error exception */
178 # define PJSUA2_RAISE_ERROR(status) \
179 PJSUA2_RAISE_ERROR2(status, string())
180
181 /** Raise Error exception */
182 # define PJSUA2_RAISE_ERROR2(status,op) \
183 PJSUA2_RAISE_ERROR3(status, op, string())
184
185 /** Raise Error exception */
186 # define PJSUA2_RAISE_ERROR3(status,op,txt) \
187 do { \
188 Error err_ = Error(status, op, txt, string(), 0); \
189 PJ_LOG(1,(THIS_FILE, "%s", err_.info().c_str())); \
190 throw err_; \
191 } while (0)
192
193 #endif
194
195 /** Raise Error exception if the expression fails */
196 #define PJSUA2_CHECK_RAISE_ERROR2(status, op) \
197 do { \
198 if (status != PJ_SUCCESS) { \
199 PJSUA2_RAISE_ERROR2(status, op); \
200 } \
201 } while (0)
202
203 /** Raise Error exception if the status fails */
204 #define PJSUA2_CHECK_RAISE_ERROR(status) \
205 PJSUA2_CHECK_RAISE_ERROR2(status, "")
206
207 /** Raise Error exception if the expression fails */
208 #define PJSUA2_CHECK_EXPR(expr) \
209 do { \
210 pj_status_t the_status = expr; \
211 PJSUA2_CHECK_RAISE_ERROR2(the_status, #expr); \
212 } while (0)
213
214 /** Run the statement and catch and ignore Error exception */
215 #define PJSUA2_CATCH_IGNORE(stmt) \
216 try { \
217 stmt; \
218 } catch (Error &err) { \
219 PJ_UNUSED_ARG(err); \
220 }
221
222 //////////////////////////////////////////////////////////////////////////////
223 /**
224 * Version information.
225 */
226 struct Version
227 {
228 /** Major number */
229 int major;
230
231 /** Minor number */
232 int minor;
233
234 /** Additional revision number */
235 int rev;
236
237 /** Version suffix (e.g. "-svn") */
238 string suffix;
239
240 /** The full version info (e.g. "2.1.0-svn") */
241 string full;
242
243 /**
244 * PJLIB version number as three bytes with the following format:
245 * 0xMMIIRR00, where MM: major number, II: minor number, RR: revision
246 * number, 00: always zero for now.
247 */
248 unsigned numeric;
249 };
250
251 //////////////////////////////////////////////////////////////////////////////
252
253 /**
254 * Representation of time value.
255 */
256 struct TimeVal
257 {
258 /**
259 * The seconds part of the time.
260 */
261 long sec;
262
263 /**
264 * The miliseconds fraction of the time.
265 */
266 long msec;
267
268 public:
269 TimeVal() : sec(0), msec(0)
270 {}
271
272 /**
273 * Convert from pjsip
274 */
275 void fromPj(const pj_time_val &prm);
276 };
277
278 /**
279 * @} PJSUA2
280 */
281
282 } // namespace pj
283
284
285
286 #endif /* __PJSUA2_TYPES_HPP__ */