root/trunk/freebob/src/debugmodule.h

Revision 43, 4.7 kB (checked in by wagi, 18 years ago)

Debug module overhaul.
Compile warnings removed.
Creating and destroying of AvDevices? now done as described in mail.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* debugmodule.h
2  * Copyright (C) 2004,05 by Daniel Wagner, Pieter Palmers
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 <stdio.h>
25 #include <libraw1394/raw1394.h>
26
27 // debug print control flags
28 #define DEBUG_LEVEL_INFO            (1<<0)
29 #define DEBUG_LEVEL_DEVICE          (1<<1)
30 #define DEBUG_LEVEL_SUBUNIT         (1<<2)
31 #define DEBUG_LEVEL_DESCRIPTOR      (1<<3)
32 #define DEBUG_LEVEL_INFOBLOCK       (1<<4)
33 #define DEBUG_LEVEL_TRANSFERS       (1<<5)
34
35 // 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)
40
41 unsigned char toAscii( unsigned char c );
42 void quadlet2char( quadlet_t quadlet, unsigned char* buff );
43 void hexDump( unsigned char *data_start, unsigned int length );
44
45 class DebugBase {
46  public:
47     DebugBase();
48     virtual ~DebugBase();
49
50     void setDebugLevel( int level )
51         { m_level = level; }
52
53     virtual void debugError( const char* file,
54                              const char* function,
55                              unsigned int line,
56                              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;
64
65  protected:
66     int m_level;
67 };
68
69 class DebugStandard : public DebugBase {
70  public:
71     DebugStandard();
72     virtual ~DebugStandard();
73
74     virtual void debugError( const char* file,
75                              const char* function,
76                              unsigned int line,
77                              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;
85 };
86
87 class DebugAnsiColor : public DebugBase {
88  public:
89     DebugAnsiColor();
90     virtual ~DebugAnsiColor();
91
92     virtual void debugError( const char* file,
93                              const char* function,
94                              unsigned int line,
95                              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
104  protected:
105     const char* getLevelColor( int level ) const;
106 };
107
108 class DebugHtml : public DebugBase {
109  public:
110     DebugHtml();
111     virtual ~DebugHtml();
112
113     void debugError( const char* file,
114                      const char* function,
115                      unsigned int line,
116                      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;
124
125  protected:
126     const char* getLevelColor( int level ) const;
127 };
128
129 #ifdef DEBUG
130
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 )
135
136 // XXX To change the debug module the header has to be edited
137 // which sucks big time
138 #define DECLARE_DEBUG_MODULE DebugAnsiColor m_debug
139
140 #else /* !DEBUG */
141
142 #define setDebugLevel(x)
143 #define debugError(format, args...)
144 #define debugPrint(level, format, args...)
145 #define debugPrint(level, format, args...)
146 #define debugPrintShort(level, format, args...)
147
148 #define DECLARE_DEBUG_MODULE
149
150 #endif /* DEBUG */
151
152 #endif
Note: See TracBrowser for help on using the browser.