Changeset 51

Show
Ignore:
Timestamp:
01/23/05 07:25:27 (19 years ago)
Author:
wagi
Message:

Support non-instance debugging (e.g. in static function) with a global
debug module instance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/freebob/src/debugmodule.cpp

    r43 r51  
    4343 
    4444void 
    45 DebugStandard::debugError( const char* file, 
     45DebugStandard::error( const char* file, 
    4646                           const char* function, 
    4747                           unsigned int line, 
     
    5757 
    5858void 
    59 DebugStandard::debugPrint( int level, 
     59DebugStandard::print( int level, 
    6060                           const char* file, 
    6161                           const char* function, 
     
    7474 
    7575void 
    76 DebugStandard::debugPrintShort( int level, 
     76DebugStandard::printShort( int level, 
    7777                                const char* format, ... ) const 
    7878{ 
     
    9595 
    9696void 
    97 DebugAnsiColor::debugError( const char* file, 
    98                             const char* function, 
    99                             unsigned int line, 
    100                             const char* format, ... ) const 
     97DebugAnsiColor::error( const char* file, 
     98                       const char* function, 
     99                       unsigned int line, 
     100                       const char* format, ... ) const 
    101101{ 
    102102    va_list arg; 
     
    111111 
    112112void 
    113 DebugAnsiColor::debugPrint( int level, 
    114                             const char* file, 
    115                             const char* function, 
    116                             unsigned int line, 
    117                             const char* format, ... ) const 
     113DebugAnsiColor::print( int level, 
     114                       const char* file, 
     115                       const char* function, 
     116                       unsigned int line, 
     117                       const char* format, ... ) const 
    118118{ 
    119119    if (level & m_level) { 
     
    130130 
    131131void 
    132 DebugAnsiColor::debugPrintShort( int level, 
    133                                  const char* format, ... ) const 
     132DebugAnsiColor::printShort( int level, 
     133                            const char* format, ... ) const 
    134134{ 
    135135    if (level & m_level) { 
     
    183183 
    184184void 
    185 DebugHtml::debugError( const char* file, 
    186                        const char* function, 
    187                        unsigned int line, 
    188                        const char* format, ... ) const 
     185DebugHtml::error( const char* file, 
     186                  const char* function, 
     187                  unsigned int line, 
     188                  const char* format, ... ) const 
    189189{ 
    190190    va_list arg; 
     
    199199 
    200200void 
    201 DebugHtml::debugPrint( int level, 
    202                        const char* file, 
    203                        const char* function, 
    204                        unsigned int line, 
    205                        const char* format, ... ) const 
     201DebugHtml::print( int level, 
     202                  const char* file, 
     203                  const char* function, 
     204                  unsigned int line, 
     205                  const char* format, ... ) const 
    206206{ 
    207207    if (level & m_level) { 
     
    218218 
    219219void 
    220 DebugHtml::debugPrintShort( int level, const char* format, ... ) const 
     220DebugHtml::printShort( int level, const char* format, ... ) const 
    221221{ 
    222222    if (level & m_level) { 
  • trunk/freebob/src/debugmodule.h

    r43 r51  
    3333#define DEBUG_LEVEL_TRANSFERS       (1<<5) 
    3434 
     35#define DEBUG_LEVEL_SCHEDULER       (1<<6) 
     36 
    3537// convenience defines 
    36 #define DEBUG_LEVEL_ALL      (DEBUG_LEVEL_INFO | DEBUG_LEVEL_DEVICE | DEBUG_LEVEL_SUBUNIT | DEBUG_LEVEL_DESCRIPTOR | DEBUG_LEVEL_INFOBLOCK | DEBUG_LEVEL_TRANSFERS ) 
    37 #define DEBUG_LEVEL_LOW      (DEBUG_LEVEL_INFO | DEBUG_LEVEL_DEVICE) 
    38 #define DEBUG_LEVEL_MODERATE (DEBUG_LEVEL_INFO | DEBUG_LEVEL_DEVICE | DEBUG_LEVEL_SUBUNIT) 
    39 #define DEBUG_LEVEL_HIGH     (DEBUG_LEVEL_MODERATE | DEBUG_LEVEL_DESCRIPTOR | DEBUG_LEVEL_INFOBLOCK) 
     38#define DEBUG_LEVEL_ALL      (  DEBUG_LEVEL_INFO \ 
     39                              | DEBUG_LEVEL_DEVICE \ 
     40                              | DEBUG_LEVEL_SUBUNIT \ 
     41                              | DEBUG_LEVEL_DESCRIPTOR \ 
     42                              | DEBUG_LEVEL_INFOBLOCK \ 
     43                              | DEBUG_LEVEL_TRANSFERS \ 
     44                              | DEBUG_LEVEL_SCHEDULER ) 
     45#define DEBUG_LEVEL_LOW      (  DEBUG_LEVEL_INFO \ 
     46                              | DEBUG_LEVEL_DEVICE ) 
     47#define DEBUG_LEVEL_MODERATE (  DEBUG_LEVEL_INFO \ 
     48                              | DEBUG_LEVEL_DEVICE \ 
     49                              | DEBUG_LEVEL_SUBUNIT ) 
     50#define DEBUG_LEVEL_HIGH     (  DEBUG_LEVEL_MODERATE \ 
     51                              | DEBUG_LEVEL_DESCRIPTOR \ 
     52                              | DEBUG_LEVEL_INFOBLOCK ) 
    4053 
    4154unsigned char toAscii( unsigned char c ); 
     
    4861    virtual ~DebugBase(); 
    4962 
    50     void setDebugLevel( int level ) 
     63    void setLevel( int level ) 
    5164        { m_level = level; } 
    5265 
    53     virtual void debugError( const char* file,  
    54                              const char* function,  
    55                              unsigned int line,  
     66    virtual void error( const char* file,  
     67                        const char* function,  
     68                        unsigned int line,  
     69                        const char* format, ... ) const = 0; 
     70    virtual void print( int level,  
     71                        const char* file,  
     72                        const char* function,  
     73                        unsigned int line,  
     74                        const char* format, ... ) const = 0; 
     75    virtual void printShort( int level,  
    5676                             const char* format, ... ) const = 0; 
    57     virtual void debugPrint( int level,  
    58                              const char* file,  
    59                              const char* function,  
    60                              unsigned int line,  
    61                              const char* format, ... ) const = 0; 
    62     virtual void debugPrintShort( int level,  
    63                                   const char* format, ... ) const = 0; 
    6477 
    6578 protected: 
     
    7285    virtual ~DebugStandard(); 
    7386 
    74     virtual void debugError( const char* file,  
    75                              const char* function,  
    76                              unsigned int line,  
     87    virtual void error( const char* file,  
     88                        const char* function,  
     89                        unsigned int line,  
     90                        const char* format, ... ) const; 
     91    virtual void print( int level,  
     92                        const char* file,  
     93                        const char* function,  
     94                        unsigned int line,  
     95                        const char* format, ... ) const; 
     96    virtual void printShort( int level,  
    7797                             const char* format, ... ) const; 
    78     virtual void debugPrint( int level,  
    79                              const char* file,  
    80                              const char* function,  
    81                              unsigned int line,  
    82                              const char* format, ... ) const; 
    83     virtual void debugPrintShort( int level,  
    84                                   const char* format, ... ) const; 
    8598}; 
    8699 
     
    90103    virtual ~DebugAnsiColor(); 
    91104 
    92     virtual void debugError( const char* file,  
    93                              const char* function,  
    94                              unsigned int line,  
     105    virtual void error( const char* file,  
     106                        const char* function,  
     107                        unsigned int line,  
     108                        const char* format, ... ) const; 
     109    virtual void print( int level,  
     110                        const char* file,  
     111                        const char* function,  
     112                        unsigned int line,  
     113                        const char* format, ... ) const; 
     114    virtual void printShort( int level,  
    95115                             const char* format, ... ) const; 
    96     virtual void debugPrint( int level,  
    97                              const char* file,  
    98                              const char* function,  
    99                              unsigned int line,  
    100                              const char* format, ... ) const; 
    101     virtual void debugPrintShort( int level,  
    102                                   const char* format, ... ) const; 
    103  
     116     
    104117 protected: 
    105118    const char* getLevelColor( int level ) const; 
     
    111124    virtual ~DebugHtml(); 
    112125 
    113     void debugError( const char* file,  
    114                      const char* function,  
    115                      unsigned int line,  
     126    void error( const char* file,  
     127                const char* function,  
     128                unsigned int line,  
     129                const char* format, ... ) const; 
     130    void print( int level,  
     131                const char* file,  
     132                const char* function,  
     133                unsigned int line,  
     134                const char* format, ... ) const; 
     135    void printShort( int level,  
    116136                     const char* format, ... ) const; 
    117     void debugPrint( int level,  
    118                      const char* file,  
    119                      const char* function,  
    120                      unsigned int line,  
    121                      const char* format, ... ) const; 
    122     void debugPrintShort( int level,  
    123                           const char* format, ... ) const; 
    124137 
    125138 protected: 
     
    129142#ifdef DEBUG 
    130143 
    131 #define setDebugLevel(x) m_debug.setDebugLevel( x ) 
    132 #define debugError(format, args...) m_debug.debugError( __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
    133 #define debugPrint(level, format, args...) m_debug.debugPrint( level, __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
    134 #define debugPrintShort(level, format, args...) m_debug.debugPrintShort( level, format, ##args ) 
     144#define setDebugLevel(x) m_debug.setLevel( x ) 
     145#define debugError(format, args...) m_debug.error( __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
     146#define debugPrint(level, format, args...) m_debug.print( level, __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
     147#define debugPrintShort(level, format, args...) m_debug.printShort( level, format, ##args ) 
     148 
     149#define setGlobalDebugLevel(x) gGlobalDebugModule.setLevel( x ) 
     150#define debugGlobalError(format, args...) gGlobalDebugModule.error( __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
     151#define debugGlobalPrint(level, format, args...) gGlobalDebugModule.print( level, __FILE__, __FUNCTION__, __LINE__, format, ##args ) 
     152#define debugGlobalPrintShort(level, format, args...) gGlobalDebugModule.printShort( level, format, ##args ) 
    135153 
    136154// XXX To change the debug module the header has to be edited 
    137155// which sucks big time 
    138156#define DECLARE_DEBUG_MODULE DebugAnsiColor m_debug 
     157 
     158// For static functions 
     159#define DECLARE_GLOBAL_DEBUG_MODULE DebugAnsiColor gGlobalDebugModule 
     160#define USE_GLOBAL_DEBUG_MODULE extern DebugAnsiColor gGlobalDebugModule 
    139161 
    140162#else /* !DEBUG */