~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/pjlib/include/pj/types.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: types.h 4359 2013-02-21 11:18:36Z bennylp $ */
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 __PJ_TYPES_H__
21
 
#define __PJ_TYPES_H__
22
 
 
23
 
 
24
 
/**
25
 
 * @file types.h
26
 
 * @brief Declaration of basic types and utility.
27
 
 */
28
 
/**
29
 
 * @defgroup PJ_BASIC Basic Data Types and Library Functionality.
30
 
 * @ingroup PJ_DS
31
 
 * @{
32
 
 */
33
 
#include <pj/config.h>
34
 
 
35
 
PJ_BEGIN_DECL
36
 
 
37
 
/* ************************************************************************* */
38
 
 
39
 
/** Signed 32bit integer. */
40
 
typedef int             pj_int32_t;
41
 
 
42
 
/** Unsigned 32bit integer. */
43
 
typedef unsigned int    pj_uint32_t;
44
 
 
45
 
/** Signed 16bit integer. */
46
 
typedef short           pj_int16_t;
47
 
 
48
 
/** Unsigned 16bit integer. */
49
 
typedef unsigned short  pj_uint16_t;
50
 
 
51
 
/** Signed 8bit integer. */
52
 
typedef signed char     pj_int8_t;
53
 
 
54
 
/** Unsigned 8bit integer. */
55
 
typedef unsigned char   pj_uint8_t;
56
 
 
57
 
/** Large unsigned integer. */
58
 
typedef size_t          pj_size_t;
59
 
 
60
 
/** Large signed integer. */
61
 
typedef long            pj_ssize_t;
62
 
 
63
 
/** Status code. */
64
 
typedef int             pj_status_t;
65
 
 
66
 
/** Boolean. */
67
 
typedef int             pj_bool_t;
68
 
 
69
 
/** Native char type, which will be equal to wchar_t for Unicode
70
 
 * and char for ANSI. */
71
 
#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
72
 
    typedef wchar_t pj_char_t;
73
 
#else
74
 
    typedef char pj_char_t;
75
 
#endif
76
 
 
77
 
/** This macro creates Unicode or ANSI literal string depending whether
78
 
 *  native platform string is Unicode or ANSI. */
79
 
#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
80
 
#   define PJ_T(literal_str)    L##literal_str
81
 
#else
82
 
#   define PJ_T(literal_str)    literal_str
83
 
#endif
84
 
 
85
 
 
86
 
/** Status is OK. */
87
 
#define PJ_SUCCESS  0
88
 
 
89
 
/** True value. */
90
 
#define PJ_TRUE     1
91
 
 
92
 
/** False value. */
93
 
#define PJ_FALSE    0
94
 
 
95
 
/**
96
 
 * File offset type.
97
 
 */
98
 
#if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0
99
 
typedef pj_int64_t pj_off_t;
100
 
#else
101
 
typedef pj_ssize_t pj_off_t;
102
 
#endif
103
 
 
104
 
/* ************************************************************************* */
105
 
/*
106
 
 * Data structure types.
107
 
 */
108
 
/**
109
 
 * This type is used as replacement to legacy C string, and used throughout
110
 
 * the library. By convention, the string is NOT null terminated.
111
 
 */
112
 
struct pj_str_t
113
 
{
114
 
    /** Buffer pointer, which is by convention NOT null terminated. */
115
 
    char       *ptr;
116
 
 
117
 
    /** The length of the string. */
118
 
    pj_ssize_t  slen;
119
 
};
120
 
 
121
 
/**
122
 
 * This structure represents high resolution (64bit) time value. The time
123
 
 * values represent time in cycles, which is retrieved by calling
124
 
 * #pj_get_timestamp().
125
 
 */
126
 
typedef union pj_timestamp
127
 
