Changeset 25 in libcf for trunk/src/cf_log.c
- Timestamp:
- 02/02/13 17:27:06 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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];
Note:
See TracChangeset
for help on using the changeset viewer.