blob: 251f7f7b60696268807ac79b226da3d747af067f [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 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_CONFIG_H__
20#define __PJ_CONFIG_H__
21
22/**
23 * @file config.h
24 * @brief PJLIB Main configuration settings.
25 */
26
27/********************************************************************
28 * Include compiler specific configuration.
29 */
30#if defined(_MSC_VER)
31# include <pj/compat/cc_msvc.h>
32#elif defined(__GNUC__)
33# include <pj/compat/cc_gcc.h>
34#else
35# error "Unknown compiler."
36#endif
37
38
39/********************************************************************
40 * Include target OS specific configuration.
41 */
42#if defined(PJ_WIN32) && PJ_WIN32!=0
43# include <pj/compat/os_win32.h>
Benny Prijono9cf138e2006-01-19 03:58:29 +000044#elif defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
45# include <pj/compat/os_win32_wince.h>
Benny Prijono9033e312005-11-21 02:08:39 +000046#elif defined(PJ_LINUX) && PJ_LINUX!=0
47# include <pj/compat/os_linux.h>
48#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL!=0
49# include <pj/compat/os_linux_kernel.h>
50#elif defined(PJ_PALMOS) && PJ_PALMOS!=0
51# include <pj/compat/os_palmos.h>
52#elif defined(PJ_SUNOS) && PJ_SUNOS!=0
53# include <pj/compat/os_sunos.h>
Benny Prijonoe67d99a2006-03-20 12:39:24 +000054#elif defined(PJ_DARWINOS) && PJ_DARWINOS!=0
55# include <pj/compat/os_darwinos.h>
Benny Prijono42c5b9e2006-05-10 19:24:40 +000056#elif defined(PJ_RTEMS) && PJ_RTEMS!=0
57# include <pj/compat/os_rtems.h>
Benny Prijono9033e312005-11-21 02:08:39 +000058#else
59# error "Please specify target os."
60#endif
61
62
63/********************************************************************
64 * Target machine specific configuration.
65 */
66#if defined (PJ_M_I386) && PJ_M_I386 != 0
67# include <pj/compat/m_i386.h>
Benny Prijono7db431e2006-07-23 14:38:49 +000068#elif defined (PJ_M_X86_64) && PJ_M_X86_64 != 0
69# include <pj/compat/m_x86_64.h>
Benny Prijono9033e312005-11-21 02:08:39 +000070#elif defined (PJ_M_M68K) && PJ_M_M68K != 0
71# include <pj/compat/m_m68k.h>
72#elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0
73# include <pj/compat/m_alpha.h>
74#elif defined (PJ_M_SPARC) && PJ_M_SPARC != 0
75# include <pj/compat/m_sparc.h>
Benny Prijono9cf138e2006-01-19 03:58:29 +000076#elif defined (PJ_M_ARMV4) && PJ_M_ARMV4 != 0
Benny Prijonoace00932006-02-14 21:04:47 +000077# include <pj/compat/m_armv4.h>
Benny Prijonoe67d99a2006-03-20 12:39:24 +000078#elif defined (PJ_M_POWERPC) && PJ_M_POWERPC != 0
79# include <pj/compat/m_powerpc.h>
Benny Prijono9033e312005-11-21 02:08:39 +000080#else
81# error "Please specify target machine."
82#endif
83
84/* Include size_t definition. */
85#include <pj/compat/size_t.h>
86
87/* Include site/user specific configuration to control PJLIB features.
88 * YOU MUST CREATE THIS FILE YOURSELF!!
89 */
90#include <pj/config_site.h>
91
92/********************************************************************
93 * PJLIB Features.
94 */
95
96/* Overrides for DOXYGEN */
97#ifdef DOXYGEN
98# undef PJ_FUNCTIONS_ARE_INLINED
99# undef PJ_HAS_FLOATING_POINT
100# undef PJ_LOG_MAX_LEVEL
101# undef PJ_LOG_MAX_SIZE
102# undef PJ_LOG_USE_STACK_BUFFER
103# undef PJ_TERM_HAS_COLOR
104# undef PJ_POOL_DEBUG
105# undef PJ_HAS_TCP
106# undef PJ_MAX_HOSTNAME
107# undef PJ_IOQUEUE_MAX_HANDLES
108# undef FD_SETSIZE
109# undef PJ_HAS_SEMAPHORE
110# undef PJ_HAS_EVENT_OBJ
111# undef PJ_ENABLE_EXTRA_CHECK
Benny Prijono99683ae2005-11-21 16:59:47 +0000112# undef PJ_EXCEPTION_USE_WIN32_SEH
Benny Prijono11852992006-03-18 12:28:03 +0000113# undef PJ_HAS_ERROR_STRING
Benny Prijono9033e312005-11-21 02:08:39 +0000114#endif
115
116/**
117 * @defgroup pj_config Build Configuration
118 * @ingroup PJ
119 * @{
120 *
121 * This section contains macros that can set during PJLIB build process
122 * to controll various aspects of the library.
123 *
124 * <b>Note</b>: the values in this page does NOT necessarily reflect to the
125 * macro values during the build process.
126 */
127
128/**
129 * If this macro is set to 1, it will enable some debugging checking
130 * in the library.
131 *
132 * Default: equal to (NOT NDEBUG).
133 */
134#ifndef PJ_DEBUG
135# ifndef NDEBUG
136# define PJ_DEBUG 1
137# else
138# define PJ_DEBUG 0
139# endif
140#endif
141
142/**
143 * Expand functions in *_i.h header files as inline.
144 *
145 * Default: 0.
146 */
147#ifndef PJ_FUNCTIONS_ARE_INLINED
148# define PJ_FUNCTIONS_ARE_INLINED 0
149#endif
150
151/**
152 * Use floating point computations in the library.
153 *
154 * Default: 1.
155 */
156#ifndef PJ_HAS_FLOATING_POINT
157# define PJ_HAS_FLOATING_POINT 1
158#endif
159
160/**
161 * Declare maximum logging level/verbosity. Lower number indicates higher
162 * importance, with the highest importance has level zero. The least
163 * important level is five in this implementation, but this can be extended
164 * by supplying the appropriate implementation.
165 *
166 * The level conventions:
167 * - 0: fatal error
168 * - 1: error
169 * - 2: warning
170 * - 3: info
171 * - 4: debug
172 * - 5: trace
173 * - 6: more detailed trace
174 *
175 * Default: 4
176 */
177#ifndef PJ_LOG_MAX_LEVEL
178# define PJ_LOG_MAX_LEVEL 5
179#endif
180
181/**
182 * Maximum message size that can be sent to output device for each call
183 * to PJ_LOG(). If the message size is longer than this value, it will be cut.
184 * This may affect the stack usage, depending whether PJ_LOG_USE_STACK_BUFFER
185 * flag is set.
186 *
Benny Prijonoccf95622006-02-07 18:48:01 +0000187 * Default: 1500
Benny Prijono9033e312005-11-21 02:08:39 +0000188 */
189#ifndef PJ_LOG_MAX_SIZE
Benny Prijonoccf95622006-02-07 18:48:01 +0000190# define PJ_LOG_MAX_SIZE 1500
Benny Prijono9033e312005-11-21 02:08:39 +0000191#endif
192
193/**
194 * Log buffer.
195 * Does the log get the buffer from the stack? (default is yes).
196 * If the value is set to NO, then the buffer will be taken from static
197 * buffer, which in this case will make the log function non-reentrant.
198 *
199 * Default: 1
200 */
201#ifndef PJ_LOG_USE_STACK_BUFFER
202# define PJ_LOG_USE_STACK_BUFFER 1
203#endif
204
205
206/**
207 * Colorfull terminal (for logging etc).
208 *
209 * Default: 1
210 */
211#ifndef PJ_TERM_HAS_COLOR
212# define PJ_TERM_HAS_COLOR 1
213#endif
214
Benny Prijono8508aa02006-03-30 15:56:01 +0000215
Benny Prijono9033e312005-11-21 02:08:39 +0000216/**
Benny Prijono8508aa02006-03-30 15:56:01 +0000217 * If pool debugging is used, then each memory allocation from the pool
218 * will call malloc(), and pool will release all memory chunks when it
219 * is destroyed. This works better when memory verification programs
220 * such as Rational Purify is used.
Benny Prijono9033e312005-11-21 02:08:39 +0000221 *
222 * Default: 0
223 */
224#ifndef PJ_POOL_DEBUG
225# define PJ_POOL_DEBUG 0
226#endif
227
Benny Prijono8508aa02006-03-30 15:56:01 +0000228
229/**
Benny Prijono42c5b9e2006-05-10 19:24:40 +0000230 * Specify this as \a stack_size argument in #pj_thread_create() to specify
231 * that thread should use default stack size for the current platform.
232 *
233 * Default: 8192
234 */
235#ifndef PJ_THREAD_DEFAULT_STACK_SIZE
236# define PJ_THREAD_DEFAULT_STACK_SIZE 8192
237#endif
238
239
240/**
Benny Prijono8508aa02006-03-30 15:56:01 +0000241 * Do we have alternate pool implementation?
242 *
243 * Default: 0
244 */
245#ifndef PJ_HAS_POOL_ALT_API
246# define PJ_HAS_POOL_ALT_API PJ_POOL_DEBUG
247#endif
248
249
Benny Prijono9033e312005-11-21 02:08:39 +0000250/**
251 * \def PJ_HAS_TCP
252 * Support TCP in the library.
253 * Disabling TCP will reduce the footprint slightly (about 6KB).
254 *
255 * Default: 1
256 */
257#ifndef PJ_HAS_TCP
258# define PJ_HAS_TCP 1
259#endif
260
261/**
262 * Maximum hostname length.
263 * Libraries sometimes needs to make copy of an address to stack buffer;
264 * the value here affects the stack usage.
265 *
266 * Default: 128
267 */
268#ifndef PJ_MAX_HOSTNAME
269# define PJ_MAX_HOSTNAME (128)
270#endif
271
272/**
273 * Constants for declaring the maximum handles that can be supported by
274 * a single IOQ framework. This constant might not be relevant to the
275 * underlying I/O queue impelementation, but still, developers should be
276 * aware of this constant, to make sure that the program will not break when
277 * the underlying implementation changes.
278 *
279 * For implementation based on select(), the value here will be used as the
280 * maximum number of socket handles passed to select() (i.e. FD_SETSIZE will
281 * be set to this value).
282 *
Benny Prijonoe67d99a2006-03-20 12:39:24 +0000283 * Default: if FD_SETSIZE is defined and the value is greather than 256,
284 * then it will be used. Otherwise 256 (64 for WinCE).
Benny Prijono9033e312005-11-21 02:08:39 +0000285 */
286#ifndef PJ_IOQUEUE_MAX_HANDLES
Benny Prijono11852992006-03-18 12:28:03 +0000287# if defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
288# define PJ_IOQUEUE_MAX_HANDLES (64)
289# else
290# define PJ_IOQUEUE_MAX_HANDLES (256)
291# endif
Benny Prijono9033e312005-11-21 02:08:39 +0000292#endif
293
Benny Prijono8508aa02006-03-30 15:56:01 +0000294
295/**
296 * If PJ_IOQUEUE_HAS_SAFE_UNREG macro is defined, then ioqueue will do more
297 * things to ensure thread safety of handle unregistration operation by
298 * employing reference counter to each handle.
299 *
300 * In addition, the ioqueue will preallocate memory for the handles,
301 * according to the maximum number of handles that is specified during
302 * ioqueue creation.
303 *
304 * All applications would normally want this enabled, but you may disable
305 * this if:
306 * - there is no dynamic unregistration to all ioqueues.
307 * - there is no threading, or there is no preemptive multitasking.
308 *
309 * Default: 1
310 */
311#ifndef PJ_IOQUEUE_HAS_SAFE_UNREG
312# define PJ_IOQUEUE_HAS_SAFE_UNREG 1
313#endif
314
315
316/**
317 * When safe unregistration (PJ_IOQUEUE_HAS_SAFE_UNREG) is configured in
318 * ioqueue, the PJ_IOQUEUE_KEY_FREE_DELAY macro specifies how long the
319 * ioqueue key is kept in closing state before it can be reused.
320 *
321 * The value is in miliseconds.
322 *
323 * Default: 500 msec.
324 */
325#ifndef PJ_IOQUEUE_KEY_FREE_DELAY
326# define PJ_IOQUEUE_KEY_FREE_DELAY 500
327#endif
328
329
Benny Prijono9033e312005-11-21 02:08:39 +0000330/**
331 * Overrides FD_SETSIZE so it is consistent throughout the library.
332 * OS specific configuration header (compat/os_*) might have declared
333 * FD_SETSIZE, thus we only set if it hasn't been declared.
334 *
335 * Default: #PJ_IOQUEUE_MAX_HANDLES
336 */
337#ifndef FD_SETSIZE
338# define FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES
339#endif
340
341/**
342 * Has semaphore functionality?
343 *
344 * Default: 1
345 */
346#ifndef PJ_HAS_SEMAPHORE
347# define PJ_HAS_SEMAPHORE 1
348#endif
349
350
351/**
352 * Event object (for synchronization, e.g. in Win32)
353 *
354 * Default: 1
355 */
356#ifndef PJ_HAS_EVENT_OBJ
357# define PJ_HAS_EVENT_OBJ 1
358#endif
359
360
361/**
362 * Enable library's extra check.
363 * If this macro is enabled, #PJ_ASSERT_RETURN macro will expand to
364 * run-time checking. If this macro is disabled, #PJ_ASSERT_RETURN
365 * will simply evaluate to #pj_assert().
366 *
367 * You can disable this macro to reduce size, at the risk of crashes
368 * if invalid value (e.g. NULL) is passed to the library.
369 *
370 * Default: 1
371 */
372#ifndef PJ_ENABLE_EXTRA_CHECK
373# define PJ_ENABLE_EXTRA_CHECK 1
374#endif
375
376
377/**
378 * Enable name registration for exceptions with #pj_exception_id_alloc().
379 * If this feature is enabled, then the library will keep track of
380 * names associated with each exception ID requested by application via
381 * #pj_exception_id_alloc().
382 *
383 * Disabling this macro will reduce the code and .bss size by a tad bit.
384 * See also #PJ_MAX_EXCEPTION_ID.
385 *
386 * Default: 1
387 */
388#ifndef PJ_HAS_EXCEPTION_NAMES
389# define PJ_HAS_EXCEPTION_NAMES 1
390#endif
391
392/**
393 * Maximum number of unique exception IDs that can be requested
394 * with #pj_exception_id_alloc(). For each entry, a small record will
395 * be allocated in the .bss segment.
396 *
397 * Default: 16
398 */
399#ifndef PJ_MAX_EXCEPTION_ID
400# define PJ_MAX_EXCEPTION_ID 16
401#endif
402
Benny Prijono99683ae2005-11-21 16:59:47 +0000403/**
404 * Should we use Windows Structured Exception Handling (SEH) for the
405 * PJLIB exceptions.
406 *
407 * Default: 0
408 */
409#ifndef PJ_EXCEPTION_USE_WIN32_SEH
410# define PJ_EXCEPTION_USE_WIN32_SEH 0
411#endif
412
413/**
414 * Should we attempt to use Pentium's rdtsc for high resolution
415 * timestamp.
416 *
417 * Default: 0
418 */
419#ifndef PJ_TIMESTAMP_USE_RDTSC
420# define PJ_TIMESTAMP_USE_RDTSC 0
421#endif
422
Benny Prijono11852992006-03-18 12:28:03 +0000423/**
424 * Include error message string in the library (pj_strerror()).
425 * This is very much desirable!
426 *
427 * Default: 1
428 */
429#ifndef PJ_HAS_ERROR_STRING
430# define PJ_HAS_ERROR_STRING 1
431#endif
432
Benny Prijono99683ae2005-11-21 16:59:47 +0000433
Benny Prijonodcf29962006-03-23 18:03:40 +0000434/**
435 * Include pj_stricmp_alnum() and pj_strnicmp_alnum(), i.e. custom
436 * functions to compare alnum strings. On some systems, they're faster
437 * then stricmp/strcasecmp, but they can be slower on other systems.
438 * When disabled, pjlib will fallback to stricmp/strnicmp.
439 *
440 * Default: 0
441 */
442#ifndef PJ_HAS_STRICMP_ALNUM
443# define PJ_HAS_STRICMP_ALNUM 0
444#endif
445
446
Benny Prijono9033e312005-11-21 02:08:39 +0000447/** @} */
448
449/********************************************************************
450 * General macros.
451 */
452
453/**
454 * @def PJ_INLINE(type)
455 * @param type The return type of the function.
456 * Expand the function as inline.
457 */
458#define PJ_INLINE(type) PJ_INLINE_SPECIFIER type
459
460/**
461 * @def PJ_DECL(type)
462 * @param type The return type of the function.
463 * Declare a function.
464 */
465/**
466 * @def PJ_DECL_NO_RETURN(type)
467 * @param type The return type of the function.
468 * Declare a function that will not return.
469 */
470/**
471 * @def PJ_BEGIN_DECL
472 * Mark beginning of declaration section in a header file.
473 */
474/**
475 * @def PJ_END_DECL
476 * Mark end of declaration section in a header file.
477 */
478#ifdef __cplusplus
479# define PJ_DECL(type) type
480# define PJ_DECL_NO_RETURN(type) type PJ_NORETURN
Benny Prijono99683ae2005-11-21 16:59:47 +0000481# define PJ_IDECL_NO_RETURN(type) PJ_INLINE(type) PJ_NORETURN
Benny Prijono9033e312005-11-21 02:08:39 +0000482# define PJ_BEGIN_DECL extern "C" {
483# define PJ_END_DECL }
484#else
485# define PJ_DECL(type) extern type
486# define PJ_DECL_NO_RETURN(type) PJ_NORETURN type
Benny Prijono99683ae2005-11-21 16:59:47 +0000487# define PJ_IDECL_NO_RETURN(type) PJ_NORETURN PJ_INLINE(type)
Benny Prijono9033e312005-11-21 02:08:39 +0000488# define PJ_BEGIN_DECL
489# define PJ_END_DECL
490#endif
491
492/**
493 * @def PJ_DEF(type)
494 * @param type The return type of the function.
495 * Define a function.
496 */
497#define PJ_DEF(type) type
498
499/**
500 * @def PJ_EXPORT_SYMBOL(sym)
501 * @param sym The symbol to export.
502 * Export the specified symbol in compilation type that requires export
503 * (e.g. Linux kernel).
504 */
505#ifdef __PJ_EXPORT_SYMBOL
506# define PJ_EXPORT_SYMBOL(sym) __PJ_EXPORT_SYMBOL(sym)
507#else
508# define PJ_EXPORT_SYMBOL(sym)
509#endif
510
511/**
512 * @def PJ_IDECL(type)
513 * @param type The function's return type.
514 * Declare a function that may be expanded as inline.
515 */
516/**
517 * @def PJ_IDEF(type)
518 * @param type The function's return type.
519 * Define a function that may be expanded as inline.
520 */
521
522#if PJ_FUNCTIONS_ARE_INLINED
523# define PJ_IDECL(type) PJ_INLINE(type)
524# define PJ_IDEF(type) PJ_INLINE(type)
525#else
526# define PJ_IDECL(type) PJ_DECL(type)
527# define PJ_IDEF(type) PJ_DEF(type)
528#endif
529
530/**
531 * @def PJ_UNUSED_ARG(arg)
532 * @param arg The argument name.
533 * PJ_UNUSED_ARG prevents warning about unused argument in a function.
534 */
535#define PJ_UNUSED_ARG(arg) (void)arg
536
537/**
538 * @def PJ_TODO(id)
539 * @param id Any identifier that will be printed as TODO message.
540 * PJ_TODO macro will display TODO message as warning during compilation.
541 * Example: PJ_TODO(CLEAN_UP_ERROR);
542 */
543#ifndef PJ_TODO
544# define PJ_TODO(id) TODO___##id:
545#endif
546
547/**
548 * Function attributes to inform that the function may throw exception.
549 *
550 * @param x The exception list, enclosed in parenthesis.
551 */
552#define __pj_throw__(x)
553
554
555/********************************************************************
556 * Sanity Checks
557 */
558#ifndef PJ_HAS_HIGH_RES_TIMER
559# error "PJ_HAS_HIGH_RES_TIMER is not defined!"
560#endif
561
562#if !defined(PJ_HAS_PENTIUM)
563# error "PJ_HAS_PENTIUM is not defined!"
564#endif
565
566#if !defined(PJ_IS_LITTLE_ENDIAN)
567# error "PJ_IS_LITTLE_ENDIAN is not defined!"
568#endif
569
570#if !defined(PJ_IS_BIG_ENDIAN)
571# error "PJ_IS_BIG_ENDIAN is not defined!"
572#endif
573
Benny Prijono42c5b9e2006-05-10 19:24:40 +0000574#if !defined(PJ_EMULATE_RWMUTEX)
575# error "PJ_EMULATE_RWMUTEX should be defined in compat/os_xx.h"
576#endif
Benny Prijono9033e312005-11-21 02:08:39 +0000577
Benny Prijono42c5b9e2006-05-10 19:24:40 +0000578#if !defined(PJ_THREAD_SET_STACK_SIZE)
579# error "PJ_THREAD_SET_STACK_SIZE should be defined in compat/os_xx.h"
580#endif
581
582#if !defined(PJ_THREAD_ALLOCATE_STACK)
583# error "PJ_THREAD_ALLOCATE_STACK should be defined in compat/os_xx.h"
584#endif
Benny Prijono9033e312005-11-21 02:08:39 +0000585
586PJ_BEGIN_DECL
587
588/**
589 * PJLIB version string.
590 */
591extern const char *PJ_VERSION;
592
593/**
594 * Dump configuration to log with verbosity equal to info(3).
595 */
596PJ_DECL(void) pj_dump_config(void);
597
598PJ_END_DECL
599
600
601#endif /* __PJ_CONFIG_H__ */
602