{
128
 
    struct
129
 
    {
130
 
#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
131
 
        pj_uint32_t lo;     /**< Low 32-bit value of the 64-bit value. */
132
 
        pj_uint32_t hi;     /**< high 32-bit value of the 64-bit value. */
133
 
#else
134
 
        pj_uint32_t hi;     /**< high 32-bit value of the 64-bit value. */
135
 
        pj_uint32_t lo;     /**< Low 32-bit value of the 64-bit value. */
136
 
#endif
137
 
    } u32;                  /**< The 64-bit value as two 32-bit values. */
138
 
 
139
 
#if PJ_HAS_INT64
140
 
    pj_uint64_t u64;        /**< The whole 64-bit value, where available. */
141
 
#endif
142
 
} pj_timestamp;
143
 
 
144
 
 
145
 
 
146
 
/**
147
 
 * The opaque data type for linked list, which is used as arguments throughout
148
 
 * the linked list operations.
149
 
 */
150
 
typedef void pj_list_type;
151
 
 
152
 
/** 
153
 
 * List.
154
 
 */
155
 
typedef struct pj_list pj_list;
156
 
 
157
 
/**
158
 
 * Opaque data type for hash tables.
159
 
 */
160
 
typedef struct pj_hash_table_t pj_hash_table_t;
161
 
 
162
 
/**
163
 
 * Opaque data type for hash entry (only used internally by hash table).
164
 
 */
165
 
typedef struct pj_hash_entry pj_hash_entry;
166
 
 
167
 
/**
168
 
 * Data type for hash search iterator.
169
 
 * This structure should be opaque, however applications need to declare
170
 
 * concrete variable of this type, that's why the declaration is visible here.
171
 
 */
172
 
typedef struct pj_hash_iterator_t
173
 
{
174
 
    pj_uint32_t      index;     /**< Internal index.     */
175
 
    pj_hash_entry   *entry;     /**< Internal entry.     */
176
 
} pj_hash_iterator_t;
177
 
 
178
 
 
179
 
/**
180
 
 * Forward declaration for memory pool factory.
181
 
 */
182
 
typedef struct pj_pool_factory pj_pool_factory;
183
 
 
184
 
/**
185
 
 * Opaque data type for memory pool.
186
 
 */
187
 
typedef struct pj_pool_t pj_pool_t;
188
 
 
189
 
/**
190
 
 * Forward declaration for caching pool, a pool factory implementation.
191
 
 */
192
 
typedef struct pj_caching_pool pj_caching_pool;
193
 
 
194
 
/**
195
 
 * This type is used as replacement to legacy C string, and used throughout
196
 
 * the library.
197
 
 */
198
 
typedef struct pj_str_t pj_str_t;
199
 
 
200
 
/**
201
 
 * Opaque data type for I/O Queue structure.
202
 
 */
203
 
typedef struct pj_ioqueue_t pj_ioqueue_t;
204
 
 
205
 
/**
206
 
 * Opaque data type for key that identifies a handle registered to the
207
 
 * I/O queue framework.
208
 
 */
209
 
typedef struct pj_ioqueue_key_t pj_ioqueue_key_t;
210
 
 
211
 
/**
212
 
 * Opaque data to identify timer heap.
213
 
 */
214
 
typedef struct pj_timer_heap_t pj_timer_heap_t;
215
 
 
216
 
/** 
217
 
 * Opaque data type for atomic operations.
218
 
 */
219
 
typedef struct pj_atomic_t pj_atomic_t;
220
 
 
221
 
/**
222
 
 * Value type of an atomic variable.
223
 
 */
224
 
typedef PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t;
225
 
 
226
 
/* ************************************************************************* */
227
 
 
228
 
/** Thread handle. */
229
 
typedef struct pj_thread_t pj_thread_t;
230
 
 
231
 
/** Lock object. */
232
 
typedef struct pj_lock_t pj_lock_t;
233
 
 
234
 
/** Group lock */
235
 
typedef struct pj_grp_lock_t pj_grp_lock_t;
236
 
 
237
 
/** Mutex handle. */
238
 
typedef struct pj_mutex_t pj_mutex_t;
239
 
 
240
 
