Changeset 19 in libcf for trunk/src/cf_log.c


Ignore:
Timestamp:
02/01/13 12:48:28 (11 years ago)
Author:
cheese
Message:

#1 add logging function with mapped id

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/cf_log.c

    r14 r19  
    201201CF_Log_Finalize (void)
    202202{
     203    int mapid = 0;
     204
     205    for (mapid = 0 ; mapid < gLogEnvironment.ctxSize ; mapid++)
     206    {
     207        CF_Log_UnmapCtxID (mapid);
     208    }
     209
     210    if (gLogEnvironment.ctxPool != NULL)
     211        free (gLogEnvironment.ctxPool);
     212
    203213    memset (&gLogEnvironment, 0x00, sizeof (CF_LOG_ENVIRONMENT));
    204214
     
    257267
    258268int
    259 CF_Log_SetMultiThread (CF_Log_Ctx ctx)
    260 {
    261     CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
    262 
    263     CHECK_INVALID_CTX (ctx);
    264 
    265     if (CF_Mutex_Create (&context->mutex) < 0)
    266         return CF_ERROR_LOG_SET_MULTITHREAD;
    267 
    268     return CF_OK;
    269 }
    270 
    271 int
    272 CF_Log_UnsetMultiThread (CF_Log_Ctx ctx)
    273 {
    274     CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
    275 
    276     CHECK_INVALID_CTX (ctx);
    277 
    278     if (CF_Mutex_Destory (&context->mutex) < 0)
    279         return CF_ERROR_LOG_UNSET_MULTITHREAD;
    280 
    281     return CF_OK;
    282 }
    283 
    284 int
    285269CF_Log_DestroyCtx (CF_Log_Ctx ctx)
    286270{
     
    313297
    314298int
     299CF_Log_SetMultiThread (CF_Log_Ctx ctx)
     300{
     301    CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
     302
     303    CHECK_INVALID_CTX (ctx);
     304
     305    if (CF_Mutex_Create (&context->mutex) < 0)
     306        return CF_ERROR_LOG_SET_MULTITHREAD;
     307
     308    return CF_OK;
     309}
     310
     311int
     312CF_Log_UnsetMultiThread (CF_Log_Ctx ctx)
     313{
     314    CF_LOG_CTX * context = (CF_LOG_CTX *) ctx;
     315
     316    CHECK_INVALID_CTX (ctx);
     317
     318    if (CF_Mutex_Destory (&context->mutex) < 0)
     319        return CF_ERROR_LOG_UNSET_MULTITHREAD;
     320
     321    return CF_OK;
     322}
     323
     324int
    315325CF_Log_Write (CF_Log_Ctx    ctx,
    316326              const char    * prefix,
     
    373383    return CF_OK;
    374384}
     385
     386int
     387CF_Log_MapCtxID (const int          mapid,
     388                 const CF_Log_Ctx   ctx)
     389{
     390    if (gLogEnvironment.ctxPool == NULL || gLogEnvironment.ctxSize <= 0)
     391        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
     401int
     402CF_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)
     408        return CF_ERROR_LOG_NOT_MAPPED_ID;
     409
     410    CF_Log_DestroyCtx (gLogEnvironment.ctxPool[mapid]);
     411
     412    free (gLogEnvironment.ctxPool[mapid]);
     413    gLogEnvironment.ctxPool[mapid] = NULL;
     414
     415    return CF_OK;
     416}
     417
     418CF_Log_Ctx
     419CF_Log_GetMappedCtx (const int mapid)
     420{
     421    if (gLogEnvironment.ctxPool == NULL || gLogEnvironment.ctxSize <= 0)
     422        return NULL;
     423
     424    return gLogEnvironment.ctxPool[mapid];
     425}
Note: See TracChangeset for help on using the changeset viewer.