Changeset 25 in libcf
- Timestamp:
- 02/02/13 17:27:06 (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cf_debug.h
r21 r25 19 19 20 20 #ifdef _DEBUG 21 # define CF_DEBUG_CREATE_CTX() \ 22 CF_Debug_CreateCtx () 23 24 # define CF_DEBUG_DESTROY_CTX(__ctx) \ 25 CF_Debug_DestroyCtx (__ctx) 26 21 27 # define CF_UPDATE_CTX(__ctx) \ 22 28 CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__) 29 23 30 # define CF_DEBUG_PRINT(__fp,__fmt,...) \ 24 31 CF_Debug_Print (__fp,__FILE__,__func__,__LINE__,__fmt,##__VA_ARGS__) 32 25 33 # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) \ 26 34 CF_Debug_PrintBin (__fp,__FILE__,__func__,__LINE__,__bin,__len,__fmt,##__VA_ARGS__) 35 27 36 # define CF_DEBUG_TRACE(__ctx,__fmt,...) \ 28 37 do { \ … … 30 39 CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__); \ 31 40 } while (0) 41 32 42 # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) \ 33 43 do { \ … … 35 45 CF_Debug_TraceBin (__ctx,__bin,__len,__fmt,##__VA_ARGS__); \ 36 46 } while (0) 47 37 48 # define CF_DEBUG_CALLSTACK_PUSH(__ctx) \ 38 49 CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__) 50 39 51 # define CF_DEBUG_CALLSTACK_POP \ 40 52 CF_Debug_CallStackPop 41 53 #else // #ifdef _DEBUG 54 # define CF_DEBUG_CREATE_CTX() NULL 55 # define CF_DEBUG_DESTROY_CTX(__ctx) 42 56 # define CF_UPDATE_CTX(__ctx) 57 # define CF_DEBUG_PRINT(__fp,__fmt,...) 58 # define CF_DEBUG_PRINT_BIN(__fp,__bin,__len,__fmt,...) 43 59 # define CF_DEBUG_TRACE(__ctx,__fmt,...) 44 60 # define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...) 45 61 # define CF_DEBUG_CALLSTACK_PUSH(__ctx) 46 # define CF_DEBUG_CALLSTACK_POP( )62 # define CF_DEBUG_CALLSTACK_POP(__ctx,__callstack) 1 47 63 #endif // #ifdef _DEBUG 48 64 -
trunk/src/cf_log.c
r23 r25 24 24 #endif // #ifdef _WIN32 25 25 26 #define CHECK_INVALID_CTX(__ctx) \ 27 if (__ctx == NULL) \ 28 return CF_ERROR_LOG_INVALID_CTX 29 30 #define LOCK_LOG_CTX(__ctx) \ 31 CF_Mutex_Lock (&__ctx->mutex) 32 33 #define UNLOCK_LOG_CTX(__ctx) \ 34 CF_Mutex_Unlock (&__ctx->mutex) 26 #define CHECK_INVALID_CTX(__ctx) (__ctx == NULL) 27 #define LOCK_LOG_CTX(__ctx) CF_Mutex_Lock (&__ctx->mutex) 28 #define UNLOCK_LOG_CTX(__ctx) CF_Mutex_Unlock (&__ctx->mutex) 29 #define CHECK_INITIALIZED() (gLogEnvironment.ctxPool == NULL|| \ 30 gLogEnvironment.ctxSize <= 0 ) 31 #define CHECK_INVALID_MAPID(__mapid) (gLogEnvironment.ctxSize <= __mapid) 32 #define CHECK_MAPPED_ID(__mapid) (gLogEnvironment.ctxPool[__mapid] != NULL) \ 33 35 34 36 35 #define CF_LOG_BUFFER_DEFAULT_SIZE 128 * 1024 … … 271 270 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 272 271 273 CHECK_INVALID_CTX (ctx); 272 if (CHECK_INVALID_CTX (ctx)) 273 return CF_ERROR_LOG_INVALID_CTX; 274 274 275 275 memset (context->path, 0x00, sizeof (context->path)); … … 301 301 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 302 302 303 CHECK_INVALID_CTX (ctx); 303 if (CHECK_INVALID_CTX (ctx)) 304 return CF_ERROR_LOG_INVALID_CTX; 304 305 305 306 if (CF_Mutex_Create (&context->mutex) < 0) … … 314 315 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 315 316 316 CHECK_INVALID_CTX (ctx); 317 if (CHECK_INVALID_CTX (ctx)) 318 return CF_ERROR_LOG_INVALID_CTX; 317 319 318 320 if (CF_Mutex_Destory (&context->mutex) < 0) … … 332 334 size_t length = 0; 333 335 334 CHECK_INVALID_CTX (ctx); 336 if (CHECK_INVALID_CTX (ctx)) 337 return CF_ERROR_LOG_INVALID_CTX; 335 338 336 339 LOCK_LOG_CTX (context); … … 375 378 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 376 379 377 CHECK_INVALID_CTX (ctx); 380 if (CHECK_INVALID_CTX (ctx)) 381 return CF_ERROR_LOG_INVALID_CTX; 378 382 379 383 LOCK_LOG_CTX (context); … … 388 392 const CF_Log_Ctx ctx) 389 393 { 390 if (gLogEnvironment.ctxPool == NULL || gLogEnvironment.ctxSize <= 0) 394 int result = 0; 395 396 TRY 397 { 398 if (CHECK_INITIALIZED()) 399 { 400 result = CF_ERROR_LOG_NOT_INITIALIZE; 401 TRY_BREAK; 402 } 403 if (CHECK_INVALID_MAPID(mapid)) 404 { 405 result = CF_ERROR_LOG_INVALID_MAPID; 406 TRY_BREAK; 407 } 408 if (CHECK_MAPPED_ID(mapid)) 409 { 410 result = CF_ERROR_LOG_ALREADY_MAPPED_ID; 411 TRY_BREAK; 412 } 413 } 414 CATCH_IF (result < 0) 415 { 416 CF_Log_DestroyCtx (ctx); 417 return result; 418 } 419 420 gLogEnvironment.ctxPool[mapid] = ctx; 421 422 return CF_OK; 423 } 424 425 int 426 CF_Log_UnmapCtxID (const int mapid) 427 { 428 if (CHECK_INITIALIZED()) 391 429 return CF_ERROR_LOG_NOT_INITIALIZE; 392 393 if (gLogEnvironment.ctxPool[mapid] != NULL) 394 return CF_ERROR_LOG_ALREADY_MAPPED_ID; 395 396 gLogEnvironment.ctxPool[mapid] = ctx; 397 398 return CF_OK; 399 } 400 401 int 402 CF_Log_UnmapCtxID (const int mapid) 403 { 404 if (gLogEnvironment.ctxPool == NULL || gLogEnvironment.ctxSize <= 0) 405 return CF_ERROR_LOG_NOT_INITIALIZE; 406 407 if (gLogEnvironment.ctxPool[mapid] == NULL) 430 if (CHECK_INVALID_MAPID(mapid)) 431 return CF_ERROR_LOG_INVALID_MAPID; 432 if (!CHECK_MAPPED_ID(mapid)) 408 433 return CF_ERROR_LOG_NOT_MAPPED_ID; 409 434 … … 419 444 CF_Log_GetMappedCtx (const int mapid) 420 445 { 421 if ( gLogEnvironment.ctxPool == NULL || gLogEnvironment.ctxSize <= 0)446 if (CHECK_INITIALIZED()) 422 447 return NULL; 448 if (CHECK_INVALID_MAPID(mapid)) 449 return NULL; 450 if (!CHECK_MAPPED_ID(mapid)) 451 return NULL; 423 452 424 453 return gLogEnvironment.ctxPool[mapid]; -
trunk/test/test.c
r24 r25 3 3 */ 4 4 #include "cf_file.h" 5 #include "cf_debug.h"6 5 #include "cf_log.h" 7 6 #include "cf_socket.h" 8 7 #include "cf_thread.h" 9 8 9 /* 10 * before including "cf_debug.h", 11 * if _DEBUG is defined, the debugging code will be act. 12 */ 13 #include "cf_debug.h" 14 10 15 #include <stdlib.h> 11 16 #include <string.h> … … 30 35 31 36 /* initialize */ 32 CF_Log_Initialize (1 0);37 CF_Log_Initialize (1); 33 38 34 39 /* context {{{ */
Note:
See TracChangeset
for help on using the changeset viewer.