Changeset 14 in libcf


Ignore:
Timestamp:
01/31/13 22:55:37 (11 years ago)
Author:
cheese
Message:

#1 add test code and fix debug and logging error

Location:
trunk
Files:
5 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_debug.h

    r10 r14  
    1717
    1818#ifdef _DEBUG
     19# define CF_UPDATE_CTX(__ctx)                                       \
     20    CF_Debug_UpdateCtx (__ctx,__FILE__,__func__,__LINE__)
    1921# define CF_DEBUG_TRACE(__ctx,__fmt,...)                            \
    20     CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__)
     22    do {                                                            \
     23    CF_UPDATE_CTX (__ctx);                                          \
     24    CF_Debug_Trace (__ctx,__fmt,##__VA_ARGS__);                     \
     25    } while (0)
    2126# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)            \
    22     CF_Debug_Trace (__ctx,__bin,__len,__fmt,##__VA_ARGS__)
     27    do {                                                            \
     28    CF_UPDATE_CTX (__ctx);                                          \
     29    CF_Debug_Trace (__ctx,__bin,__len,__fmt,##__VA_ARGS__);         \
     30    } while (0)
    2331# define CF_DEBUG_CALLSTACK_PUSH(__ctx)                             \
    24     CF_Debug_CallstackPush (__ctx,__FILE__,__func__,__LINE__)
     32    CF_Debug_CallStackPush (__ctx,__FILE__,__func__,__LINE__)
    2533# define CF_DEBUG_CALLSTACK_POP                                     \
    26     CF_Debug_CallstackPop
     34    CF_Debug_CallStackPop
    2735#else // #ifdef _DEBUG
     36# define CF_UPDATE_CTX(__ctx)
    2837# define CF_DEBUG_TRACE(__ctx,__fmt,...)
    2938# define CF_DEBUG_TRACE_BIN(__ctx,__bin,__len,__fmt,...)
     
    3443typedef void *  CF_Debug_Ctx;
    3544typedef struct cf_debug_callStack {
     45    char    file[NAME_LENGTH + 1];
    3646    char    function[NAME_LENGTH + 1];
    3747    int     line;
     
    5161CF_Debug_SetOutputFD    (CF_Debug_Ctx   ctx,
    5262                         int            fd);
     63
     64CF_EXPORT int
     65CF_Debug_UpdateCtx      (CF_Debug_Ctx   ctx,
     66                         const char     * file,
     67                         const char     * func,
     68                         const int      line);
    5369
    5470CF_EXPORT int
  • trunk/src/cf_debug.c

    r12 r14  
    4949} S_CF_DEBUG_CTX, CF_DEBUG_CTX;
    5050
    51 void
     51int
    5252CF_Debug_Local_Print (CF_DEBUG_CTX  * ctx,
    5353                      const char    * fmt,
    5454                      va_list       valist)
    5555{
    56     fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s %s(%d)] ",
     56    fprintf (GET_CTX_OSTREAM (ctx), "[DEBUG][%s:%d][%s] ",
    5757                                    ctx->file,
    58                                     ctx->func,
    59                                     ctx->line);
     58                                    ctx->line,
     59                                    ctx->func);
    6060    vfprintf (GET_CTX_OSTREAM (ctx), fmt, valist);
     61
     62    return CF_OK;
    6163}
    6264
     
    129131        return CF_ERROR_DEBUG_SET_OUTPUT_FD;
    130132    }
     133
     134    return CF_OK;
     135}
     136
     137int
     138CF_Debug_UpdateCtx (CF_Debug_Ctx    ctx,
     139                    const char      * file,
     140                    const char      * func,
     141                    const int       line)
     142{
     143    CF_DEBUG_CTX * context = (CF_DEBUG_CTX *) ctx;
     144
     145    CHECK_INVALID_CTX (ctx);
     146
     147    strncpy (context->file, file, strlen (file));
     148    strncpy (context->func, func, strlen (func));
     149    context->line = line;
    131150
    132151    return CF_OK;
     
    154173                   const char           * fmt, ...)
    155174{
    156     int             i, j;
    157     va_list         valist;
    158     FILE            * fp = GET_CTX_OSTREAM (ctx);
    159 
    160     CHECK_INVALID_CTX (ctx);
     175    int     i, j;
     176    va_list valist;
     177    FILE    * fp = NULL;
     178
     179    CHECK_INVALID_CTX (ctx);
     180    fp = GET_CTX_OSTREAM (ctx);
    161181
    162182    va_start (valist, fmt);
     
    210230    context->callstack.caller = push;
    211231
    212     /* set current context */
    213     sprintf (context->file, "%s", file);
    214     sprintf (context->func, "%s", func);
    215     context->line = line;
     232    CF_Debug_UpdateCtx (ctx, file, func, line);
    216233
    217234    return CF_OK;
     
    233250    if (callstack != NULL)
    234251    {
     252        sprintf (callstack->file    , "%s", pop->file);
    235253        sprintf (callstack->function, "%s", pop->func);
    236254        callstack->line = pop->line;
     
    244262    if (pop->caller != NULL)
    245263    {
    246         sprintf (context->file, "%s", pop->caller->file);
    247         sprintf (context->func, "%s", pop->caller->func);
    248         context->line = pop->caller->line;
    249         context->callstack.caller = pop->caller;
    250     }
    251 
     264        CF_Debug_UpdateCtx (ctx,
     265                            pop->caller->file,
     266                            pop->caller->func,
     267                            pop->caller->line);
     268    }
     269
     270    context->callstack.caller = pop->caller;
    252271    free (pop);
    253272
  • trunk/src/cf_file.c

    r5 r14  
    55
    66#ifdef _WIN32
     7# include <stdio.h>
    78# include <io.h>
    8 # include <stdio.h>
     9# include <sys/stat.h>
     10
     11# define S_IWUSR        _S_IWRITE
     12# define S_IRUSR        _S_IREAD
     13# define S_IXUSR        _S_IEXEC
     14# define S_IRGRP        0x00000000
     15# define S_IWGRP        0x00000000
     16# define S_IXGRP        0x00000000
     17# define S_IROTH        0x00000000
     18# define S_IWOTH        0x00000000
     19# define S_IXOTH        0x00000000
    920#else // #ifdef _WIN32
    1021# include <unistd.h>
     
    2637CF_File_Create (const char * path)
    2738{
    28     int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, 0);
     39    int result = open (path, O_CREAT | O_WRONLY | O_TRUNC, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
    2940
    3041    if (result < 0)
  • trunk/src/cf_log.c

    r13 r14  
    22 * cf_log.c
    33 */
     4#ifdef _WIN32
     5# define _USE_32BIT_TIME_T
     6#endif
     7
    48#include "cf_log.h"
    59#include "cf_file.h"
     
    1418
    1519#ifdef _WIN32
     20# define snprintf       _snprintf
    1621# include <Windows.h>
    1722#else // #ifdef _WIN32
     
    2429
    2530#define LOCK_LOG_CTX(__ctx)                     \
    26     if (CF_Mutex_Lock (&__ctx->mutex) < 0)      \
    27         return CF_ERROR_LOG_LOCK_CTX
     31    CF_Mutex_Lock (&__ctx->mutex)
    2832
    2933#define UNLOCK_LOG_CTX(__ctx)                   \
    30     if (CF_Mutex_Unlock (&__ctx->mutex) < 0)    \
    31         return CF_ERROR_LOG_UNLOCK_CTX
     34    CF_Mutex_Unlock (&__ctx->mutex)
    3235
    3336#define CF_LOG_BUFFER_DEFAULT_SIZE      128 * 1024
     
    146149    CF_Log_Local_GetTime (&dt);
    147150
    148     sprintf (buffer, "%02d-%02d-%02d %02d:%02d:%02d.%03d",
    149                      dt.year, dt.month, dt.day,
    150                      dt.hour, dt.min, dt.sec, dt.usec);
     151   
     152
     153    snprintf (buffer, strlen ("0000-00-00 00:00:00.000"),
     154              "%02d-%02d-%02d %02d:%02d:%02d.%03d",
     155              dt.year, dt.month, dt.day,
     156              dt.hour, dt.min, dt.sec, dt.usec);
    151157
    152158    return CF_OK;
     
    287293    if (context->buffer != NULL)
    288294    {
    289         /* FIXME : write residual data in buffer */
    290 
     295        CF_Log_Flush (ctx);
    291296        free (context->buffer);
    292297        context->buffer = NULL;
  • trunk/src/makefile

    r10 r14  
    4343                    cf_log          \
    4444
    45 LIB_NAME        = cf
     45TARGET_NAME     = cf
    4646
    4747CC              = gcc
     
    5757TARGET_PATH     = ../_build
    5858OBJ_PATH        = ../_obj
    59 TARGET          = $(TARGET_PATH)/lib$(LIB_NAME).$(EXT_SHARED)
     59TARGET          = $(TARGET_PATH)/lib$(TARGET_NAME).$(EXT_SHARED)
    6060SRCS            = $(addsuffix .$(SOURCE_TYPE),$(FILES))
    6161OBJS            = $(addprefix $(OBJ_PATH)/,$(addsuffix .o,$(FILES)))
  • trunk/windows/libcf.sln

    r13 r14  
    22Microsoft Visual Studio Solution File, Format Version 10.00
    33# Visual Studio 2008
    4 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcf", "libcf/libcf.vcproj", "{E5FB2D95-3841-464C-B23F-94ADA4499FE6}"
     4Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libCF", "libcf\libcf.vcproj", "{E5FB2D95-3841-464C-B23F-94ADA4499FE6}"
     5EndProject
     6Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcproj", "{D344FA91-7B7A-4390-9CA5-E1ABCCECA3A2}"
     7    ProjectSection(ProjectDependencies) = postProject
     8        {E5FB2D95-3841-464C-B23F-94ADA4499FE6} = {E5FB2D95-3841-464C-B23F-94ADA4499FE6}
     9    EndProjectSection
    510EndProject
    611Global
     
    1419        {E5FB2D95-3841-464C-B23F-94ADA4499FE6}.Release|Win32.ActiveCfg = Release|Win32
    1520        {E5FB2D95-3841-464C-B23F-94ADA4499FE6}.Release|Win32.Build.0 = Release|Win32
     21        {D344FA91-7B7A-4390-9CA5-E1ABCCECA3A2}.Debug|Win32.ActiveCfg = Debug|Win32
     22        {D344FA91-7B7A-4390-9CA5-E1ABCCECA3A2}.Debug|Win32.Build.0 = Debug|Win32
     23        {D344FA91-7B7A-4390-9CA5-E1ABCCECA3A2}.Release|Win32.ActiveCfg = Release|Win32
     24        {D344FA91-7B7A-4390-9CA5-E1ABCCECA3A2}.Release|Win32.Build.0 = Release|Win32
    1625    EndGlobalSection
    1726    GlobalSection(SolutionProperties) = preSolution
  • trunk/windows/libcf/libcf.vcproj

    r13 r14  
    2222            IntermediateDirectory="$(ConfigurationName)"
    2323            ConfigurationType="2"
    24             CharacterSet="1"
     24            CharacterSet="0"
    2525            >
    2626            <Tool
     
    9595            IntermediateDirectory="$(ConfigurationName)"
    9696            ConfigurationType="2"
    97             CharacterSet="1"
     97            CharacterSet="0"
    9898            WholeProgramOptimization="1"
    9999            >
Note: See TracChangeset for help on using the changeset viewer.