C++SDK  1.0.0
defines.h
浏览该文件的文档.
1 
2 #ifndef RTCDEFINES_H
3 #define RTCDEFINES_H
4 
6 // First definition: choose OS
8 
9 #ifdef WIN32
10  #ifndef RT_WIN32
11  #define RT_WIN32
12  #endif // RT_WIN32
13 #endif // WIN32
14 
15 #ifdef UNIX
16  #ifndef RT_UNIX
17  #define RT_UNIX
18  #endif // RT_UNIX
19 #endif // UNIX
20 
21 #ifdef LINUX
22  #ifndef RT_LINUX
23  #define RT_LINUX
24  #endif // RT_LINUX
25  #ifndef RT_UNIX
26  #define RT_UNIX
27  #endif // RT_UNIX
28 #endif // LINUX
29 
30 #ifdef ANDROID
31  #ifndef RT_ANDROID
32  #define RT_ANDROID
33  #endif // RT_LINUX
34  #ifndef RT_UNIX
35  #define RT_UNIX
36  #endif // RT_UNIX
37 #endif // ANDROID
38 
39 #ifdef MACOS
40  #ifndef RT_MACOS
41  #define RT_MACOS
42  #endif // RT_MACOS
43 #endif // MACOS
44 
45 #ifdef IOS
46 #ifndef RT_IOS
47 #define RT_IOS
48 #endif // RT_IOS
49 #endif // IOS
50 
51 
52 #if (defined(RT_LINUX) && !defined(RT_ANDROID)) || defined(RT_WIN32) || (defined(RT_MAC) && !defined(RT_IOS))
53 #ifndef RT_DESKTOP
54 #define RT_DESKTOP
55 #endif // RT_DESKTOP
56 #endif
57 
59 // OS API definition
61 
62 #ifdef RT_MACOS
63  #define _BSD_TIME_T_ long /* time() */
64  typedef _BSD_TIME_T_ time_t;
65  #ifndef MachOSupport
66  # define socklen_t int
67  #endif //MachOSupport
68  #define EINPROGRESS 36 /* Operation now in progress */
69  #define EINTR 4
70  #define EPERM 1
71  typedef int sem_t;
72  #define RLIMIT_NOFILE 8
73  //#define RT_HAS_BUILTIN_ATOMIC_OP 1
74  enum
75  {
76  PTHREAD_MUTEX_TIMED_NP,
77  PTHREAD_MUTEX_RECURSIVE_NP,
78  PTHREAD_MUTEX_ERRORCHECK_NP,
79  PTHREAD_MUTEX_ADAPTIVE_NP
80 
81  , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_ADAPTIVE_NP
82  };
83 
84  #ifndef MachOSupport
85  #include "ioccom.h"
86  #endif //MachOSupport
87 
88  /* Generic file-descriptor ioctl's. */
89  #define FIOCLEX _IO('f', 1) /* set close on exec on fd */
90  #define FIONCLEX _IO('f', 2) /* remove close on exec */
91  #define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
92  #define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
93  #define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
94  #define FIOSETOWN _IOW('f', 124, int) /* set owner */
95  #define FIOGETOWN _IOR('f', 123, int) /* get owner */
96  #define FIODTYPE _IOR('f', 122, int) /* get d_type */
97 
98  //for TCP
99  #ifndef MachOSupport
100  #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
101  #endif
102 
103  #ifndef MachOSupport
104  #define TCP_MAXSEG 0x02 /* set maximum segment size */
105  #endif
106 
107  #define TCP_NOPUSH 0x04 /* don't push last block of write */
108  #define TCP_NOOPT 0x08 /* don't use TCP options */
109 
110  #ifndef MachOSupport
111  #define TCP_KEEPALIVE 0x10 /* idle time used when SO_KEEPALIVE is enabled */
112  #endif
113 //pthread
114 
115  #define PTHREAD_CREATE_JOINABLE 1
116  #define PTHREAD_CREATE_DETACHED 2
117 
118  #define PTHREAD_INHERIT_SCHED 1
119  #define PTHREAD_EXPLICIT_SCHED 2
120 
121  #define PTHREAD_CANCEL_ENABLE 0x01 /* Cancel takes place at next cancellation point */
122  #define PTHREAD_CANCEL_DISABLE 0x00 /* Cancel postponed */
123  #define PTHREAD_CANCEL_DEFERRED 0x02 /* Cancel waits until cancellation point */
124  #define PTHREAD_CANCEL_ASYNCHRONOUS 0x00 /* Cancel occurs immediately */
125 
126  /* We only support PTHREAD_SCOPE_SYSTEM */
127  #define PTHREAD_SCOPE_SYSTEM 1
128  #define PTHREAD_SCOPE_PROCESS 2
129 
130  /* We only support PTHREAD_PROCESS_PRIVATE */
131  #define PTHREAD_PROCESS_SHARED 1
132  #define PTHREAD_PROCESS_PRIVATE 2
133 
134  //extern CHARSET_INFO *default_charset_info;
135  //#define my_ctype (default_charset_info->ctype)
136  //#define isspace(c) ((my_ctype+1)[(uchar) (c)] & _S)
137  // temp define for compiler
138 
139  #ifndef MachOSupport
140  struct timespec {
141  time_t tv_sec; /* seconds */
142  long tv_nsec; /* and nanoseconds */
143  };
144 
145  //#define EAGAIN 35
146  //#define EWOULDBLOCK EAGAIN
147  #define EWOULDBLOCK 35
148  #endif //MachOSupport
149 #endif
150 
151 #ifdef RT_WIN32
152 #ifndef _CRT_SECURE_NO_WARNINGS
153  #define _CRT_SECURE_NO_WARNINGS
154 #endif
155 
156 #ifndef _SCL_SECURE_NO_DEPRECATE
157  #define _SCL_SECURE_NO_DEPRECATE
158 #endif
159 
160 #define _CRT_NONSTDC_NO_WARNINGS
161 #define _CRT_NONSTDC_NO_DEPRECATE
162 #endif
163 
164 #ifdef RT_SOLARIS
165  #define INADDR_NONE 0xffffffff
166 #endif
167 
168 
169 #ifdef RT_WIN32
170  #if defined (_LIB) || (RT_OS_BUILD_LIB)
171  #define RT_API_EXPORT
172  #else
173  #if defined (_USRDLL) || (RT_OS_BUILD_DLL)||(_WINDLL)
174  #define RT_API_EXPORT __declspec(dllexport)
175  #else
176  #define RT_API_EXPORT __declspec(dllimport)
177  #endif // _USRDLL || RT_OS_BUILD_DLL
178  #endif // _LIB || RT_OS_BUILD_LIB
179 
180  #ifdef RT_API_EXPORT_NONEED // for not expect plugin exports api add by oz
181  #undef RT_API_EXPORT
182  #define RT_API_EXPORT
183  #endif
184 
185 #elif defined (RT_LINUX)
186  #define RT_API_EXPORT __attribute__((visibility("default")))
187 #else
188  #define RT_API_EXPORT
189 #endif // !RT_WIN32
190 
191 
192 #if defined (RT_WIN32)
193  #define RT_OS_SEPARATE '\\'
194 #elif defined (RT_UNIX) || defined(RT_MACOS) || defined(RT_IOS)
195  #define RT_OS_SEPARATE '/'
196 #endif
197 
198 #define RT_BIT_ENABLED(dword, bit) (((dword) & (bit)) != 0)
199 #define RT_BIT_DISABLED(dword, bit) (((dword) & (bit)) == 0)
200 #define RT_BIT_CMP_MASK(dword, bit, mask) (((dword) & (bit)) == mask)
201 #define RT_SET_BITS(dword, bits) (dword |= (bits))
202 #define RT_CLR_BITS(dword, bits) (dword &= ~(bits))
203 
205 // Assert
207 
208 #ifdef RT_WIN32
209  #include <crtdbg.h>
210  #ifdef _DEBUG
211  #define RT_DEBUG
212  #endif // _DEBUG
213 
214  #if defined (RT_DEBUG)
215  #define RT_ASSERTE _ASSERTE
216  #endif // RT_DEBUG
217 #endif // RT_WIN32
218 
219 #ifdef RT_UNIX
220  #include <assert.h>
221  #if defined (RT_DEBUG) && !defined (RT_DISABLE_ASSERTE)
222  #define RT_ASSERTE assert
223  #endif // RT_DEBUG
224 #endif // RT_UNIX
225 
226 
227 
228 #ifdef RT_DISABLE_ASSERTE
229 #include "debug.h"
230 #ifdef RT_ASSERTE
231 #undef RT_ASSERTE
232 #endif
233 #define RT_ASSERTE(expr) \
234  do { \
235  if (!(expr)) { \
236  LOG_ERROR(__FILE__ << ":" << __LINE__ << " Assert failed: " << #expr); \
237  } \
238  } while (0)
239 #endif // RT_DISABLE_ASSERTE
240 
241 #ifndef RT_ASSERTE
242 #define RT_ASSERTE(expr)
243 #endif // RT_ASSERTE
244 
245  //#define RT_ASSERTE_THROW RT_ASSERTE
246 
247 #ifdef RT_DISABLE_ASSERTE
248 #define RT_ASSERTE_RETURN(expr, rv) \
249  do { \
250  if (!(expr)) { \
251  LOG_ERROR(__FILE__ << ":" << __LINE__ << " Assert failed: " << #expr); \
252  return rv; \
253  } \
254  } while (0)
255 
256 #define RT_ASSERTE_RETURN_VOID(expr) \
257  do { \
258  if (!(expr)) { \
259  LOG_ERROR(__FILE__ << ":" << __LINE__ << " Assert failed: " << #expr); \
260  return; \
261  } \
262  } while (0)
263 #else
264 #define RT_ASSERTE_RETURN(expr, rv) \
265  do { \
266  RT_ASSERTE((expr)); \
267  if (!(expr)) { \
268  LOG_ERROR(__FILE__ << ":" << __LINE__ << " Assert failed: " << #expr); \
269  return rv; \
270  } \
271  } while (0)
272 
273 #define RT_ASSERTE_RETURN_VOID(expr) \
274  do { \
275  RT_ASSERTE((expr)); \
276  if (!(expr)) { \
277  LOG_ERROR(__FILE__ << ":" << __LINE__ << " Assert failed: " << #expr); \
278  return; \
279  } \
280  } while (0)
281 
282 #endif // RT_DISABLE_ASSERTE
283 
284 // mainly copied from ace/Basic_Types.h
285 // Byte-order (endian-ness) determination.
286 # if defined (BYTE_ORDER)
287 # if (BYTE_ORDER == LITTLE_ENDIAN)
288 # define RT_LITTLE_ENDIAN 0x0123
289 # define RT_BYTE_ORDER RT_LITTLE_ENDIAN
290 # elif (BYTE_ORDER == BIG_ENDIAN)
291 # define RT_BIG_ENDIAN 0x3210
292 # define RT_BYTE_ORDER RT_BIG_ENDIAN
293 # else
294 # error: unknown BYTE_ORDER!
295 # endif /* BYTE_ORDER */
296 # elif defined (_BYTE_ORDER)
297 # if (_BYTE_ORDER == _LITTLE_ENDIAN)
298 # define RT_LITTLE_ENDIAN 0x0123
299 # define RT_BYTE_ORDER RT_LITTLE_ENDIAN
300 # elif (_BYTE_ORDER == _BIG_ENDIAN)
301 # define RT_BIG_ENDIAN 0x3210
302 # define RT_BYTE_ORDER RT_BIG_ENDIAN
303 # else
304 # error: unknown _BYTE_ORDER!
305 # endif /* _BYTE_ORDER */
306 # elif defined (__BYTE_ORDER)
307 # if (__BYTE_ORDER == __LITTLE_ENDIAN)
308 # define RT_LITTLE_ENDIAN 0x0123
309 # define RT_BYTE_ORDER RT_LITTLE_ENDIAN
310 # elif (__BYTE_ORDER == __BIG_ENDIAN)
311 # define RT_BIG_ENDIAN 0x3210
312 # define RT_BYTE_ORDER RT_BIG_ENDIAN
313 # else
314 # error: unknown __BYTE_ORDER!
315 # endif /* __BYTE_ORDER */
316 # else /* ! BYTE_ORDER && ! __BYTE_ORDER */
317  // We weren't explicitly told, so we have to figure it out . . .
318 # if defined (i386) || defined (__i386__) || defined (_M_IX86) || \
319  defined (vax) || defined (__alpha) || defined (__LITTLE_ENDIAN__) ||\
320  defined (ARM) || defined (_M_IA64)
321  // We know these are little endian.
322 # define RT_LITTLE_ENDIAN 0x0123
323 # define RT_BYTE_ORDER RT_LITTLE_ENDIAN
324 # else
325  // Otherwise, we assume big endian.
326 # define RT_BIG_ENDIAN 0x3210
327 # define RT_BYTE_ORDER RT_BIG_ENDIAN
328 # endif
329 # endif /* ! BYTE_ORDER && ! __BYTE_ORDER */
330 
331 #ifdef RT_WIN32
332 # define RT_LL_PREFIX "I64"
333 #else
334 #if (defined(RT_LINUX) && !defined(RT_ANDROID)) // linux
335 # define RT_LL_PREFIX "l"
336 #else
337 # define RT_LL_PREFIX "ll"
338 #endif
339 #endif
340 
341 //#include <stddef.h> // for NULL, size_t
342 #if !(defined(_MSC_VER) && (_MSC_VER < 1600))
343 #include <stdint.h> // for uintptr_t
344 #endif
345 
346 #if !defined(INT_TYPES_DEFINED)
347 #define INT_TYPES_DEFINED
348 #ifdef COMPILER_MSVC
349 typedef unsigned __int64 uint64;
350 typedef __int64 int64;
351 #ifndef INT64_C
352 #define INT64_C(x) x ## I64
353 #endif
354 #ifndef UINT64_C
355 #define UINT64_C(x) x ## UI64
356 #endif
357 #define INT64_F "I64"
358 #else // COMPILER_MSVC
359 // On Mac OS X, cssmconfig.h defines uint64 as uint64_t
360 // TODO(fbarchard): Use long long for compatibility with chromium on BSD/OSX.
361 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
362 typedef uint64_t uint64;
363 typedef int64_t int64;
364 #ifndef INT64_C
365 #define INT64_C(x) x ## LL
366 #endif
367 #ifndef UINT64_C
368 #define UINT64_C(x) x ## ULL
369 #endif
370 #define INT64_F "l"
371 #elif defined(__LP64__)
372 typedef unsigned long uint64; // NOLINT
373 typedef long int64; // NOLINT
374 #ifndef INT64_C
375 #define INT64_C(x) x ## L
376 #endif
377 #ifndef UINT64_C
378 #define UINT64_C(x) x ## UL
379 #endif
380 #define INT64_F "l"
381 #else // __LP64__
382 typedef unsigned long long uint64; // NOLINT
383 typedef long long int64; // NOLINT
384 #ifndef INT64_C
385 #define INT64_C(x) x ## LL
386 #endif
387 #ifndef UINT64_C
388 #define UINT64_C(x) x ## ULL
389 #endif
390 #define INT64_F "ll"
391 #endif // __LP64__
392 #endif // COMPILER_MSVC
393 typedef unsigned int uint32;
394 typedef int int32;
395 typedef unsigned short uint16; // NOLINT
396 typedef short int16; // NOLINT
397 typedef unsigned char uint8;
398 typedef signed char int8;
399 #endif // INT_TYPES_DEFINED
400 
401 #ifdef RT_LINUX
402 #ifndef LONG_MAX // added for linux build
403 #define LONG_MAX (2147483647L)
404 #endif
405 #endif
406 
407 #endif // !RTCDEFINES_H
unsigned short uint16
Definition: defines.h:395
int int32
Definition: defines.h:394
unsigned int uint32
Definition: defines.h:393
long long int64
Definition: defines.h:383
unsigned long long uint64
Definition: defines.h:382
signed char int8
Definition: defines.h:398
unsigned char uint8
Definition: defines.h:397
short int16
Definition: defines.h:396