Changeset 136 in libcf
- Timestamp:
- 07/17/13 12:13:28 (11 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_debug.c
r128 r136 59 59 } CF_DEBUG_CTX; 60 60 61 CF_Debug_Ctx gDebugSingleCtx = NULL;61 static CF_Debug_Ctx gDebugSingleCtx = NULL; 62 62 63 63 static int -
trunk/src/cf_log.c
r128 r136 37 37 38 38 #define ASSERT_INIT() \ 39 if (gLog Array.ctxPool == NULL || \40 gLog Array.ctxSize <= 0 ) \39 if (gLogPool.ctxPool == NULL || \ 40 gLogPool.poolSize <= 0 ) \ 41 41 return CF_ERROR_LOG_NOT_INITIALIZE 42 42 43 43 #define ASSERT_MAPID(__mapid) \ 44 if (gLog Array.ctxSize <= __mapid) \44 if (gLogPool.poolSize <= __mapid) \ 45 45 return CF_ERROR_LOG_INVALID_MAPID 46 46 47 47 #define ASSERT_MAPPED_CTX(__mapid) \ 48 if (gLog Array.ctxPool[__mapid] != NULL) \48 if (gLogPool.ctxPool[__mapid] != NULL) \ 49 49 return CF_ERROR_LOG_ALREADY_MAPPED_ID 50 50 51 51 #define ASSERT_NOT_MAPPED_CTX(__mapid) \ 52 if (gLog Array.ctxPool[__mapid] == NULL) \52 if (gLogPool.ctxPool[__mapid] == NULL) \ 53 53 return CF_ERROR_LOG_NOT_MAPPED_ID 54 54 … … 87 87 { 88 88 CF_Log_Ctx * ctxPool; 89 int ctxSize;90 } CF_LOG_ ARRAY;91 92 static CF_LOG_ ARRAY gLogArray;89 int poolSize; 90 } CF_LOG_POOL; 91 92 static CF_LOG_POOL gLogPool; 93 93 94 94 #if defined(_WIN32) || defined(_WIN64) … … 294 294 * \param prefix 로그의 프리픽스 문자열 295 295 * \param fmt 포맷 스트링 296 * \param ... 가변 인자 297 */ 298 static int 299 CF_Log_WriteCtx (CF_Log_Ctx ctx, 300 const char * prefix, 301 const char * fmt, 302 // ...) 303 va_list valist) 296 * \param valist 가변 인자 리스트 297 */ 298 static int 299 CF_Log_WriteVA (CF_Log_Ctx ctx, 300 const char * prefix, 301 const char * fmt, 302 va_list valist) 304 303 { 305 304 #define BUF_LEN 16 * 1024 306 305 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 307 // va_list valist;308 306 char buffer[BUF_LEN + 1] = {0x00,}; 309 307 char datetime[LOG_DATETIME_LENGTH + 1] = {0x00,}; 310 308 int length = 0; 309 int result = 0; 311 310 312 311 ASSERT_CTX (ctx); 313 314 CF_Mutex_Lock (context->mutex);315 // va_start (valist, fmt);316 312 317 313 CF_Log_Local_GetTimeString (datetime); … … 319 315 vsnprintf (&buffer[length], BUF_LEN - (size_t)length, fmt, valist); 320 316 321 CF_Log_Local_Push (context, buffer, strlen (buffer)); 322 323 // va_end (valist); 317 CF_Mutex_Lock (context->mutex); 318 result = CF_Log_Local_Push (context, buffer, strlen (buffer)); 324 319 CF_Mutex_Unlock (context->mutex); 325 320 326 return CF_OK; 321 return result; 322 } 323 324 /** 325 * 로그 컨텍스트에 따라 로그 쓰기 326 * 327 * \return 성공 시, CF_OK; 실패 시, 오류 코드 328 * 329 * \param ctx 로그 컨텍스트 330 * \param prefix 로그의 프리픽스 문자열 331 * \param fmt 포맷 스트링 332 * \param ... 가변 인자 333 */ 334 int 335 CF_Log_WriteCtx (CF_Log_Ctx ctx, 336 const char * prefix, 337 const char * fmt, ...) 338 { 339 int result = 0; 340 va_list valist; 341 342 va_start (valist, fmt); 343 result = CF_Log_WriteVA (ctx, prefix, fmt, valist); 344 va_end (valist); 345 346 return result; 327 347 } 328 348 … … 337 357 CF_Log_FlushCtx (CF_Log_Ctx ctx) 338 358 { 339 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 359 CF_LOG_CTX * context = (CF_LOG_CTX *) ctx; 360 int result = 0; 340 361 341 362 ASSERT_CTX (ctx); 342 363 343 CF_Mutex_Lock (context->mutex);344 364 CF_Log_Local_Flush (context); 365 result = CF_Mutex_Lock (context->mutex); 345 366 CF_Mutex_Unlock (context->mutex); 346 367 347 return CF_OK;368 return result; 348 369 } 349 370 … … 464 485 ASSERT_MAPPED_CTX (mapid); 465 486 466 gLog Array.ctxPool[mapid] = ctx;487 gLogPool.ctxPool[mapid] = ctx; 467 488 468 489 return CF_OK; … … 487 508 ASSERT_NOT_MAPPED_CTX (mapid); 488 509 489 CF_Log_DestroyCtx (gLog Array.ctxPool[mapid]);490 491 free (gLog Array.ctxPool[mapid]);492 gLog Array.ctxPool[mapid] = NULL;510 CF_Log_DestroyCtx (gLogPool.ctxPool[mapid]); 511 512 free (gLogPool.ctxPool[mapid]); 513 gLogPool.ctxPool[mapid] = NULL; 493 514 494 515 return CF_OK; … … 511 532 ASSERT_NOT_MAPPED_CTX (mapid); 512 533 513 *ctx = gLog Array.ctxPool[mapid];534 *ctx = gLogPool.ctxPool[mapid]; 514 535 515 536 return CF_OK; … … 526 547 CF_Log_Initialize (const int poolSize) 527 548 { 528 memset (&gLog Array, 0x00, sizeof (CF_LOG_ARRAY));549 memset (&gLogPool, 0x00, sizeof (CF_LOG_POOL)); 529 550 530 551 if (poolSize > 0) 531 552 { 532 gLog Array.ctxPool =553 gLogPool.ctxPool = 533 554 (CF_Log_Ctx *) calloc ((size_t) poolSize, sizeof (CF_Log_Ctx)); 534 if (gLog Array.ctxPool == NULL)555 if (gLogPool.ctxPool == NULL) 535 556 return CF_ERROR_LOG_INITIALIZE; 536 gLog Array.ctxSize = poolSize;557 gLogPool.poolSize = poolSize; 537 558 } 538 559 … … 550 571 int mapid = 0; 551 572 552 for (mapid = 0 ; mapid < gLog Array.ctxSize ; mapid++)573 for (mapid = 0 ; mapid < gLogPool.poolSize ; mapid++) 553 574 { 554 575 CF_Log_UnmapCtxID (mapid); 555 576 } 556 577 557 if (gLog Array.ctxPool != NULL)558 free (gLog Array.ctxPool);559 560 memset (&gLog Array, 0x00, sizeof (CF_LOG_ARRAY));578 if (gLogPool.ctxPool != NULL) 579 free (gLogPool.ctxPool); 580 581 memset (&gLogPool, 0x00, sizeof (CF_LOG_POOL)); 561 582 562 583 return CF_OK; … … 679 700 680 701 va_start (valist, fmt); 681 result = CF_Log_Write Ctx(ctx, prefix, fmt, valist);702 result = CF_Log_WriteVA (ctx, prefix, fmt, valist); 682 703 va_end (valist); 683 704
Note:
See TracChangeset
for help on using the changeset viewer.