/** Semaphore handle. */
241
 
typedef struct pj_sem_t pj_sem_t;
242
 
 
243
 
/** Event object. */
244
 
typedef struct pj_event_t pj_event_t;
245
 
 
246
 
/** Unidirectional stream pipe object. */
247
 
typedef struct pj_pipe_t pj_pipe_t;
248
 
 
249
 
/** Operating system handle. */
250
 
typedef void *pj_oshandle_t;
251
 
 
252
 
/** Socket handle. */
253
 
typedef long pj_sock_t;
254
 
 
255
 
/** Generic socket address. */
256
 
typedef void pj_sockaddr_t;
257
 
 
258
 
/** Forward declaration. */
259
 
typedef struct pj_sockaddr_in pj_sockaddr_in;
260
 
 
261
 
/** Color type. */
262
 
typedef unsigned int pj_color_t;
263
 
 
264
 
/** Exception id. */
265
 
typedef int pj_exception_id_t;
266
 
 
267
 
/* ************************************************************************* */
268
 
 
269
 
/** Utility macro to compute the number of elements in static array. */
270
 
#define PJ_ARRAY_SIZE(a)    (sizeof(a)/sizeof(a[0]))
271
 
 
272
 
/** Maximum value for signed 32-bit integer. */
273
 
#define PJ_MAXINT32  0x7FFFFFFFL
274
 
 
275
 
/**
276
 
 * Length of object names.
277
 
 */
278
 
#define PJ_MAX_OBJ_NAME 32
279
 
 
280
 
/* ************************************************************************* */
281
 
/*
282
 
 * General.
283
 
 */
284
 
/**
285
 
 * Initialize the PJ Library.
286
 
 * This function must be called before using the library. The purpose of this
287
 
 * function is to initialize static library data, such as character table used
288
 
 * in random string generation, and to initialize operating system dependent
289
 
 * functionality (such as WSAStartup() in Windows).
290
 
 *
291
 
 * Apart from calling pj_init(), application typically should also initialize
292
 
 * the random seed by calling pj_srand().
293
 
 *
294
 
 * @return PJ_SUCCESS on success.
295
 
 */
296
 
PJ_DECL(pj_status_t) pj_init(void);
297
 
 
298
 
 
299
 
/**
300
 
 * Shutdown PJLIB.
301
 
 */
302
 
PJ_DECL(void) pj_shutdown(void);
303
 
 
304
 
/**
305
 
 * Type of callback to register to pj_atexit().
306
 
 */
307
 
typedef void (*pj_exit_callback)(void);
308
 
 
309
 
/**
310
 
 * Register cleanup function to be called by PJLIB when pj_shutdown() is 
311
 
 * called.
312
 
 *
313
 
 * @param func      The function to be registered.
314
 
 *
315
 
 * @return PJ_SUCCESS on success.
316
 
 */
317
 
PJ_DECL(pj_status_t) pj_atexit(pj_exit_callback func);
318
 
 
319
 
 
320
 
 
321
 
/**
322
 
 * Swap the byte order of an 16bit data.
323
 
 *
324
 
 * @param val16     The 16bit data.
325
 
 *
326
 
 * @return          An 16bit data with swapped byte order.
327
 
 */
328
 
PJ_INLINE(pj_int16_t) pj_swap16(pj_int16_t val16)
329
 
{
330
 
    pj_uint8_t *p = (pj_uint8_t*)&val16;
331
 
    pj_uint8_t tmp = *p;
332
 
    *p = *(p+1);
333
 
    *(p+1) = tmp;
334
 
    return val16;
335
 
}
336
 
 
337
 
/**
338
 
 * Swap the byte order of an 32bit data.
339
 
 *
340
 
 * @param val32     The 32bit data.
341
 
 *
342
 
 * @return          An 32bit data with swapped byte order.
343
 
 */
344
 
PJ_INLINE(pj_int32_t) pj_swap32(pj_int32_t val32)
345
 
