File: debug.h

package info (click to toggle)
raidutils 0.0.6-23
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,840 kB
  • sloc: cpp: 39,794; ansic: 22,774; sh: 8,306; makefile: 19
file content (224 lines) | stat: -rw-r--r-- 6,399 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* Copyright (c) 1996-2004, Adaptec Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name of the Adaptec Corporation nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __DEBUG_H
#define __DEBUG_H

#include "osd_defs.h"

#ifndef _DPT_NETWARE
#if HAVE_FSTREAM
# include <fstream>
#else
# if HAVE_FSTREAM_H
#  include <fstream.h>
# endif
#endif
#if HAVE_IOSTREAM
# include <iostream>
#else
# if HAVE_IOSTREAM_H
#  include <iostream.h>
# endif
#endif
#if HAVE_IOMANIP
# include <iomanip>
#else
# if HAVE_IOMANIP_H
#  include <iomanip.h>
# endif
#endif
#include <string.h>
#include <stdio.h>
#endif


//#if defined(_DPT_ERGO) || defined (_DPT_NETWARE) || defined (_DPT_WIN_3X) || defined (_DPT_REAL)
#define SNI_DEBUG 0
//#else
//#define SNI_DEBUG 1
//#endif

#if SNI_DEBUG == 0

#       define DEBUG_ON
#       define DEBUG_OFF
#       define DEBUG_SETLEVEL(x)
#       define DEBUG_SETOUTPUT(x)
#       define DEBUG_BEGIN(lev,meth)
#       define DEBUG(l,x)
#       define DEBUG1(l,X)
#       define DEBUG2(l,X1,X2)
#       define DEBUG3(l,X1,X2,X3)

#else

//==================================================================
#define DEBUG_ON                Debug::SetDebugLevel(10)
#define DEBUG_OFF               Debug::SetDebugLevel(0)

#define DEBUG_SETLEVEL(x)       Debug::SetDebugLevel(x)
#define DEBUG_SETOUTPUT(x)      Debug::SetOutPut(x)

#define DEBUG_BEGIN(level,meth) Debug debug(#meth,level)

#define DEBUG(level,x)                          \
	debug.SetLocalLevel(level);             \
	debug << dec                            \
	<< "<" << __FILE__ << ' ' << __LINE__   \
	<< "> " << x << endl

#define DEBUG1(level,X)                         \
	debug.SetLocalLevel(level);             \
	debug << dec                            \
	<< "<" << __FILE__ << ' ' << __LINE__   \
	<< "> "#X"=" << X << endl

#define DEBUG2(level,X1,X2)                     \
	debug.SetLocalLevel(level);             \
	debug << dec                            \
	<< "<" << __FILE__ << ' ' << __LINE__   \
	<< "> "#X1"=" << X1 << "  "#X2"=" << X2 << endl

#define DEBUG3(level,X1,X2,X3)                  \
	debug.SetLocalLevel(level);             \
	debug << dec                            \
	<< "<" << __FILE__ << ' ' << __LINE__   \
	<< "> "#X1"=" << X1                     \
	<< "  "#X2"=" << X2                     \
	<< "  "#X3"=" << X3 << endl


//==================================================================
#define LSH(X) Debug &operator<<(X x) \
{  if (level < Debug::debugLevel ) \
	*Debug::ost << x; \
    return *this; \
}

typedef ostream &(*OMANI) (ostream &);
typedef ios     &(*SMANI) (ios &);
typedef ios     &(*SMANI) (ios &);

class Debug
{
public: //----------------------------------------------------------------
    Debug(const char *method=NULL, const int nl=0);
    ~Debug(void);

    LSH(int);
    LSH(unsigned int);
    LSH(short);
    LSH(unsigned short);
    LSH(long);
    LSH(unsigned long);
    LSH(float);
    LSH(double);
    LSH(char);
    LSH(unsigned char);
    LSH(void *);
    LSH(const char *);
    LSH(OMANI);
    LSH(SMANI);
    LSH(streambuf *);
#if (!defined(_DPT_SOLARIS) && !defined(_DPT_OS2) && !defined(_DPT_BSDI) && !defined(_DPT_FREE_BSD) && !defined(_DPT_LINUX))
    LSH(const SMANIP(int) &);
    LSH(const SMANIP(long) &);
#endif

    ostream *operator   ->()    { return Debug::ost; };
	    operator void*()    { return (void *)Debug::ost; };
    int     operator    !()     { return ! *Debug::ost; };

	int     GetLocalLevel   (void)          { return level; };
	void    SetLocalLevel   (const int &nl) { level = nl; };

static  void    SetDebugLevel   (const int &nl) ;
static  int     GetDebugLevel   (void)          { return Debug::debugLevel; };
static  void    SetOutPut       (ostream &post) { Debug::ost = &post; };
static  void    SetOutPut       (ostream *post) { Debug::ost = post; };

private: //-----------------------------------------------------------------
		char    method_[128];
	int     level;
	int     printEnd;

static  int     debugLevel;
static  ostream *ost;
static  Debug   out;
static  int     count;

};


inline
Debug::Debug(const char *meth, const int nl) : level(nl), printEnd(0)
{
    if (meth != NULL) {
	sprintf(method_, "BEGIN %d: %s",count ,meth);
	if ( level < Debug::debugLevel) {
	    printEnd = 1;
	    Debug::out << dec << '\n' << method_  << "-----------------";
	    Debug::out << " global debug level = " << Debug::debugLevel;
	    Debug::out << endl;
	}
	count++;
    } else
	method_[0] = '\0';
}

inline
Debug::~Debug(void)
{
    if (method_[0] != '\0') {
	count--;
	memcpy(method_, "END  ", 5);
	if ( printEnd ) {
	    *Debug::ost << dec <<  method_  << "-----------------" << endl;
	}

	Debug::ost->flush();
    }
}


inline
void  Debug::SetDebugLevel(const int &nl)
{
    if (nl != Debug::debugLevel) {
	Debug::debugLevel = nl;
#ifdef SNI_MIPS
	*Debug::ost << dec;
	*Debug::ost << "new global debug level = " << Debug::debugLevel;
	*Debug::ost << endl;
#endif
    }
}
#endif
#endif