summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp12
-rw-r--r--libopie2/opiecore/odebug.h9
2 files changed, 14 insertions, 7 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index 3bffdd0..d8dfe26 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -100,107 +100,107 @@ struct DebugBackend {
100 void debug( unsigned short level, unsigned int, const QString& data ); 100 void debug( unsigned short level, unsigned int, const QString& data );
101 101
102private: 102private:
103 void debugFile( const QString&, const QString& data ); 103 void debugFile( const QString&, const QString& data );
104 void debugMsgB( const QString&, const QString& data ); 104 void debugMsgB( const QString&, const QString& data );
105 void debugShel( const QString&, const QString& data ); 105 void debugShel( const QString&, const QString& data );
106 void debugSysl( int, const QString& ); 106 void debugSysl( int, const QString& );
107 void debugSock( const QString&, const QString& data ); 107 void debugSock( const QString&, const QString& data );
108 QCString line( const QString&, const QString& data ); 108 QCString line( const QString&, const QString& data );
109 bool m_opened : 1; 109 bool m_opened : 1;
110 QFile *m_file; 110 QFile *m_file;
111 QHostAddress m_addr; 111 QHostAddress m_addr;
112 int m_port; 112 int m_port;
113 QSocketDevice *m_sock; 113 QSocketDevice *m_sock;
114 short m_outp; 114 short m_outp;
115}; 115};
116 116
117void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) { 117void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) {
118 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); 118 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
119 119
120 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an 120 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
121 // ML: example use. I think it's not necessary to implement such a strategy here. 121 // ML: example use. I think it's not necessary to implement such a strategy here.
122 // ML: Comments? 122 // ML: Comments?
123 123
124 int priority = 0; 124 int priority = 0;
125 QString caption; 125 QString caption;
126 QString lev; 126 QString lev;
127 switch( level ) 127 switch( level )
128 { 128 {
129 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; 129 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
130 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; 130 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
131 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; 131 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
132 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); 132 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
133 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; 133 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
134 } 134 }
135 135
136 if (!oApp && (m_outp == 1)) { 136 if (!oApp && (m_outp == 1)) {
137 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); 137 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
138 m_outp = 2; // need an application object to use MsgBox 138 m_outp = 2; // need an application object to use MsgBox
139 } 139 }
140 140
141 // gcc 2.9x is dumb and sucks... can you hear it? 141 // gcc 2.9x is dumb and sucks... can you hear it?
142 //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; 142 //QString areaName = (oApp) ? oApp->appName() : "<unknown>";
143 QString areaName; 143 QString areaName;
144 if ( oApp ) areaName = oApp->appName(); 144 if ( oApp ) areaName = oApp->appName();
145 else areaName = "<unknown>"; 145 else areaName = "<unknown>";
146 146
147 switch( m_outp ) { 147 switch( m_outp ) {
148 case -1: // ignore 148 case ODEBUG_IGNORE:
149 return; 149 return;
150 case 0: // File 150 case ODEBUG_FILE:
151 return debugFile( areaName, data ); 151 return debugFile( areaName, data );
152 case 1: // Message Box 152 case ODEBUG_MSGBOX:
153 return debugMsgB( areaName, data ); 153 return debugMsgB( areaName, data );
154 case 2: 154 case ODEBUG_STDERR:
155 return debugShel( areaName,data ); 155 return debugShel( areaName,data );
156 case 3: // syslog 156 case ODEBUG_SYSLOG:
157 return debugSysl( priority, data ); 157 return debugSysl( priority, data );
158 case 4: // socket 158 case ODEBUG_SOCKET:
159 return debugSock( areaName, data ); 159 return debugSock( areaName, data );
160 } 160 }
161} 161}
162 162
163inline void DebugBackend::debugFile(const QString& area, const QString& data) { 163inline void DebugBackend::debugFile(const QString& area, const QString& data) {
164 /* something went wrong with the file don't bother.. */ 164 /* something went wrong with the file don't bother.. */
165 if ( m_opened && !m_file ) 165 if ( m_opened && !m_file )
166 return; 166 return;
167 else if ( !m_opened ) { 167 else if ( !m_opened ) {
168 m_opened = true; 168 m_opened = true;
169 m_file = new QFile( OGlobalSettings::debugOutput() ); 169 m_file = new QFile( OGlobalSettings::debugOutput() );
170 if (!m_file->open( IO_WriteOnly | IO_Append ) ) { 170 if (!m_file->open( IO_WriteOnly | IO_Append ) ) {
171 delete m_file; m_file = 0; 171 delete m_file; m_file = 0;
172 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(), 172 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(),
173 strerror(errno) ); 173 strerror(errno) );
174 return; 174 return;
175 } 175 }
176 } 176 }
177 177
178 /* go to end of file */ 178 /* go to end of file */
179 m_file->at( m_file->size() ); 179 m_file->at( m_file->size() );
180 QCString li = line( area, data ); 180 QCString li = line( area, data );
181 m_file->writeBlock(li.data(), li.length() ); 181 m_file->writeBlock(li.data(), li.length() );
182} 182}
183 183
184void DebugBackend::debugMsgB( const QString& area, const QString& data ) { 184void DebugBackend::debugMsgB( const QString& area, const QString& data ) {
185 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") ); 185 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") );
186} 186}
187 187
188void DebugBackend::debugShel( const QString& are, const QString& data ) { 188void DebugBackend::debugShel( const QString& are, const QString& data ) {
189 FILE *output = stderr; 189 FILE *output = stderr;
190 fprintf( output, "%s: %s", are.local8Bit().data(), 190 fprintf( output, "%s: %s", are.local8Bit().data(),
191 data.local8Bit().data() ); 191 data.local8Bit().data() );
192} 192}
193 193
194void DebugBackend::debugSysl( int prio, const QString& data ) { 194void DebugBackend::debugSysl( int prio, const QString& data ) {
195 ::syslog( prio, "%s", data.local8Bit().data() ); 195 ::syslog( prio, "%s", data.local8Bit().data() );
196} 196}
197 197
198void DebugBackend::debugSock( const QString& are, const QString& data ) { 198void DebugBackend::debugSock( const QString& are, const QString& data ) {
199 if ( m_opened && !m_sock ) 199 if ( m_opened && !m_sock )
200 return; 200 return;
201 else if ( !m_opened ){ 201 else if ( !m_opened ){
202 m_opened = true; 202 m_opened = true;
203 QString destination = OGlobalSettings::debugOutput(); 203 QString destination = OGlobalSettings::debugOutput();
204 if ( destination && destination.find(":") != -1 ) { 204 if ( destination && destination.find(":") != -1 ) {
205 QString host = destination.left( destination.find(":") ); 205 QString host = destination.left( destination.find(":") );
206 m_port = destination.right( destination.length()-host.length()-1 ).toInt(); 206 m_port = destination.right( destination.length()-host.length()-1 ).toInt();
diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h
index 3851a41..21a6c26 100644
--- a/libopie2/opiecore/odebug.h
+++ b/libopie2/opiecore/odebug.h
@@ -22,96 +22,103 @@
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31*/ 31*/
32 32
33#ifndef ODEBUG_H 33#ifndef ODEBUG_H
34#define ODEBUG_H 34#define ODEBUG_H
35 35
36#include <qstring.h> 36#include <qstring.h>
37 37
38class QWidget; 38class QWidget;
39class QDateTime; 39class QDateTime;
40class QDate; 40class QDate;
41class QTime; 41class QTime;
42class QPoint; 42class QPoint;
43class QSize; 43class QSize;
44class QRect; 44class QRect;
45class QRegion; 45class QRegion;
46class QStringList; 46class QStringList;
47class QColor; 47class QColor;
48class QBrush; 48class QBrush;
49 49
50namespace Opie { 50namespace Opie {
51namespace Core { 51namespace Core {
52 52
53class odbgstream; 53class odbgstream;
54class ondbgstream; 54class ondbgstream;
55 55
56#ifdef __GNUC__ 56#ifdef __GNUC__
57#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] " 57#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
58#else 58#else
59#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] " 59#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
60#endif 60#endif
61 61
62#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] " 62#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
63 63
64#define owarn Opie::Core::odWarning() 64#define owarn Opie::Core::odWarning()
65#define oerr Opie::Core::odError() 65#define oerr Opie::Core::odError()
66#define odebug Opie::Core::odDebug() 66#define odebug Opie::Core::odDebug()
67#define ofatal Opie::Core::odFatal() 67#define ofatal Opie::Core::odFatal()
68#define oendl "\n" 68#define oendl "\n"
69 69
70const int ODEBUG_IGNORE = -1;
71const int ODEBUG_FILE = 0;
72const int ODEBUG_MSGBOX = 1;
73const int ODEBUG_STDERR = 2;
74const int ODEBUG_SYSLOG = 3;
75const int ODEBUG_SOCKET = 4;
76
70class odbgstreamprivate; 77class odbgstreamprivate;
71/** 78/**
72 * odbgstream is a text stream that allows you to print debug messages. 79 * odbgstream is a text stream that allows you to print debug messages.
73 * Using the overloaded "<<" operator you can send messages. Usually 80 * Using the overloaded "<<" operator you can send messages. Usually
74 * you do not create the odbgstream yourself, but use @ref odDebug() (odebug) 81 * you do not create the odbgstream yourself, but use @ref odDebug() (odebug)
75 * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one. 82 * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one.
76 * 83 *
77 * Example: 84 * Example:
78 * <pre> 85 * <pre>
79 * int i = 5; 86 * int i = 5;
80 * odebug << "The value of i is " << i << oendl; 87 * odebug << "The value of i is " << i << oendl;
81 * </pre> 88 * </pre>
82 * @see odbgstream 89 * @see odbgstream
83 */ 90 */
84 91
85/*====================================================================================== 92/*======================================================================================
86 * odbgstream 93 * odbgstream
87 *======================================================================================*/ 94 *======================================================================================*/
88 95
89class odbgstream 96class odbgstream
90{ 97{
91 public: 98 public:
92 /** 99 /**
93 * @internal 100 * @internal
94 */ 101 */
95 odbgstream(unsigned int _area, unsigned int _level, bool _print = true); 102 odbgstream(unsigned int _area, unsigned int _level, bool _print = true);
96 odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true); 103 odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true);
97 odbgstream(odbgstream &str); 104 odbgstream(odbgstream &str);
98 odbgstream(const odbgstream &str); 105 odbgstream(const odbgstream &str);
99 virtual ~odbgstream(); 106 virtual ~odbgstream();
100 107
101 /** 108 /**
102 * Prints the given value. 109 * Prints the given value.
103 * @param i the boolean to print (as "true" or "false") 110 * @param i the boolean to print (as "true" or "false")
104 * @return this stream 111 * @return this stream
105 */ 112 */
106 odbgstream &operator<<(bool i); 113 odbgstream &operator<<(bool i);
107 /** 114 /**
108 * Prints the given value. 115 * Prints the given value.
109 * @param i the short to print 116 * @param i the short to print
110 * @return this stream 117 * @return this stream
111 */ 118 */
112 odbgstream &operator<<(short i); 119 odbgstream &operator<<(short i);
113 /** 120 /**
114 * Prints the given value. 121 * Prints the given value.
115 * @param i the unsigned short to print 122 * @param i the unsigned short to print
116 * @return this stream 123 * @return this stream
117 */ 124 */
@@ -352,97 +359,97 @@ class ondbgstream {
352 */ 359 */
353 ondbgstream &operator<<(const char *) { return *this; } 360 ondbgstream &operator<<(const char *) { return *this; }
354 /** 361 /**
355 * Does nothing. 362 * Does nothing.
356 * @return this stream 363 * @return this stream
357 */ 364 */
358 ondbgstream& operator<<(const void *) { return *this; } 365 ondbgstream& operator<<(const void *) { return *this; }
359 /** 366 /**
360 * Does nothing. 367 * Does nothing.
361 * @return this stream 368 * @return this stream
362 */ 369 */
363 ondbgstream& operator<<(void *) { return *this; } 370 ondbgstream& operator<<(void *) { return *this; }
364 /** 371 /**
365 * Does nothing. 372 * Does nothing.
366 * @return this stream 373 * @return this stream
367 */ 374 */
368 ondbgstream& operator<<(double) { return *this; } 375 ondbgstream& operator<<(double) { return *this; }
369 /** 376 /**
370 * Does nothing. 377 * Does nothing.
371 * @return this stream 378 * @return this stream
372 */ 379 */
373 ondbgstream& operator<<(long) { return *this; } 380 ondbgstream& operator<<(long) { return *this; }
374 /** 381 /**
375 * Does nothing. 382 * Does nothing.
376 * @return this stream 383 * @return this stream
377 */ 384 */
378 ondbgstream& operator<<(unsigned long) { return *this; } 385 ondbgstream& operator<<(unsigned long) { return *this; }
379 /** 386 /**
380 * Does nothing. 387 * Does nothing.
381 * @return this stream 388 * @return this stream
382 */ 389 */
383 ondbgstream& operator << (QWidget*) { return *this; } 390 ondbgstream& operator << (QWidget*) { return *this; }
384 /** 391 /**
385 * Does nothing. 392 * Does nothing.
386 * @return this stream 393 * @return this stream
387 */ 394 */
388 ondbgstream &form(const char *, ...) { return *this; } 395 ondbgstream &form(const char *, ...) { return *this; }
389 396
390 ondbgstream& operator<<( const QDateTime& ) { return *this; } 397 ondbgstream& operator<<( const QDateTime& ) { return *this; }
391 ondbgstream& operator<<( const QDate& ) { return *this; } 398 ondbgstream& operator<<( const QDate& ) { return *this; }
392 ondbgstream& operator<<( const QTime& ) { return *this; } 399 ondbgstream& operator<<( const QTime& ) { return *this; }
393 ondbgstream& operator<<( const QPoint & ) { return *this; } 400 ondbgstream& operator<<( const QPoint & ) { return *this; }
394 ondbgstream& operator<<( const QSize & ) { return *this; } 401 ondbgstream& operator<<( const QSize & ) { return *this; }
395 ondbgstream& operator<<( const QRect & ) { return *this; } 402 ondbgstream& operator<<( const QRect & ) { return *this; }
396 ondbgstream& operator<<( const QRegion & ) { return *this; } 403 ondbgstream& operator<<( const QRegion & ) { return *this; }
397 ondbgstream& operator<<( const QStringList & ) { return *this; } 404 ondbgstream& operator<<( const QStringList & ) { return *this; }
398 ondbgstream& operator<<( const QColor & ) { return *this; } 405 ondbgstream& operator<<( const QColor & ) { return *this; }
399 ondbgstream& operator<<( const QBrush & ) { return *this; } 406 ondbgstream& operator<<( const QBrush & ) { return *this; }
400 407
401private: 408private:
402 class Private; 409 class Private;
403 Private *d; 410 Private *d;
404}; 411};
405 412
406/*====================================================================================== 413/*======================================================================================
407 * related functions 414 * related functions
408 *======================================================================================*/ 415 *======================================================================================*/
409 416
410/** 417/**
411 * Does nothing. 418 * Does nothing.
412 * @param a stream 419 * @param a stream
413 * @return the given @p s 420 * @return the given @p s
414 */ 421 */
415inline ondbgstream& endl( ondbgstream & s) { return s; } 422inline ondbgstream& endl( ondbgstream & s) { return s; }
416/** 423/**
417 * Does nothing. 424 * Does nothing.
418 * @param a stream 425 * @param a stream
419 * @return the given @p s 426 * @return the given @p s
420 */ 427 */
421inline ondbgstream& flush( ondbgstream & s) { return s; } 428inline ondbgstream& flush( ondbgstream & s) { return s; }
422inline ondbgstream& perror( ondbgstream & s) { return s; } 429inline ondbgstream& perror( ondbgstream & s) { return s; }
423 430
424/** 431/**
425 * Returns a debug stream. You can use it to print debug 432 * Returns a debug stream. You can use it to print debug
426 * information. 433 * information.
427 * @param area an id to identify the output, 0 for default 434 * @param area an id to identify the output, 0 for default
428 */ 435 */
429odbgstream odDebug(int area = 0); 436odbgstream odDebug(int area = 0);
430odbgstream odDebug(bool cond, int area = 0); 437odbgstream odDebug(bool cond, int area = 0);
431/** 438/**
432 * Returns a backtrace. 439 * Returns a backtrace.
433 * @param levels the number of levels (-1 for unlimited) of the backtrace 440 * @param levels the number of levels (-1 for unlimited) of the backtrace
434 * @return a backtrace 441 * @return a backtrace
435 */ 442 */
436QString odBacktrace(int levels = -1); 443QString odBacktrace(int levels = -1);
437/** 444/**
438 * Returns a dummy debug stream. The stream does not print anything. 445 * Returns a dummy debug stream. The stream does not print anything.
439 * @param area an id to identify the output, 0 for default 446 * @param area an id to identify the output, 0 for default
440 * @see odDebug() 447 * @see odDebug()
441 */ 448 */
442inline ondbgstream ondDebug(int = 0) { return ondbgstream(); } 449inline ondbgstream ondDebug(int = 0) { return ondbgstream(); }
443inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); } 450inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); }
444inline QString ondBacktrace() { return QString::null; } 451inline QString ondBacktrace() { return QString::null; }
445inline QString ondBacktrace(int) { return QString::null; } 452inline QString ondBacktrace(int) { return QString::null; }
446 453
447/** 454/**
448 * Returns a warning stream. You can use it to print warning 455 * Returns a warning stream. You can use it to print warning