{
346
 
    pj_uint8_t *p = (pj_uint8_t*)&val32;
347
 
    pj_uint8_t tmp = *p;
348
 
    *p = *(p+3);
349
 
    *(p+3) = tmp;
350
 
    tmp = *(p+1);
351
 
    *(p+1) = *(p+2);
352
 
    *(p+2) = tmp;
353
 
    return val32;
354
 
}
355
 
 
356
 
 
357
 
/**
358
 
 * @}
359
 
 */
360
 
/**
361
 
 * @addtogroup PJ_TIME Time Data Type and Manipulation.
362
 
 * @ingroup PJ_MISC
363
 
 * @{
364
 
 */
365
 
 
366
 
/**
367
 
 * Representation of time value in this library.
368
 
 * This type can be used to represent either an interval or a specific time
369
 
 * or date. 
370
 
 */
371
 
typedef struct pj_time_val
372
 
{
373
 
    /** The seconds part of the time. */
374
 
    long    sec;
375
 
 
376
 
    /** The miliseconds fraction of the time. */
377
 
    long    msec;
378
 
 
379
 
} pj_time_val;
380
 
 
381
 
/**
382
 
 * Normalize the value in time value.
383
 
 * @param t     Time value to be normalized.
384
 
 */
385
 
PJ_DECL(void) pj_time_val_normalize(pj_time_val *t);
386
 
 
387
 
/**
388
 
 * Get the total time value in miliseconds. This is the same as
389
 
 * multiplying the second part with 1000 and then add the miliseconds
390
 
 * part to the result.
391
 
 *
392
 
 * @param t     The time value.
393
 
 * @return      Total time in miliseconds.
394
 
 * @hideinitializer
395
 
 */
396
 
#define PJ_TIME_VAL_MSEC(t)     ((t).sec * 1000 + (t).msec)
397
 
 
398
 
/**
399
 
 * This macro will check if \a t1 is equal to \a t2.
400
 
 *
401
 
 * @param t1    The first time value to compare.
402
 
 * @param t2    The second time value to compare.
403
 
 * @return      Non-zero if both time values are equal.
404
 
 * @hideinitializer
405
 
 */
406
 
#define PJ_TIME_VAL_EQ(t1, t2)  ((t1).sec==(t2).sec && (t1).msec==(t2).msec)
407
 
 
408
 
/**
409
 
 * This macro will check if \a t1 is greater than \a t2
410
 
 *
411
 
 * @param t1    The first time value to compare.
412
 
 * @param t2    The second time value to compare.
413
 
 * @return      Non-zero if t1 is greater than t2.
414
 
 * @hideinitializer
415
 
 */
416
 
#define PJ_TIME_VAL_GT(t1, t2)  ((t1).sec>(t2).sec || \
417
 
                                ((t1).sec==(t2).sec && (t1).msec>(t2).msec))
418
 
 
419
 
/**
420
 
 * This macro will check if \a t1 is greater than or equal to \a t2
421
 
 *
422
 
 * @param t1    The first time value to compare.
423
 
 * @param t2    The second time value to compare.
424
 
 * @return      Non-zero if t1 is greater than or equal to t2.
425
 
 * @hideinitializer
426
 
 */
427
 
#define PJ_TIME_VAL_GTE(t1, t2) (PJ_TIME_VAL_GT(t1,t2) || \
428
 
                                 PJ_TIME_VAL_EQ(t1,t2))
429
 
 
430
 
/**
431
 
 * This macro will check if \a t1 is less than \a t2
432
 
 *
433
 
 * @param t1    The first time value to compare.
434
 
 * @param t2    The second time value to compare.
435
 
 * @return      Non-zero if t1 is less than t2.
436
 
 * @hideinitializer
437
 
 */
438
 
#define PJ_TIME_VAL_LT(t1, t2)  (!(PJ_TIME_VAL_GTE(t1,t2)))
439
 
 
440
 
