OSDN Git Service

* WorkBackup: 2015/05/27(Wed) AM 05:32 (Implementing DebugErrorInfoPrint() )
authorKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Tue, 26 May 2015 20:32:01 +0000 (05:32 +0900)
committerKoine Yuusuke(koinec) <koinec@users.sourceforge.jp>
Tue, 26 May 2015 20:32:01 +0000 (05:32 +0900)
include/libbrownie.h
libbrownie/drd64_libbrownie.h
libbrownie/drd64_libbrownie_error.c
libbrownie/drd64_libbrownie_error.h
libbrownie/test_libbrownie_error.c

index 5318d01..8f15527 100644 (file)
@@ -49,13 +49,19 @@ Comment:
 
 /* drd64_libbrownie_error.c Functions ========================*/
 LIBBROWNIE_FUNC
+       int LibBrownie_Error_GetReferenceCount( void );
+LIBBROWNIE_FUNC
+       int LibBrownie_Error_DebugErrorInfoPrint( Drd64_ErrorInfo *p_errinfo, int i_id );
+LIBBROWNIE_FUNC
+       int LibBrownie_Error_DebugAllInfoPrint( void );
+LIBBROWNIE_FUNC
        int LibBrownie_Error_SetErrorInfo(
                        DWord dw_errcode, DWord dw_errlocation, int i_syserrno,
                        QWord qw_value1, QWord qw_value2 );
 LIBBROWNIE_FUNC
        Drd64_ErrorInfo *LibBrownie_Error_GetErrorInfo( int i_history_id );
 LIBBROWNIE_FUNC
-       int LibBrownie_Error_InitErrorSystem( int i_max_errorinfo );
+       int LibBrownie_Error_InitErrorSystem( void );
 LIBBROWNIE_FUNC
        void LibBrownie_Error_TermErrorSystem( void );
 
index 94325aa..17a4845 100644 (file)
@@ -42,6 +42,7 @@ Comment:
 #include<string.h>
 #include<netdb.h>
 #include<unistd.h>
+#include<assert.h>
 #include<sys/types.h>
 #include<sys/socket.h>
 #include<sys/un.h>
index 38ac07c..121d829 100644 (file)
@@ -47,7 +47,66 @@ static       int                             gi_refcount                             = 0;
 ----------------------------------------------------------------------*/
 LIBBROWNIE_FUNC
 int
