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 |
#define DEBUG_LEVEL_SCHEDULER (1<<6) |
---|
36 |
|
---|
37 |
// convenience defines |
---|
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 ) |
---|
53 |
|
---|
54 |
unsigned char toAscii( unsigned char c ); |
---|
55 |
void quadlet2char( quadlet_t quadlet, unsigned char* buff ); |
---|
56 |
void hexDump( unsigned char *data_start, unsigned int length ); |
---|
57 |
|
---|
58 |
class DebugBase { |
---|
59 |
public: |
---|
60 |
DebugBase(); |
---|
61 |
virtual ~DebugBase(); |
---|
62 |
|
---|
63 |
void setLevel( int level ) |
---|
64 |
{ m_level = level; } |
---|
65 |
|
---|
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, |
---|
76 |
const char* format, ... ) const = 0; |
---|
77 |
|
---|
78 |
protected: |
---|
79 |
int m_level; |
---|
80 |
}; |
---|
81 |
|
---|
82 |
class DebugStandard : public DebugBase { |
---|
83 |
public: |
---|
84 |
DebugStandard(); |
---|
85 |
virtual ~DebugStandard(); |
---|
86 |
|
---|
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, |
---|
97 |
const char* format, ... ) const; |
---|
98 |
}; |
---|
99 |
|
---|
100 |
class DebugAnsiColor : public DebugBase { |
---|
101 |
public: |
---|
102 |
DebugAnsiColor(); |
---|
103 |
virtual ~DebugAnsiColor(); |
---|
104 |
|
---|
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, |
---|
115 |
const char* format, ... ) const; |
---|
116 |
|
---|
117 |
protected: |
---|
118 |
const char* getLevelColor( int level ) const; |
---|
119 |
}; |
---|
120 |
|
---|
121 |
class DebugHtml : public DebugBase { |
---|
122 |
public: |
---|
123 |
DebugHtml(); |
---|
124 |
virtual ~DebugHtml(); |
---|
125 |
|
---|
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, |
---|
136 |
const char* format, ... ) const; |
---|
137 |
|
---|
138 |
protected: |
---|
139 |
const char* getLevelColor( int level ) const; |
---|
140 |
}; |
---|
141 |
|
---|
142 |
#ifdef DEBUG |
---|
143 |
|
---|
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 ) |
---|
153 |
|
---|
154 |
// XXX To change the debug module the header has to be edited |
---|
155 |
// which sucks big time |
---|
156 |
#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 |
---|
161 |
|
---|
162 |
#else /* !DEBUG */ |
---|
163 |
|
---|
164 |
#define setDebugLevel(x) |
---|
165 |
#define debugError(format, args...) |
---|
166 |
#define debugPrint(level, format, args...) |
---|
167 |
#define debugPrint(level, format, args...) |
---|
168 |
#define debugPrintShort(level, format, args...) |
---|
169 |
|
---|
170 |
#define DECLARE_DEBUG_MODULE |
---|
171 |
|
---|
172 |
#endif /* DEBUG */ |
---|
173 |
|
---|
174 |
#endif |
---|