/**
441
 
 * This macro will check if \a t1 is less than or equal to \a t2.
442
 
 *
443
 
 * @param t1    The first time value to compare.
444
 
 * @param t2    The second time value to compare.
445
 
 * @return      Non-zero if t1 is less than or equal to t2.
446
 
 * @hideinitializer
447
 
 */
448
 
#define PJ_TIME_VAL_LTE(t1, t2) (!PJ_TIME_VAL_GT(t1, t2))
449
 
 
450
 
/**
451
 
 * Add \a t2 to \a t1 and store the result in \a t1. Effectively
452
 
 *
453
 
 * this macro will expand as: (\a t1 += \a t2).
454
 
 * @param t1    The time value to add.
455
 
 * @param t2    The time value to be added to \a t1.
456
 
 * @hideinitializer
457
 
 */
458
 
#define PJ_TIME_VAL_ADD(t1, t2)     do {                            \
459
 
                                        (t1).sec += (t2).sec;       \
460
 
                                        (t1).msec += (t2).msec;     \
461
 
                                        pj_time_val_normalize(&(t1)); \
462
 
                                    } while (0)
463
 
 
464
 
 
465
 
/**
466
 
 * Substract \a t2 from \a t1 and store the result in \a t1. Effectively
467
 
 * this macro will expand as (\a t1 -= \a t2).
468
 
 *
469
 
 * @param t1    The time value to subsctract.
470
 
 * @param t2    The time value to be substracted from \a t1.
471
 
 * @hideinitializer
472
 
 */
473
 
#define PJ_TIME_VAL_SUB(t1, t2)     do {                            \
474
 
                                        (t1).sec -= (t2).sec;       \
475
 
                                        (t1).msec -= (t2).msec;     \
476
 
                                        pj_time_val_normalize(&(t1)); \
477
 
                                    } while (0)
478
 
 
479
 
 
480
 
/**
481
 
 * This structure represent the parsed representation of time.
482
 
 * It is acquired by calling #pj_time_decode().
483
 
 */
484
 
typedef struct pj_parsed_time
485
 
{
486
 
    /** This represents day of week where value zero means Sunday */
487
 
    int wday;
488
 
 
489
 
    /* This represents day of the year, 0-365, where zero means
490
 
     *  1st of January.
491
 
     */
492
 
    /*int yday; */
493
 
 
494
 
    /** This represents day of month: 1-31 */
495
 
    int day;
496
 
 
497
 
    /** This represents month, with the value is 0 - 11 (zero is January) */
498
 
    int mon;
499
 
 
500
 
    /** This represent the actual year (unlike in ANSI libc where
501
 
     *  the value must be added by 1900).
502
 
     */
503
 
    int year;
504
 
 
505
 
    /** This represents the second part, with the value is 0-59 */
506
 
    int sec;
507
 
 
508
 
    /** This represents the minute part, with the value is: 0-59 */
509
 
    int min;
510
 
 
511
 
    /** This represents the hour part, with the value is 0-23 */
512
 
    int hour;
513
 
 
514
 
    /** This represents the milisecond part, with the value is 0-999 */
515
 
    int msec;
516
 
 
517
 
} pj_parsed_time;
518
 
 
519
 
 
520
 
/**
521
 
 * @}   // Time Management
522
 
 */
523
 
 
524
 
/* ************************************************************************* */
525
 
/*
526
 
 * Terminal.
527
 
 */
528
 
/**
529
 
 * Color code combination.
530
 
 */
531
 
enum {
532
 
    PJ_TERM_COLOR_R     = 2,    /**< Red            */
533
 
    PJ_TERM_COLOR_G     = 4,    /**< Green          */
534
 
    PJ_TERM_COLOR_B     = 1,    /**< Blue.          */
535
 
    PJ_TERM_COLOR_BRIGHT = 8    /**< Bright mask.   */
536
 
};
537
 
 
538
 
 
539
 
 
540
 
 
541
 
PJ_END_DECL
542
 
 
543
 
 
544
 
#endif /* __PJ_TYPES_H__ */
545