root/branches/stable_0_2_0/libfreebob/src/debugmodule/debugmodule.h

Revision 161, 6.3 kB (checked in by anonymous, 18 years ago)

This commit was manufactured by cvs2svn to create branch 'stable_0_2_0'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* debugmodule.h
2  * Copyright (C) 2005 by Daniel Wagner
3  *
4  * This file is part of FreeBob.
5  *
6  * FreeBob is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * FreeBob is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with FreeBob; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA.
19  */
20
21 #ifndef DEBUGMODULE_H
22 #define DEBUGMODULE_H
23
24 #include "../fbtypes.h"
25
26 #include <vector>
27 #include <iostream>
28
29 typedef short debug_level_t;
30
31 #define debugFatal( format, args... )                               \
32                 m_debugModule.print( DebugModule::eDL_Fatal,        \
33                                      __FILE__,                      \
34                                      __FUNCTION__,                  \
35                                      __LINE__,                      \
36                                      format,                        \
37                                      ##args )
38 #define debugError( format, args... )                               \
39                 m_debugModule.print( DebugModule::eDL_Error,        \
40                                      __FILE__,                      \
41                                      __FUNCTION__,                  \
42                                      __LINE__,                      \
43                                      format,                        \
44                                      ##args )
45 #define debugWarning( format, args... )                             \
46                 m_debugModule.print( DebugModule::eDL_Warning,      \
47                                      __FILE__,                      \
48                                      __FUNCTION__,                  \
49                                      __LINE__,                      \
50                                     format,                         \
51                                     ##args )
52
53 #define debugFatalShort( format, args... )                          \
54                 m_debugModule.printShort( DebugModule::eDL_Fatal,   \
55                                      format,                        \
56                                      ##args )
57 #define debugErrorShort( format, args... )                          \
58                 m_debugModule.printShort( DebugModule::eDL_Error,   \
59                                      format,                        \
60                                      ##args )
61 #define debugWarningShort( format, args... )                        \
62                 m_debugModule.printShort( DebugModule::eDL_Warning, \
63                                      format,                        \
64                                      ##args )
65
66 #define DECLARE_DEBUG_MODULE static DebugModule m_debugModule
67 #define IMPL_DEBUG_MODULE( ClassName, RegisterName, Level )        \
68                 DebugModule ClassName::m_debugModule =             \
69                     DebugModule( #RegisterName, Level )
70
71 #define DECLARE_GLOBAL_DEBUG_MODULE extern DebugModule m_debugModule
72 #define IMPL_GLOBAL_DEBUG_MODULE( RegisterName, Level )            \
73                 DebugModule m_debugModule =                        \
74                     DebugModule( #RegisterName, Level )
75                
76
77
78 #ifdef DEBUG
79
80     #define debugOutput( level, format, args... )                  \
81                 m_debugModule.print( level,                        \
82                                      __FILE__,                     \
83                                      __FUNCTION__,                 \
84                                      __LINE__,                     \
85                                      format,                       \
86                                      ##args )
87
88     #define debugOutputShort( level, format, args... )             \
89                 m_debugModule.printShort( level,                   \
90                                      format,                       \
91                                      ##args )
92
93 #else
94
95     #define debugOutput( level, format, args... )
96     #define debugOutputShort( level, format, args... )
97
98 #endif
99
100 unsigned char toAscii( unsigned char c );
101 void quadlet2char( fb_quadlet_t quadlet, unsigned char* buff );
102 void hexDump( unsigned char *data_start, unsigned int length );
103 void hexDumpQuadlets( quadlet_t *data_start, unsigned int length );
104
105 class DebugModule {
106 public:
107     enum {
108         eDL_Fatal   = 0,
109         eDL_Error   = 1,
110         eDL_Warning = 2,
111         eDL_Normal  = 3,
112         eDL_Verbose = 4,
113     } EDebugLevel;
114
115     DebugModule( std::string name, debug_level_t level );
116     virtual ~DebugModule();
117
118     void printShort( debug_level_t level,
119                      const char* format,
120                      ... ) const;
121
122     void print( debug_level_t level,
123                 const char*   file,
124                 const char*   function,
125                 unsigned int  line,
126                 const char*   format,
127                 ... ) const;
128
129     bool setLevel( debug_level_t level )
130         { m_level = level; return true; }
131     debug_level_t getLevel()
132         { return m_level; }
133     std::string getName()
134         { return m_name; }
135
136 protected:
137     const char* getPreSequence( debug_level_t level ) const;
138     const char* getPostSequence( debug_level_t level ) const;
139
140 private:
141     std::string   m_name;
142     debug_level_t m_level;
143 };
144
145 #define DEBUG_LEVEL_NORMAL  DebugModule::eDL_Normal
146 #define DEBUG_LEVEL_VERBOSE DebugModule::eDL_Verbose
147
148
149 class DebugModuleManager {
150 public:
151     friend class DebugModule;
152
153     static DebugModuleManager* instance();
154     bool setDebugLevel( std::string name, debug_level_t level );
155
156 protected:
157     bool registerModule( DebugModule& debugModule );
158     bool unregisterModule( DebugModule& debugModule );
159
160 private:
161     DebugModuleManager();
162     ~DebugModuleManager();
163
164     typedef std::vector< DebugModule* > DebugModuleVector;
165     typedef std::vector< DebugModule* >::iterator DebugModuleVectorIterator;
166
167
168     static DebugModuleManager* m_instance;
169     DebugModuleVector          m_debugModules;
170 };
171
172 #endif
Note: See TracBrowser for help on using the browser.