BLOG | DOCUMENTATION | GITHUB

Home --> Documentations --> PJLIB Reference

types.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
3 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#ifndef __PJ_TYPES_H__
20#define __PJ_TYPES_H__
21
22
32#include <pj/config.h>
33#include <pj/limits.h>
34
36
37/* ************************************************************************* */
38
40typedef int pj_int32_t;
41
43typedef unsigned int pj_uint32_t;
44
46typedef short pj_int16_t;
47
49typedef unsigned short pj_uint16_t;
50
52typedef signed char pj_int8_t;
53
55typedef unsigned char pj_uint8_t;
56
58typedef size_t pj_size_t;
59
61#if defined(PJ_WIN64) && PJ_WIN64!=0
62 typedef pj_int64_t pj_ssize_t;
63#else
64 typedef long pj_ssize_t;
65#endif
66
68typedef int pj_status_t;
69
71typedef int pj_bool_t;
72
75#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
76 typedef wchar_t pj_char_t;
77#else
78 typedef char pj_char_t;
79#endif
80
83#if defined(PJ_NATIVE_STRING_IS_UNICODE) && PJ_NATIVE_STRING_IS_UNICODE!=0
84# define PJ_T(literal_str) L##literal_str
85#else
86# define PJ_T(literal_str) literal_str
87#endif
88
91{
94
97
99 PJ_FALSE=0
101
105#if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0
106typedef pj_int64_t pj_off_t;
107#else
109#endif
110
111/* ************************************************************************* */
112/*
113 * Data structure types.
114 */
120{
122 char *ptr;
123
126};
127
133typedef union pj_timestamp
134{
135 struct
136 {
137#if defined(PJ_IS_LITTLE_ENDIAN) && PJ_IS_LITTLE_ENDIAN!=0
140#else
143#endif
144 } u32;
146#if PJ_HAS_INT64
147 pj_uint64_t u64;
148#endif
150
151
152
157typedef void pj_list_type;
158
162typedef struct pj_list pj_list;
163
168
173
179typedef struct pj_hash_iterator_t
180{
184
185
189typedef struct pj_pool_factory pj_pool_factory;
190
194typedef struct pj_pool_t pj_pool_t;
195
199typedef struct pj_caching_pool pj_caching_pool;
200
205typedef struct pj_str_t pj_str_t;
206
211
217
222
227
231typedef PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t;
232
233/* ************************************************************************* */
234
237
239typedef struct pj_lock_t pj_lock_t;
240
243
245typedef struct pj_mutex_t pj_mutex_t;
246
248typedef struct pj_sem_t pj_sem_t;
249
251typedef struct pj_event_t pj_event_t;
252
254typedef struct pj_pipe_t pj_pipe_t;
255
257typedef void *pj_oshandle_t;
258
260#if defined(PJ_WIN64) && PJ_WIN64!=0
261 typedef pj_int64_t pj_sock_t;
262#else
263 typedef long pj_sock_t;
264#endif
265
267typedef void pj_sockaddr_t;
268
270typedef struct pj_sockaddr_in pj_sockaddr_in;
271
273typedef unsigned int pj_color_t;
274
277
278/* ************************************************************************* */
279
281#define PJ_ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
282
286#define PJ_MAX_OBJ_NAME 32
287
288/* ************************************************************************* */
289/*
290 * General.
291 */
304PJ_DECL(pj_status_t) pj_init(void);
305
306
310PJ_DECL(void) pj_shutdown(void);
311
315typedef void (*pj_exit_callback)(void);
316
326
327
328
337{
338 pj_uint8_t *p = (pj_uint8_t*)&val16;
339 pj_uint8_t tmp = *p;
340 *p = *(p+1);
341 *(p+1) = tmp;
342 return val16;
343}
344
353{
354 pj_uint8_t *p = (pj_uint8_t*)&val32;
355 pj_uint8_t tmp = *p;
356 *p = *(p+3);
357 *(p+3) = tmp;
358 tmp = *(p+1);
359 *(p+1) = *(p+2);
360 *(p+2) = tmp;
361 return val32;
362}
363
364
369#if (PJ_MAXLONG <= 2147483647L)
370# define PJ_CHECK_OVERFLOW_UINT32_TO_LONG(uint32_var, exec_on_overflow) \
371 do { \
372 if (uint32_var > PJ_MAXLONG) { \
373 exec_on_overflow; \
374 } \
375 } while (0)
376#else
377/* 'long' is longer than 32bit, uint32_var should never overflow */
378# define PJ_CHECK_OVERFLOW_UINT32_TO_LONG(uint32_var, exec_on_overflow)
379#endif
380
381
396typedef struct pj_time_val
397{
399 long sec;
400
402 long msec;
403
405
411
421#define PJ_TIME_VAL_MSEC(t) ((t).sec * 1000 + (t).msec)
422
431#define PJ_TIME_VAL_EQ(t1, t2) ((t1).sec==(t2).sec && (t1).msec==(t2).msec)
432
441#define PJ_TIME_VAL_GT(t1, t2) ((t1).sec>(t2).sec || \
442 ((t1).sec==(t2).sec && (t1).msec>(t2).msec))
443
452#define PJ_TIME_VAL_GTE(t1, t2) (PJ_TIME_VAL_GT(t1,t2) || \
453 PJ_TIME_VAL_EQ(t1,t2))
454
463#define PJ_TIME_VAL_LT(t1, t2) (!(PJ_TIME_VAL_GTE(t1,t2)))
464
473#define PJ_TIME_VAL_LTE(t1, t2) (!PJ_TIME_VAL_GT(t1, t2))
474
483#define PJ_TIME_VAL_ADD(t1, t2) do { \
484 (t1).sec += (t2).sec; \
485 (t1).msec += (t2).msec; \
486 pj_time_val_normalize(&(t1)); \
487 } while (0)
488
489
498#define PJ_TIME_VAL_SUB(t1, t2) do { \
499 (t1).sec -= (t2).sec; \
500 (t1).msec -= (t2).msec; \
501 pj_time_val_normalize(&(t1)); \
502 } while (0)
503
504
509typedef struct pj_parsed_time
510{
512 int wday;
513
514 /* This represents day of the year, 0-365, where zero means
515 * 1st of January.
516 */
517 /*int yday; */
518
520 int day;
521
523 int mon;
524
528 int year;
529
531 int sec;
532
534 int min;
535
537 int hour;
538
540 int msec;
541
543
544
549/* ************************************************************************* */
550/*
551 * Terminal.
552 */
556enum {
562
563
564
565
567
568
569#endif /* __PJ_TYPES_H__ */
570
PJLIB Main configuration settings.
unsigned char pj_uint8_t
Definition: types.h:55
pj_status_t pj_init(void)
long pj_ssize_t
Definition: types.h:64
short pj_int16_t
Definition: types.h:46
int pj_bool_t
Definition: types.h:71
struct pj_ioqueue_t pj_ioqueue_t
Definition: types.h:210
struct pj_mutex_t pj_mutex_t
Definition: types.h:245
struct pj_lock_t pj_lock_t
Definition: types.h:239
void * pj_oshandle_t
Definition: types.h:257
struct pj_sem_t pj_sem_t
Definition: types.h:248
unsigned short pj_uint16_t
Definition: types.h:49
pj_int32_t pj_swap32(pj_int32_t val32)
Definition: types.h:352
PJ_ATOMIC_VALUE_TYPE pj_atomic_value_t
Definition: types.h:231
void pj_list_type
Definition: types.h:157
long pj_sock_t
Definition: types.h:263
pj_constants_
Definition: types.h:91
struct pj_atomic_t pj_atomic_t
Definition: types.h:226
char pj_char_t
Definition: types.h:78
struct pj_ioqueue_key_t pj_ioqueue_key_t
Definition: types.h:216
pj_int16_t pj_swap16(pj_int16_t val16)
Definition: types.h:336
struct pj_hash_entry pj_hash_entry
Definition: types.h:172
size_t pj_size_t
Definition: types.h:58
struct pj_event_t pj_event_t
Definition: types.h:251
void pj_sockaddr_t
Definition: types.h:267
int pj_status_t
Definition: types.h:68
struct pj_pipe_t pj_pipe_t
Definition: types.h:254
struct pj_hash_table_t pj_hash_table_t
Definition: types.h:167
int pj_int32_t
Definition: types.h:40
void(* pj_exit_callback)(void)
Definition: types.h:315
struct pj_thread_t pj_thread_t
Definition: types.h:236
void pj_shutdown(void)
int pj_exception_id_t
Definition: types.h:276
struct pj_grp_lock_t pj_grp_lock_t
Definition: types.h:242
unsigned int pj_color_t
Definition: types.h:273
struct pj_timer_heap_t pj_timer_heap_t
Definition: types.h:221
pj_ssize_t pj_off_t
Definition: types.h:108
pj_status_t pj_atexit(pj_exit_callback func)
signed char pj_int8_t
Definition: types.h:52
unsigned int pj_uint32_t
Definition: types.h:43
@ PJ_SUCCESS
Definition: types.h:93
@ PJ_TRUE
Definition: types.h:96
@ PJ_FALSE
Definition: types.h:99
void pj_time_val_normalize(pj_time_val *t)
#define PJ_BEGIN_DECL
Definition: config.h:1284
#define PJ_INLINE(type)
Definition: config.h:1178
#define PJ_END_DECL
Definition: config.h:1285
Common min and max values.
Definition: pool.h:824
Definition: types.h:180
pj_uint32_t index
Definition: types.h:181
pj_hash_entry * entry
Definition: types.h:182
Definition: list.h:74
Definition: types.h:510
int sec
Definition: types.h:531
int hour
Definition: types.h:537
int year
Definition: types.h:528
int msec
Definition: types.h:540
int min
Definition: types.h:534
int wday
Definition: types.h:512
int day
Definition: types.h:520
int mon
Definition: types.h:523
Definition: pool.h:667
Definition: pool.h:310
Definition: sock.h:534
Definition: types.h:120
pj_ssize_t slen
Definition: types.h:125
char * ptr
Definition: types.h:122
Definition: types.h:397
long msec
Definition: types.h:402
long sec
Definition: types.h:399
@ PJ_TERM_COLOR_BRIGHT
Definition: types.h:560
@ PJ_TERM_COLOR_G
Definition: types.h:558
@ PJ_TERM_COLOR_B
Definition: types.h:559
@ PJ_TERM_COLOR_R
Definition: types.h:557
Definition: types.h:134
pj_uint32_t lo
Definition: types.h:142
pj_uint32_t hi
Definition: types.h:141
struct pj_timestamp::@9 u32

 


PJLIB Open Source, high performance, small footprint, and very very portable framework
Copyright (C) 2006-2009 Teluu Inc.