summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp
index b4eaf2d..b2a37bc 100644
--- a/libopie2/opiecore/odebug.cpp
+++ b/libopie2/opiecore/odebug.cpp
@@ -31,193 +31,197 @@
31*/ 31*/
32 32
33// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo 33// Include this header without OPIE_NO_DEBUG defined to avoid having the oDebugInfo
34// functions inlined to noops (which would then conflict with their definition here). 34// functions inlined to noops (which would then conflict with their definition here).
35 35
36#include <opie2/odebug.h> 36#include <opie2/odebug.h>
37 37
38#ifdef OPIE_NO_DEBUG 38#ifdef OPIE_NO_DEBUG
39#undef odDebug 39#undef odDebug
40#undef odBacktrace 40#undef odBacktrace
41#endif 41#endif
42 42
43/* OPIE */ 43/* OPIE */
44 44
45#include <opie2/oapplication.h> 45#include <opie2/oapplication.h>
46#include <opie2/oglobalsettings.h> 46#include <opie2/oglobalsettings.h>
47#include <opie2/oconfig.h> 47#include <opie2/oconfig.h>
48 48
49/* QT */ 49/* QT */
50 50
51#include <qbrush.h> 51#include <qbrush.h>
52#include <qdatetime.h> 52#include <qdatetime.h>
53#include <qfile.h> 53#include <qfile.h>
54#include <qhostaddress.h> 54#include <qhostaddress.h>
55#include <qmessagebox.h> 55#include <qmessagebox.h>
56#include <qintdict.h> 56#include <qintdict.h>
57#include <qpoint.h> 57#include <qpoint.h>
58#include <qrect.h> 58#include <qrect.h>
59#include <qregion.h> 59#include <qregion.h>
60#include <qsize.h> 60#include <qsize.h>
61#include <qsocketdevice.h> 61#include <qsocketdevice.h>
62#include <qstring.h> 62#include <qstring.h>
63#include <qstringlist.h> 63#include <qstringlist.h>
64#include <qtextstream.h> 64#include <qtextstream.h>
65 65
66/* UNIX */ 66/* UNIX */
67 67
68#include <stdlib.h> // abort 68#include <stdlib.h> // abort
69#include <unistd.h> // getpid 69#include <unistd.h> // getpid
70#include <stdarg.h> // vararg stuff 70#include <stdarg.h> // vararg stuff
71#include <ctype.h> // isprint 71#include <ctype.h> // isprint
72#include <syslog.h> 72#include <syslog.h>
73#include <errno.h> 73#include <errno.h>
74#include <string.h> 74#include <string.h>
75 75
76#ifndef OPIE_NO_BACKTRACE 76#ifndef OPIE_NO_BACKTRACE
77#include <execinfo.h> 77#include <execinfo.h>
78#endif 78#endif
79 79
80 80
81/*====================================================================================== 81/*======================================================================================
82 * debug levels 82 * debug levels
83 *======================================================================================*/ 83 *======================================================================================*/
84 84
85enum DebugLevels { 85enum DebugLevels {
86 ODEBUG_INFO = 0, 86 ODEBUG_INFO = 0,
87 ODEBUG_WARN = 1, 87 ODEBUG_WARN = 1,
88 ODEBUG_ERROR = 2, 88 ODEBUG_ERROR = 2,
89 ODEBUG_FATAL = 3 89 ODEBUG_FATAL = 3
90}; 90};
91 91
92/*====================================================================================== 92/*======================================================================================
93 * oDebug private data 93 * oDebug private data
94 *======================================================================================*/ 94 *======================================================================================*/
95 95
96/*====================================================================================== 96/*======================================================================================
97 * the main debug function 97 * the main debug function
98 *======================================================================================*/ 98 *======================================================================================*/
99 99
100static void oDebugBackend( unsigned short level, unsigned int area, const char *data) 100static void oDebugBackend( unsigned short level, unsigned int area, const char *data)
101{ 101{
102 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); 102 //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data );
103 103
104 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an 104 // ML: OPIE doesn't use areacodes at the moment. See the KDE debug classes for an
105 // ML: example use. I think it's not necessary to implement such a strategy here. 105 // ML: example use. I think it's not necessary to implement such a strategy here.
106 // ML: Comments? 106 // ML: Comments?
107 107
108 int priority = 0; 108 int priority = 0;
109 QString caption; 109 QString caption;
110 QString lev; 110 QString lev;
111 switch( level ) 111 switch( level )
112 { 112 {
113 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break; 113 case ODEBUG_INFO: lev = "(Info)"; caption = "Info"; priority = LOG_INFO; break;
114 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; 114 case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break;
115 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break; 115 case ODEBUG_FATAL: lev = "(Fatal)"; caption = "Fatal Error"; priority = LOG_CRIT; break;
116 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); 116 default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." );
117 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; 117 case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break;
118 } 118 }
119 119
120 short output = OGlobalSettings::debugMode(); 120 short output = OGlobalSettings::debugMode();
121 if (!oApp && (output == 1)) 121 if (!oApp && (output == 1))
122 { 122 {
123 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); 123 qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" );
124 output = 2; // need an application object to use MsgBox 124 output = 2; // need an application object to use MsgBox
125 } 125 }
126 126
127 QString areaName = (oApp) ? oApp->appName() : "<unknown>"; 127 // gcc 2.9x is dumb and sucks... can you hear it?
128 //QString areaName = (oApp) ? oApp->appName() : "<unknown>";
129 QString areaName;
130 if ( oApp ) areaName = oApp->appName();
131 else areaName = "<unknown>";
128 132
129 // Output 133 // Output
130 switch( output ) 134 switch( output )
131 { 135 {
132 case -1: // ignore 136 case -1: // ignore
133 { 137 {
134 return; 138 return;
135 } 139 }
136 case 0: // File 140 case 0: // File
137 { 141 {
138 QString outputFilename = OGlobalSettings::debugOutput(); 142 QString outputFilename = OGlobalSettings::debugOutput();
139 143
140 const int BUFSIZE = 4096; 144 const int BUFSIZE = 4096;
141 char buf[BUFSIZE] = ""; 145 char buf[BUFSIZE] = "";
142 buf[BUFSIZE-1] = '\0'; 146 buf[BUFSIZE-1] = '\0';
143 int nSize; 147 int nSize;
144 148
145 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); 149 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data);
146 150
147 QFile outputFile( outputFilename ); 151 QFile outputFile( outputFilename );
148 if ( outputFile.open( IO_WriteOnly | IO_Append ) ) 152 if ( outputFile.open( IO_WriteOnly | IO_Append ) )
149 { 153 {
150 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) 154 if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) )
151 { 155 {
152 outputFile.writeBlock( buf, BUFSIZE-1 ); 156 outputFile.writeBlock( buf, BUFSIZE-1 );
153 } 157 }
154 else 158 else
155 { 159 {
156 outputFile.writeBlock( buf, nSize ); 160 outputFile.writeBlock( buf, nSize );
157 } 161 }
158 } 162 }
159 else 163 else
160 { 164 {
161 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); 165 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) );
162 } 166 }
163 break; 167 break;
164 } // automatic close of file here 168 } // automatic close of file here
165 169
166 case 1: // Message Box 170 case 1: // Message Box
167 { 171 {
168 // Since we are in opiecore here, we cannot use OMsgBox and use 172 // Since we are in opiecore here, we cannot use OMsgBox and use
169 // QMessageBox instead 173 // QMessageBox instead
170 174
171 caption += QString("(") + areaName + ")"; 175 caption += QString("(") + areaName + ")";
172 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? 176 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr?
173 break; 177 break;
174 } 178 }
175 179
176 case 2: // Shell 180 case 2: // Shell
177 { 181 {
178 FILE *output = stderr; 182 FILE *output = stderr;
179 fprintf( output, "%s: ", (const char*) areaName ); 183 fprintf( output, "%s: ", (const char*) areaName );
180 fputs( data, output); 184 fputs( data, output);
181 break; 185 break;
182 } 186 }
183 187
184 case 3: // syslog 188 case 3: // syslog
185 { 189 {
186 syslog( priority, "%s", data); 190 syslog( priority, "%s", data);
187 break; 191 break;
188 } 192 }
189 193
190 case 4: // socket 194 case 4: // socket
191 { 195 {
192 QString destination = OGlobalSettings::debugOutput(); 196 QString destination = OGlobalSettings::debugOutput();
193 if ( destination && destination.find(":") != -1 ) 197 if ( destination && destination.find(":") != -1 )
194 { 198 {
195 QString host = destination.left( destination.find(":") ); 199 QString host = destination.left( destination.find(":") );
196 QString port = destination.right( destination.length()-host.length()-1 ); 200 QString port = destination.right( destination.length()-host.length()-1 );
197 QHostAddress addr; 201 QHostAddress addr;
198 addr.setAddress( host ); 202 addr.setAddress( host );
199 // TODO: sanity check the address 203 // TODO: sanity check the address
200 QString line; 204 QString line;
201 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); 205 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data );
202 QSocketDevice s( QSocketDevice::Datagram ); 206 QSocketDevice s( QSocketDevice::Datagram );
203 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); 207 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() );
204 if ( result == -1 ) 208 if ( result == -1 )
205 { 209 {
206 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); 210 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) );
207 } 211 }
208 } 212 }
209 break; 213 break;
210 } 214 }
211 } 215 }
212 216
213 // check if we should abort 217 // check if we should abort
214 218
215 /* 219 /*
216 220
217 if( ( nLevel == ODEBUG_FATAL ) 221 if( ( nLevel == ODEBUG_FATAL )
218 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) 222 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) )
219 abort(); 223 abort();
220 224
221 */ 225 */
222} 226}
223 227