Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 1 | /* $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 Prijono | 9cf138e | 2006-01-19 03:58:29 +0000 | [diff] [blame] | 44 | #elif defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0 |
| 45 | # include <pj/compat/os_win32_wince.h> |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 46 | #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> |
| 54 | #else |
| 55 | # error "Please specify target os." |
| 56 | #endif |
| 57 | |
| 58 | |
| 59 | /******************************************************************** |
| 60 | * Target machine specific configuration. |
| 61 | */ |
| 62 | #if defined (PJ_M_I386) && PJ_M_I386 != 0 |
| 63 | # include <pj/compat/m_i386.h> |
| 64 | #elif defined (PJ_M_M68K) && PJ_M_M68K != 0 |
| 65 | # include <pj/compat/m_m68k.h> |
| 66 | #elif defined (PJ_M_ALPHA) && PJ_M_ALPHA != 0 |
| 67 | # include <pj/compat/m_alpha.h> |
| 68 | #elif defined (PJ_M_SPARC) && PJ_M_SPARC != 0 |
| 69 | # include <pj/compat/m_sparc.h> |
Benny Prijono | 9cf138e | 2006-01-19 03:58:29 +0000 | [diff] [blame] | 70 | #elif defined (PJ_M_ARMV4) && PJ_M_ARMV4 != 0 |
| 71 | # include <pj/compat/m_arm.h> |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 72 | #else |
| 73 | # error "Please specify target machine." |
| 74 | #endif |
| 75 | |
| 76 | /* Include size_t definition. */ |
| 77 | #include <pj/compat/size_t.h> |
| 78 | |
| 79 | /* Include site/user specific configuration to control PJLIB features. |
| 80 | * YOU MUST CREATE THIS FILE YOURSELF!! |
| 81 | */ |
| 82 | #include <pj/config_site.h> |
| 83 | |
| 84 | /******************************************************************** |
| 85 | * PJLIB Features. |
| 86 | */ |
| 87 | |
| 88 | /* Overrides for DOXYGEN */ |
| 89 | #ifdef DOXYGEN |
| 90 | # undef PJ_FUNCTIONS_ARE_INLINED |
| 91 | # undef PJ_HAS_FLOATING_POINT |
| 92 | # undef PJ_LOG_MAX_LEVEL |
| 93 | # undef PJ_LOG_MAX_SIZE |
| 94 | # undef PJ_LOG_USE_STACK_BUFFER |
| 95 | # undef PJ_TERM_HAS_COLOR |
| 96 | # undef PJ_POOL_DEBUG |
| 97 | # undef PJ_HAS_TCP |
| 98 | # undef PJ_MAX_HOSTNAME |
| 99 | # undef PJ_IOQUEUE_MAX_HANDLES |
| 100 | # undef FD_SETSIZE |
| 101 | # undef PJ_HAS_SEMAPHORE |
| 102 | # undef PJ_HAS_EVENT_OBJ |
| 103 | # undef PJ_ENABLE_EXTRA_CHECK |
Benny Prijono | 99683ae | 2005-11-21 16:59:47 +0000 | [diff] [blame] | 104 | # undef PJ_EXCEPTION_USE_WIN32_SEH |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | /** |
| 108 | * @defgroup pj_config Build Configuration |
| 109 | * @ingroup PJ |
| 110 | * @{ |
| 111 | * |
| 112 | * This section contains macros that can set during PJLIB build process |
| 113 | * to controll various aspects of the library. |
| 114 | * |
| 115 | * <b>Note</b>: the values in this page does NOT necessarily reflect to the |
| 116 | * macro values during the build process. |
| 117 | */ |
| 118 | |
| 119 | /** |
| 120 | * If this macro is set to 1, it will enable some debugging checking |
| 121 | * in the library. |
| 122 | * |
| 123 | * Default: equal to (NOT NDEBUG). |
| 124 | */ |
| 125 | #ifndef PJ_DEBUG |
| 126 | # ifndef NDEBUG |
| 127 | # define PJ_DEBUG 1 |
| 128 | # else |
| 129 | # define PJ_DEBUG 0 |
| 130 | # endif |
| 131 | #endif |
| 132 | |
| 133 | /** |
| 134 | * Expand functions in *_i.h header files as inline. |
| 135 | * |
| 136 | * Default: 0. |
| 137 | */ |
| 138 | #ifndef PJ_FUNCTIONS_ARE_INLINED |
| 139 | # define PJ_FUNCTIONS_ARE_INLINED 0 |
| 140 | #endif |
| 141 | |
| 142 | /** |
| 143 | * Use floating point computations in the library. |
| 144 | * |
| 145 | * Default: 1. |
| 146 | */ |
| 147 | #ifndef PJ_HAS_FLOATING_POINT |
| 148 | # define PJ_HAS_FLOATING_POINT 1 |
| 149 | #endif |
| 150 | |
| 151 | /** |
| 152 | * Declare maximum logging level/verbosity. Lower number indicates higher |
| 153 | * importance, with the highest importance has level zero. The least |
| 154 | * important level is five in this implementation, but this can be extended |
| 155 | * by supplying the appropriate implementation. |
| 156 | * |
| 157 | * The level conventions: |
| 158 | * - 0: fatal error |
| 159 | * - 1: error |
| 160 | * - 2: warning |
| 161 | * - 3: info |
| 162 | * - 4: debug |
| 163 | * - 5: trace |
| 164 | * - 6: more detailed trace |
| 165 | * |
| 166 | * Default: 4 |
| 167 | */ |
| 168 | #ifndef PJ_LOG_MAX_LEVEL |
| 169 | # define PJ_LOG_MAX_LEVEL 5 |
| 170 | #endif |
| 171 | |
| 172 | /** |
| 173 | * Maximum message size that can be sent to output device for each call |
| 174 | * to PJ_LOG(). If the message size is longer than this value, it will be cut. |
| 175 | * This may affect the stack usage, depending whether PJ_LOG_USE_STACK_BUFFER |
| 176 | * flag is set. |
| 177 | * |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame^] | 178 | * Default: 1500 |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 179 | */ |
| 180 | #ifndef PJ_LOG_MAX_SIZE |
Benny Prijono | ccf9562 | 2006-02-07 18:48:01 +0000 | [diff] [blame^] | 181 | # define PJ_LOG_MAX_SIZE 1500 |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 182 | #endif |
| 183 | |
| 184 | /** |
| 185 | * Log buffer. |
| 186 | * Does the log get the buffer from the stack? (default is yes). |
| 187 | * If the value is set to NO, then the buffer will be taken from static |
| 188 | * buffer, which in this case will make the log function non-reentrant. |
| 189 | * |
| 190 | * Default: 1 |
| 191 | */ |
| 192 | #ifndef PJ_LOG_USE_STACK_BUFFER |
| 193 | # define PJ_LOG_USE_STACK_BUFFER 1 |
| 194 | #endif |
| 195 | |
| 196 | |
| 197 | /** |
| 198 | * Colorfull terminal (for logging etc). |
| 199 | * |
| 200 | * Default: 1 |
| 201 | */ |
| 202 | #ifndef PJ_TERM_HAS_COLOR |
| 203 | # define PJ_TERM_HAS_COLOR 1 |
| 204 | #endif |
| 205 | |
| 206 | /** |
| 207 | * Pool debugging. |
| 208 | * |
| 209 | * Default: 0 |
| 210 | */ |
| 211 | #ifndef PJ_POOL_DEBUG |
| 212 | # define PJ_POOL_DEBUG 0 |
| 213 | #endif |
| 214 | |
| 215 | /** |
| 216 | * \def PJ_HAS_TCP |
| 217 | * Support TCP in the library. |
| 218 | * Disabling TCP will reduce the footprint slightly (about 6KB). |
| 219 | * |
| 220 | * Default: 1 |
| 221 | */ |
| 222 | #ifndef PJ_HAS_TCP |
| 223 | # define PJ_HAS_TCP 1 |
| 224 | #endif |
| 225 | |
| 226 | /** |
| 227 | * Maximum hostname length. |
| 228 | * Libraries sometimes needs to make copy of an address to stack buffer; |
| 229 | * the value here affects the stack usage. |
| 230 | * |
| 231 | * Default: 128 |
| 232 | */ |
| 233 | #ifndef PJ_MAX_HOSTNAME |
| 234 | # define PJ_MAX_HOSTNAME (128) |
| 235 | #endif |
| 236 | |
| 237 | /** |
| 238 | * Constants for declaring the maximum handles that can be supported by |
| 239 | * a single IOQ framework. This constant might not be relevant to the |
| 240 | * underlying I/O queue impelementation, but still, developers should be |
| 241 | * aware of this constant, to make sure that the program will not break when |
| 242 | * the underlying implementation changes. |
| 243 | * |
| 244 | * For implementation based on select(), the value here will be used as the |
| 245 | * maximum number of socket handles passed to select() (i.e. FD_SETSIZE will |
| 246 | * be set to this value). |
| 247 | * |
| 248 | * Default: 256 |
| 249 | */ |
| 250 | #ifndef PJ_IOQUEUE_MAX_HANDLES |
| 251 | # define PJ_IOQUEUE_MAX_HANDLES (256) |
| 252 | #endif |
| 253 | |
| 254 | /** |
| 255 | * Overrides FD_SETSIZE so it is consistent throughout the library. |
| 256 | * OS specific configuration header (compat/os_*) might have declared |
| 257 | * FD_SETSIZE, thus we only set if it hasn't been declared. |
| 258 | * |
| 259 | * Default: #PJ_IOQUEUE_MAX_HANDLES |
| 260 | */ |
| 261 | #ifndef FD_SETSIZE |
| 262 | # define FD_SETSIZE PJ_IOQUEUE_MAX_HANDLES |
| 263 | #endif |
| 264 | |
| 265 | /** |
| 266 | * Has semaphore functionality? |
| 267 | * |
| 268 | * Default: 1 |
| 269 | */ |
| 270 | #ifndef PJ_HAS_SEMAPHORE |
| 271 | # define PJ_HAS_SEMAPHORE 1 |
| 272 | #endif |
| 273 | |
| 274 | |
| 275 | /** |
| 276 | * Event object (for synchronization, e.g. in Win32) |
| 277 | * |
| 278 | * Default: 1 |
| 279 | */ |
| 280 | #ifndef PJ_HAS_EVENT_OBJ |
| 281 | # define PJ_HAS_EVENT_OBJ 1 |
| 282 | #endif |
| 283 | |
| 284 | |
| 285 | /** |
| 286 | * Enable library's extra check. |
| 287 | * If this macro is enabled, #PJ_ASSERT_RETURN macro will expand to |
| 288 | * run-time checking. If this macro is disabled, #PJ_ASSERT_RETURN |
| 289 | * will simply evaluate to #pj_assert(). |
| 290 | * |
| 291 | * You can disable this macro to reduce size, at the risk of crashes |
| 292 | * if invalid value (e.g. NULL) is passed to the library. |
| 293 | * |
| 294 | * Default: 1 |
| 295 | */ |
| 296 | #ifndef PJ_ENABLE_EXTRA_CHECK |
| 297 | # define PJ_ENABLE_EXTRA_CHECK 1 |
| 298 | #endif |
| 299 | |
| 300 | |
| 301 | /** |
| 302 | * Enable name registration for exceptions with #pj_exception_id_alloc(). |
| 303 | * If this feature is enabled, then the library will keep track of |
| 304 | * names associated with each exception ID requested by application via |
| 305 | * #pj_exception_id_alloc(). |
| 306 | * |
| 307 | * Disabling this macro will reduce the code and .bss size by a tad bit. |
| 308 | * See also #PJ_MAX_EXCEPTION_ID. |
| 309 | * |
| 310 | * Default: 1 |
| 311 | */ |
| 312 | #ifndef PJ_HAS_EXCEPTION_NAMES |
| 313 | # define PJ_HAS_EXCEPTION_NAMES 1 |
| 314 | #endif |
| 315 | |
| 316 | /** |
| 317 | * Maximum number of unique exception IDs that can be requested |
| 318 | * with #pj_exception_id_alloc(). For each entry, a small record will |
| 319 | * be allocated in the .bss segment. |
| 320 | * |
| 321 | * Default: 16 |
| 322 | */ |
| 323 | #ifndef PJ_MAX_EXCEPTION_ID |
| 324 | # define PJ_MAX_EXCEPTION_ID 16 |
| 325 | #endif |
| 326 | |
Benny Prijono | 99683ae | 2005-11-21 16:59:47 +0000 | [diff] [blame] | 327 | /** |
| 328 | * Should we use Windows Structured Exception Handling (SEH) for the |
| 329 | * PJLIB exceptions. |
| 330 | * |
| 331 | * Default: 0 |
| 332 | */ |
| 333 | #ifndef PJ_EXCEPTION_USE_WIN32_SEH |
| 334 | # define PJ_EXCEPTION_USE_WIN32_SEH 0 |
| 335 | #endif |
| 336 | |
| 337 | /** |
| 338 | * Should we attempt to use Pentium's rdtsc for high resolution |
| 339 | * timestamp. |
| 340 | * |
| 341 | * Default: 0 |
| 342 | */ |
| 343 | #ifndef PJ_TIMESTAMP_USE_RDTSC |
| 344 | # define PJ_TIMESTAMP_USE_RDTSC 0 |
| 345 | #endif |
| 346 | |
| 347 | |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 348 | /** @} */ |
| 349 | |
| 350 | /******************************************************************** |
| 351 | * General macros. |
| 352 | */ |
| 353 | |
| 354 | /** |
| 355 | * @def PJ_INLINE(type) |
| 356 | * @param type The return type of the function. |
| 357 | * Expand the function as inline. |
| 358 | */ |
| 359 | #define PJ_INLINE(type) PJ_INLINE_SPECIFIER type |
| 360 | |
| 361 | /** |
| 362 | * @def PJ_DECL(type) |
| 363 | * @param type The return type of the function. |
| 364 | * Declare a function. |
| 365 | */ |
| 366 | /** |
| 367 | * @def PJ_DECL_NO_RETURN(type) |
| 368 | * @param type The return type of the function. |
| 369 | * Declare a function that will not return. |
| 370 | */ |
| 371 | /** |
| 372 | * @def PJ_BEGIN_DECL |
| 373 | * Mark beginning of declaration section in a header file. |
| 374 | */ |
| 375 | /** |
| 376 | * @def PJ_END_DECL |
| 377 | * Mark end of declaration section in a header file. |
| 378 | */ |
| 379 | #ifdef __cplusplus |
| 380 | # define PJ_DECL(type) type |
| 381 | # define PJ_DECL_NO_RETURN(type) type PJ_NORETURN |
Benny Prijono | 99683ae | 2005-11-21 16:59:47 +0000 | [diff] [blame] | 382 | # define PJ_IDECL_NO_RETURN(type) PJ_INLINE(type) PJ_NORETURN |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 383 | # define PJ_BEGIN_DECL extern "C" { |
| 384 | # define PJ_END_DECL } |
| 385 | #else |
| 386 | # define PJ_DECL(type) extern type |
| 387 | # define PJ_DECL_NO_RETURN(type) PJ_NORETURN type |
Benny Prijono | 99683ae | 2005-11-21 16:59:47 +0000 | [diff] [blame] | 388 | # define PJ_IDECL_NO_RETURN(type) PJ_NORETURN PJ_INLINE(type) |
Benny Prijono | 9033e31 | 2005-11-21 02:08:39 +0000 | [diff] [blame] | 389 | # define PJ_BEGIN_DECL |
| 390 | # define PJ_END_DECL |
| 391 | #endif |
| 392 | |
| 393 | /** |
| 394 | * @def PJ_DEF(type) |
| 395 | * @param type The return type of the function. |
| 396 | * Define a function. |
| 397 | */ |
| 398 | #define PJ_DEF(type) type |
| 399 | |
| 400 | /** |
| 401 | * @def PJ_EXPORT_SYMBOL(sym) |
| 402 | * @param sym The symbol to export. |
| 403 | * Export the specified symbol in compilation type that requires export |
| 404 | * (e.g. Linux kernel). |
| 405 | */ |
| 406 | #ifdef __PJ_EXPORT_SYMBOL |
| 407 | # define PJ_EXPORT_SYMBOL(sym) __PJ_EXPORT_SYMBOL(sym) |
| 408 | #else |
| 409 | # define PJ_EXPORT_SYMBOL(sym) |
| 410 | #endif |
| 411 | |
| 412 | /** |
| 413 | * @def PJ_IDECL(type) |
| 414 | * @param type The function's return type. |
| 415 | * Declare a function that may be expanded as inline. |
| 416 | */ |
| 417 | /** |
| 418 | * @def PJ_IDEF(type) |
| 419 | * @param type The function's return type. |
| 420 | * Define a function that may be expanded as inline. |
| 421 | */ |
| 422 | |
| 423 | #if PJ_FUNCTIONS_ARE_INLINED |
| 424 | # define PJ_IDECL(type) PJ_INLINE(type) |
| 425 | # define PJ_IDEF(type) PJ_INLINE(type) |
| 426 | #else |
| 427 | # define PJ_IDECL(type) PJ_DECL(type) |
| 428 | # define PJ_IDEF(type) PJ_DEF(type) |
| 429 | #endif |
| 430 | |
| 431 | /** |
| 432 | * @def PJ_UNUSED_ARG(arg) |
| 433 | * @param arg The argument name. |
| 434 | * PJ_UNUSED_ARG prevents warning about unused argument in a function. |
| 435 | */ |
| 436 | #define PJ_UNUSED_ARG(arg) (void)arg |
| 437 | |
| 438 | /** |
| 439 | * @def PJ_TODO(id) |
| 440 | * @param id Any identifier that will be printed as TODO message. |
| 441 | * PJ_TODO macro will display TODO message as warning during compilation. |
| 442 | * Example: PJ_TODO(CLEAN_UP_ERROR); |
| 443 | */ |
| 444 | #ifndef PJ_TODO |
| 445 | # define PJ_TODO(id) TODO___##id: |
| 446 | #endif |
| 447 | |
| 448 | /** |
| 449 | * Function attributes to inform that the function may throw exception. |
| 450 | * |
| 451 | * @param x The exception list, enclosed in parenthesis. |
| 452 | */ |
| 453 | #define __pj_throw__(x) |
| 454 | |
| 455 | |
| 456 | /******************************************************************** |
| 457 | * Sanity Checks |
| 458 | */ |
| 459 | #ifndef PJ_HAS_HIGH_RES_TIMER |
| 460 | # error "PJ_HAS_HIGH_RES_TIMER is not defined!" |
| 461 | #endif |
| 462 | |
| 463 | #if !defined(PJ_HAS_PENTIUM) |
| 464 | # error "PJ_HAS_PENTIUM is not defined!" |
| 465 | #endif |
| 466 | |
| 467 | #if !defined(PJ_IS_LITTLE_ENDIAN) |
| 468 | # error "PJ_IS_LITTLE_ENDIAN is not defined!" |
| 469 | #endif |
| 470 | |
| 471 | #if !defined(PJ_IS_BIG_ENDIAN) |
| 472 | # error "PJ_IS_BIG_ENDIAN is not defined!" |
| 473 | #endif |
| 474 | |
| 475 | |
| 476 | |
| 477 | PJ_BEGIN_DECL |
| 478 | |
| 479 | /** |
| 480 | * PJLIB version string. |
| 481 | */ |
| 482 | extern const char *PJ_VERSION; |
| 483 | |
| 484 | /** |
| 485 | * Dump configuration to log with verbosity equal to info(3). |
| 486 | */ |
| 487 | PJ_DECL(void) pj_dump_config(void); |
| 488 | |
| 489 | PJ_END_DECL |
| 490 | |
| 491 | |
| 492 | #endif /* __PJ_CONFIG_H__ */ |
| 493 | |