-       Drd64_LibBrownie_Error_SetErrorInfo(
+       LibBrownie_Error_GetReferenceCount(
+               void )
+{
+       return gi_refcount;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBBROWNIE_FUNC
+int
+       LibBrownie_Error_DebugErrorInfoPrint(
+               Drd64_ErrorInfo *p_errinfo,
+               int     i_id )
+{
+
+       assert( NULL != p_errinfo );
+
+       if( -1 == i_id )
+               { puts("[ErrorInfo] ---------------------------------------------------------"); }
+       else
+               { printf("[ErrorInfo] %2d ------------------------------------------------------\n", i_id ); }
+       printf("  ErrCode : %08x \n", p_errinfo->dw_error );
+       printf("  Location: %08x \n", p_errinfo->dw_location );
+       printf("  errno   : %d \n", p_errinfo->i_system_errno );
+       printf("  Value 1 : %016lx (%lu) \n", p_errinfo->qw_value[0], p_errinfo->qw_value[0] );
+       printf("  Value 2 : %016lx (%lu) \n", p_errinfo->qw_value[1], p_errinfo->qw_value[1] );
+
+       return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBBROWNIE_FUNC
+int
+       LibBrownie_Error_DebugAllInfoPrint(
+               void )
+{
+       int     i_cnt;
+       Drd64_ErrorInfo         *p_errinfo;
+
+       puts("[ErrorInfo Dump]*****************************************************");
+
+       for( i_cnt = 0; i_cnt < gi_max_errorinfo; i_cnt++ )     {
+               p_errinfo       = *(gpp_errorinfo_history + i_cnt);
+
+               LibBrownie_Error_DebugErrorInfoPrint( p_errinfo, i_cnt );
+       }
+       puts("*********************************************************************");
+
+       return 0x00;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+LIBBROWNIE_FUNC
+int
+       LibBrownie_Error_SetErrorInfo(
                DWord   dw_errcode,
                DWord   dw_errlocation,
                int             i_syserrno,
@@ -98,7 +157,7 @@ Drd64_ErrorInfo *
 LIBBROWNIE_FUNC
 int
        LibBrownie_Error_InitErrorSystem(
-               int i_max_errorinfo )
+               void )
 {
        int                                     i_cnt;
        Drd64_ErrorInfo         *p_errinfo;
@@ -108,28 +167,26 @@ int
        gpp_errorinfo_history   = NULL;
        gi_max_errorinfo                = 0;
 
-       if( 1 > i_max_errorinfo )       { return 0x03; }
-
        gi_refcount++;
        if( 1 < gi_refcount )   { return 0x00; }
 
        p_errinfo = (Drd64_ErrorInfo *)malloc(
-                                       sizeof( Drd64_ErrorInfo ) * i_max_errorinfo );
+                                       sizeof( Drd64_ErrorInfo ) * LIBBROWNIE_ERROR_MAXERRORS );
        if( NULL == p_errinfo )         { return 0x01; }
 
-       memset( p_errinfo, 0x00, sizeof( Drd64_ErrorInfo ) * i_max_errorinfo );
+       memset( p_errinfo, 0x00, sizeof( Drd64_ErrorInfo ) * LIBBROWNIE_ERROR_MAXERRORS );
 
        
        pp_errhistory = (Drd64_ErrorInfo **)malloc(
-                                               sizeof( Drd64_ErrorInfo * ) * i_max_errorinfo );
+                                               sizeof( Drd64_ErrorInfo * ) * LIBBROWNIE_ERROR_MAXERRORS );
        if( NULL == pp_errhistory )             { return 0x02; }
 
-       for( i_cnt = 0; i_cnt < i_max_errorinfo; i_cnt++ )
+       for( i_cnt = 0; i_cnt < LIBBROWNIE_ERROR_MAXERRORS; i_cnt++ )
                { *(pp_errhistory + i_cnt )     = (p_errinfo + i_cnt); }
 
        gp_errorinfo_pool               = p_errinfo;
        gpp_errorinfo_history   = pp_errhistory;
-       gi_max_errorinfo                = i_max_errorinfo;
+       gi_max_errorinfo                = LIBBROWNIE_ERROR_MAXERRORS;
        
        return 0x00;
 }
@@ -142,6 +199,7 @@ void
        LibBrownie_Error_TermErrorSystem(
                void )
 {
+       if( 0 == gi_refcount )  { return; }
        gi_refcount--;
        if( 0 < gi_refcount )   { return; }
 
index 94749a8..020296b 100644 (file)
@@ -37,6 +37,8 @@ Comment:
 #ifndef DRD64_HEADER_LIBBROWNIE_ERROR
 #define DRD64_HEADER_LIBBROWNIE_ERROR
 
+#define        LIBBROWNIE_ERROR_MAXERRORS      16
+
 #endif /* DRD64_HEADER_XXX */
 
 /* EOF of drd64_.h ----------------------------------- */
index 57d2748..8fbbece 100644 (file)
@@ -42,7 +42,51 @@ Comment:
 ----------------------------------------------------------------------*/
 void Test_LibBrownie_Error_test00_001(void)
 {
-       CU_ASSERT( 0x01 );
+       int             i_result;
+
+       i_result        = LibBrownie_Error_InitErrorSystem();
+       CU_ASSERT( i_result == 0x00 );
+       CU_ASSERT( 1 == LibBrownie_Error_GetReferenceCount());
+
+       i_result        = LibBrownie_Error_InitErrorSystem();
+       CU_ASSERT( i_result == 0x00 );
+       CU_ASSERT( 2 == LibBrownie_Error_GetReferenceCount());
+
+       LibBrownie_Error_TermErrorSystem();
+       CU_ASSERT( 1 == LibBrownie_Error_GetReferenceCount());
+
+       LibBrownie_Error_TermErrorSystem();
+       CU_ASSERT( 0 == LibBrownie_Error_GetReferenceCount());
+
+       LibBrownie_Error_TermErrorSystem();
+       CU_ASSERT( 0 == LibBrownie_Error_GetReferenceCount());
+
+       i_result        = LibBrownie_Error_InitErrorSystem();
+       CU_ASSERT( i_result == 0x00 );
+       CU_ASSERT( 1 == LibBrownie_Error_GetReferenceCount());
+
+       LibBrownie_Error_TermErrorSystem();
+       CU_ASSERT( 0 == LibBrownie_Error_GetReferenceCount());
+
+       return;
+}
+
+
+/*----------------------------------------------------------------------
+----------------------------------------------------------------------*/
+void Test_LibBrownie_Error_test00_002(void)
+{
+       int             i_result;
+
+       i_result        = LibBrownie_Error_InitErrorSystem();
+       CU_ASSERT( i_result == 0x00 );
+       CU_ASSERT( 1 == LibBrownie_Error_GetReferenceCount());
+
+       LibBrownie_Error_DebugAllInfoPrint();
+
+       LibBrownie_Error_TermErrorSystem();
+       CU_ASSERT( 0 == LibBrownie_Error_GetReferenceCount());
+
        return;
 }
 
@@ -58,7 +102,10 @@ int
        
        pt_brownie      = CU_add_suite( "LibBrownie_Error", NULL, NULL );
 
-       CU_add_test( pt_brownie, "LibBrownie_Error_test00_001", Test_LibBrownie_Error_test00_001 );
+       CU_add_test( pt_brownie, "LibBrownie_Error_test00_001",
+                                                                       Test_LibBrownie_Error_test00_001 );
+       CU_add_test( pt_brownie, "LibBrownie_Error_test00_002",
+                                                                       Test_LibBrownie_Error_test00_002 );
 
        return 0x00;
 }