author | zecke <zecke> | 2004-04-04 23:14:28 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-04 23:14:28 (UTC) |
commit | 76a3fc46db5f097262d3cda9df49d757e96e660c (patch) (unidiff) | |
tree | e9f255a0561809e40626a9576bb77a6f86622b09 | |
parent | 4068b42526afa8da95f1299c7f8f5f10081ae4b0 (diff) | |
download | opie-76a3fc46db5f097262d3cda9df49d757e96e660c.zip opie-76a3fc46db5f097262d3cda9df49d757e96e660c.tar.gz opie-76a3fc46db5f097262d3cda9df49d757e96e660c.tar.bz2 |
Add Postroutines which seem to not work...
Create a Debug Backend on first invocation. Sad thing is we still need
to get reconfiguration of the settings.. OpieConfigXT is needed
-rw-r--r-- | libopie2/opiecore/odebug.cpp | 203 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.cpp | 9 | ||||
-rw-r--r-- | libopie2/opiecore/oglobal.h | 1 |
3 files changed, 117 insertions, 96 deletions
diff --git a/libopie2/opiecore/odebug.cpp b/libopie2/opiecore/odebug.cpp index f258faa..3bffdd0 100644 --- a/libopie2/opiecore/odebug.cpp +++ b/libopie2/opiecore/odebug.cpp | |||
@@ -65,20 +65,12 @@ | |||
65 | #include <execinfo.h> | 65 | #include <execinfo.h> |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | namespace Opie { | 68 | namespace Opie { |
69 | namespace Core { | 69 | namespace Core { |
70 | namespace Internal { | 70 | namespace Internal { |
71 | class DebugBackend { | ||
72 | }; | ||
73 | |||
74 | static DebugBackend *backEnd = 0; | ||
75 | } | ||
76 | static void clean_up_routine() { | ||
77 | delete Internal::backEnd; | ||
78 | } | ||
79 | /*====================================================================================== | 71 | /*====================================================================================== |
80 | * debug levels | 72 | * debug levels |
81 | *======================================================================================*/ | 73 | *======================================================================================*/ |
82 | 74 | ||
83 | enum DebugLevels { | 75 | enum DebugLevels { |
84 | ODEBUG_INFO = 0, | 76 | ODEBUG_INFO = 0, |
@@ -92,14 +84,40 @@ enum DebugLevels { | |||
92 | *======================================================================================*/ | 84 | *======================================================================================*/ |
93 | 85 | ||
94 | /*====================================================================================== | 86 | /*====================================================================================== |
95 | * the main debug function | 87 | * the main debug function |
96 | *======================================================================================*/ | 88 | *======================================================================================*/ |
97 | 89 | ||
98 | static void oDebugBackend( unsigned short level, unsigned int area, const char *data) | 90 | |
99 | { | 91 | |
92 | struct DebugBackend { | ||
93 | DebugBackend() : m_opened( false ), m_file( 0 ) ,m_port( -1 ),m_sock( 0 ) { | ||
94 | m_outp = OGlobalSettings::debugMode(); | ||
95 | } | ||
96 | ~DebugBackend() { | ||
97 | delete m_file; | ||
98 | delete m_sock; | ||
99 | } | ||
100 | void debug( unsigned short level, unsigned int, const QString& data ); | ||
101 | |||
102 | private: | ||
103 | void debugFile( const QString&, const QString& data ); | ||
104 | void debugMsgB( const QString&, const QString& data ); | ||
105 | void debugShel( const QString&, const QString& data ); | ||
106 | void debugSysl( int, const QString& ); | ||
107 | void debugSock( const QString&, const QString& data ); | ||
108 | QCString line( const QString&, const QString& data ); | ||
109 | bool m_opened : 1; | ||
110 | QFile *m_file; | ||
111 | QHostAddress m_addr; | ||
112 | int m_port; | ||
113 | QSocketDevice *m_sock; | ||
114 | short m_outp; | ||
115 | }; | ||
116 | |||
117 | void DebugBackend::debug(unsigned short level, unsigned int, const QString& data) { | ||
100 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); | 118 | //qDebug( "oDebugBackend: Level=%d, Area=%d, Data=%s", level, area, data ); |
101 | 119 | ||
102 | // 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 |
103 | // 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. |
104 | // ML: Comments? | 122 | // ML: Comments? |
105 | 123 | ||
@@ -112,167 +130,158 @@ static void oDebugBackend( unsigned short level, unsigned int area, const char * | |||
112 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; | 130 | case ODEBUG_WARN: lev = "(Warn)"; caption = "Warning"; priority = LOG_WARNING; break; |
113 | 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; |
114 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); | 132 | default: qDebug( "oDebugBackend: Warning: Unknown debug level! - defaulting to ODEBUG_ERROR." ); |
115 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; | 133 | case ODEBUG_ERROR: lev = "(Error)"; caption = "Error"; priority = LOG_ERR; break; |
116 | } | 134 | } |
117 | 135 | ||
118 | short output = OGlobalSettings::debugMode(); | 136 | if (!oApp && (m_outp == 1)) { |
119 | if (!oApp && (output == 1)) | ||
120 | { | ||
121 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); | 137 | qDebug( "oDebugBackend: Warning: no oapplication object - can't use MsgBox" ); |
122 | output = 2; // need an application object to use MsgBox | 138 | m_outp = 2; // need an application object to use MsgBox |
123 | } | 139 | } |
124 | 140 | ||
125 | // gcc 2.9x is dumb and sucks... can you hear it? | 141 | // gcc 2.9x is dumb and sucks... can you hear it? |
126 | //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; | 142 | //QString areaName = (oApp) ? oApp->appName() : "<unknown>"; |
127 | QString areaName; | 143 | QString areaName; |
128 | if ( oApp ) areaName = oApp->appName(); | 144 | if ( oApp ) areaName = oApp->appName(); |
129 | else areaName = "<unknown>"; | 145 | else areaName = "<unknown>"; |
130 | 146 | ||
131 | // Output | 147 | switch( m_outp ) { |
132 | switch( output ) | ||
133 | { | ||
134 | case -1: // ignore | 148 | case -1: // ignore |
135 | { | ||
136 | return; | 149 | return; |
137 | } | ||
138 | case 0: // File | 150 | case 0: // File |
139 | { | 151 | return debugFile( areaName, data ); |
140 | QString outputFilename = OGlobalSettings::debugOutput(); | 152 | case 1: // Message Box |
141 | 153 | return debugMsgB( areaName, data ); | |
142 | const int BUFSIZE = 4096; | 154 | case 2: |
143 | char buf[BUFSIZE] = ""; | 155 | return debugShel( areaName,data ); |
144 | buf[BUFSIZE-1] = '\0'; | 156 | case 3: // syslog |
145 | int nSize; | 157 | return debugSysl( priority, data ); |
146 | 158 | case 4: // socket | |
147 | nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) areaName, data); | 159 | return debugSock( areaName, data ); |
148 | |||
149 | QFile outputFile( outputFilename ); | ||
150 | if ( outputFile.open( IO_WriteOnly | IO_Append ) ) | ||
151 | { | ||
152 | if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) | ||
153 | { | ||
154 | outputFile.writeBlock( buf, BUFSIZE-1 ); | ||
155 | } | 160 | } |
156 | else | ||
157 | { | ||
158 | outputFile.writeBlock( buf, nSize ); | ||
159 | } | 161 | } |
162 | |||
163 | inline void DebugBackend::debugFile(const QString& area, const QString& data) { | ||
164 | /* something went wrong with the file don't bother.. */ | ||
165 | if ( m_opened && !m_file ) | ||
166 | return; | ||
167 | else if ( !m_opened ) { | ||
168 | m_opened = true; | ||
169 | m_file = new QFile( OGlobalSettings::debugOutput() ); | ||
170 | if (!m_file->open( IO_WriteOnly | IO_Append ) ) { | ||
171 | delete m_file; m_file = 0; | ||
172 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*)OGlobalSettings::debugOutput(), | ||
173 | strerror(errno) ); | ||
174 | return; | ||
160 | } | 175 | } |
161 | else | ||
162 | { | ||
163 | qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) ); | ||
164 | } | 176 | } |
165 | break; | ||
166 | } // automatic close of file here | ||
167 | 177 | ||
168 | case 1: // Message Box | 178 | /* go to end of file */ |
169 | { | 179 | m_file->at( m_file->size() ); |
170 | // Since we are in opiecore here, we cannot use OMsgBox and use | 180 | QCString li = line( area, data ); |
171 | // QMessageBox instead | 181 | m_file->writeBlock(li.data(), li.length() ); |
182 | } | ||
172 | 183 | ||
173 | caption += QString("(") + areaName + ")"; | 184 | void DebugBackend::debugMsgB( const QString& area, const QString& data ) { |
174 | QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? | 185 | QMessageBox::warning( 0l, "("+area+")", data, ("Ok") ); |
175 | break; | ||
176 | } | 186 | } |
177 | 187 | ||
178 | case 2: // Shell | 188 | void DebugBackend::debugShel( const QString& are, const QString& data ) { |
179 | { | ||
180 | FILE *output = stderr; | 189 | FILE *output = stderr; |
181 | fprintf( output, "%s: ", (const char*) areaName ); | 190 | fprintf( output, "%s: %s", are.local8Bit().data(), |
182 | fputs( data, output); | 191 | data.local8Bit().data() ); |
183 | break; | ||
184 | } | 192 | } |
185 | 193 | ||
186 | case 3: // syslog | 194 | void DebugBackend::debugSysl( int prio, const QString& data ) { |
187 | { | 195 | ::syslog( prio, "%s", data.local8Bit().data() ); |
188 | syslog( priority, "%s", data); | ||
189 | break; | ||
190 | } | 196 | } |
191 | 197 | ||
192 | case 4: // socket | 198 | void DebugBackend::debugSock( const QString& are, const QString& data ) { |
193 | { | 199 | if ( m_opened && !m_sock ) |
200 | return; | ||
201 | else if ( !m_opened ){ | ||
202 | m_opened = true; | ||
194 | QString destination = OGlobalSettings::debugOutput(); | 203 | QString destination = OGlobalSettings::debugOutput(); |
195 | if ( destination && destination.find(":") != -1 ) | 204 | if ( destination && destination.find(":") != -1 ) { |
196 | { | ||
197 | QString host = destination.left( destination.find(":") ); | 205 | QString host = destination.left( destination.find(":") ); |
198 | QString port = destination.right( destination.length()-host.length()-1 ); | 206 | m_port = destination.right( destination.length()-host.length()-1 ).toInt(); |
199 | QHostAddress addr; | 207 | m_addr.setAddress( host ); |
200 | addr.setAddress( host ); | 208 | m_sock = new QSocketDevice( QSocketDevice::Datagram ); |
201 | // TODO: sanity check the address | 209 | }else{ |
202 | QString line; | 210 | m_sock = 0; |
203 | line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); | 211 | return; |
204 | QSocketDevice s( QSocketDevice::Datagram ); | ||
205 | int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); | ||
206 | if ( result == -1 ) | ||
207 | { | ||
208 | qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); | ||
209 | } | 212 | } |
210 | } | 213 | } |
211 | break; | 214 | |
215 | QCString li = line( are, data ); | ||
216 | int result = m_sock->writeBlock(li.data(), li.length(), m_addr, m_port ); | ||
217 | if ( result == -1 ) { | ||
218 | qDebug( "ODebug: can't send to address '"+ m_addr.toString() +":%d' (%s)", | ||
219 | m_port, strerror(errno) ); | ||
212 | } | 220 | } |
213 | } | 221 | } |
214 | 222 | ||
215 | // check if we should abort | 223 | QCString DebugBackend::line( const QString& area, const QString& data ) { |
216 | 224 | QString str = area +":"+data; | |
217 | /* | 225 | return str.local8Bit(); |
218 | |||
219 | if( ( nLevel == ODEBUG_FATAL ) | ||
220 | && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) | ||
221 | abort(); | ||
222 | |||
223 | */ | ||
224 | } | 226 | } |
225 | 227 | ||
228 | static DebugBackend *backEnd = 0; | ||
229 | } | ||
230 | static void clean_up_routine() { | ||
231 | qWarning( "Clean up Debug" ); | ||
232 | delete Internal::backEnd; | ||
233 | Internal::backEnd = 0; | ||
234 | } | ||
226 | /*====================================================================================== | 235 | /*====================================================================================== |
227 | * odbgstream | 236 | * odbgstream |
228 | *======================================================================================*/ | 237 | *======================================================================================*/ |
229 | 238 | ||
230 | odbgstream& perror( odbgstream &s) | 239 | odbgstream& perror( odbgstream &s) |
231 | { | 240 | { |
232 | return s << QString::fromLocal8Bit(strerror(errno)); | 241 | return s << QString::fromLocal8Bit(strerror(errno)); |
233 | } | 242 | } |
234 | 243 | ||
235 | odbgstream odDebug(int area) | 244 | odbgstream odDebug(int area) |
236 | { | 245 | { |
237 | return odbgstream(area, ODEBUG_INFO); | 246 | return odbgstream(area, Internal::ODEBUG_INFO); |
238 | } | 247 | } |
239 | odbgstream odDebug(bool cond, int area) | 248 | odbgstream odDebug(bool cond, int area) |
240 | { | 249 | { |
241 | if (cond) return odbgstream(area, ODEBUG_INFO); | 250 | if (cond) return odbgstream(area, Internal::ODEBUG_INFO); |
242 | else return odbgstream(0, 0, false); | 251 | else return odbgstream(0, 0, false); |
243 | } | 252 | } |
244 | 253 | ||
245 | odbgstream odError(int area) | 254 | odbgstream odError(int area) |
246 | { | 255 | { |
247 | return odbgstream("ERROR: ", area, ODEBUG_ERROR); | 256 | return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); |
248 | } | 257 | } |
249 | 258 | ||
250 | odbgstream odError(bool cond, int area) | 259 | odbgstream odError(bool cond, int area) |
251 | { | 260 | { |
252 | if (cond) return odbgstream("ERROR: ", area, ODEBUG_ERROR); else return odbgstream(0,0,false); | 261 | if (cond) return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR); else return odbgstream(0,0,false); |
253 | } | 262 | } |
254 | 263 | ||
255 | odbgstream odWarning(int area) | 264 | odbgstream odWarning(int area) |
256 | { | 265 | { |
257 | return odbgstream("WARNING: ", area, ODEBUG_WARN); | 266 | return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); |
258 | } | 267 | } |
259 | 268 | ||
260 | odbgstream odWarning(bool cond, int area) | 269 | odbgstream odWarning(bool cond, int area) |
261 | { | 270 | { |
262 | if (cond) return odbgstream("WARNING: ", area, ODEBUG_WARN); else return odbgstream(0,0,false); | 271 | if (cond) return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN); else return odbgstream(0,0,false); |
263 | } | 272 | } |
264 | 273 | ||
265 | odbgstream odFatal(int area) | 274 | odbgstream odFatal(int area) |
266 | { | 275 | { |
267 | return odbgstream("FATAL: ", area, ODEBUG_FATAL); | 276 | return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); |
268 | } | 277 | } |
269 | 278 | ||
270 | odbgstream odFatal(bool cond, int area) | 279 | odbgstream odFatal(bool cond, int area) |
271 | { | 280 | { |
272 | if (cond) return odbgstream("FATAL: ", area, ODEBUG_FATAL); else return odbgstream(0,0,false); | 281 | if (cond) return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL); else return odbgstream(0,0,false); |
273 | } | 282 | } |
274 | 283 | ||
275 | odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) | 284 | odbgstream::odbgstream(unsigned int _area, unsigned int _level, bool _print) |
276 | :area(_area), level(_level), print(_print) | 285 | :area(_area), level(_level), print(_print) |
277 | { | 286 | { |
278 | } | 287 | } |
@@ -410,13 +419,17 @@ void odbgstream::flush() | |||
410 | if ( output.isEmpty() || !print ) | 419 | if ( output.isEmpty() || !print ) |
411 | { | 420 | { |
412 | return; | 421 | return; |
413 | } | 422 | } |
414 | else | 423 | else |
415 | { | 424 | { |
416 | oDebugBackend( level, area, output.local8Bit().data() ); | 425 | if ( !Internal::backEnd ) { |
426 | Internal::backEnd = new Internal::DebugBackend; | ||
427 | qAddPostRoutine( clean_up_routine ); | ||
428 | } | ||
429 | Internal::backEnd->debug( level, area, output ); | ||
417 | output = QString::null; | 430 | output = QString::null; |
418 | } | 431 | } |
419 | } | 432 | } |
420 | 433 | ||
421 | odbgstream& odbgstream::form(const char *format, ...) | 434 | odbgstream& odbgstream::form(const char *format, ...) |
422 | { | 435 | { |
@@ -536,19 +549,17 @@ odbgstream& odbgstream::operator<<( const QRect& r ) | |||
536 | return *this; | 549 | return *this; |
537 | } | 550 | } |
538 | 551 | ||
539 | 552 | ||
540 | odbgstream& odbgstream::operator<<( const QRegion& reg ) | 553 | odbgstream& odbgstream::operator<<( const QRegion& reg ) |
541 | { | 554 | { |
542 | /* Qt2 doesn't have a QMemArray... :( | ||
543 | *this << "[ "; | 555 | *this << "[ "; |
544 | QMemArray<QRect>rs=reg.rects(); | 556 | QArray<QRect>rs=reg.rects(); |
545 | for (uint i=0;i<rs.size();++i) | 557 | for (uint i=0;i<rs.size();++i) |
546 | *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; | 558 | *this << QString("[%1, %2 - %3, %4] ").arg(rs[i].left()).arg(rs[i].top()).arg(rs[i].right()).arg(rs[i].bottom() ) ; |
547 | *this <<"]"; | 559 | *this <<"]"; |
548 | */ | ||
549 | return *this; | 560 | return *this; |
550 | } | 561 | } |
551 | 562 | ||
552 | 563 | ||
553 | odbgstream& odbgstream::operator<<( const QStringList& l ) | 564 | odbgstream& odbgstream::operator<<( const QStringList& l ) |
554 | { | 565 | { |
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp index ea02058..2968a7d 100644 --- a/libopie2/opiecore/oglobal.cpp +++ b/libopie2/opiecore/oglobal.cpp | |||
@@ -73,17 +73,26 @@ static char Base64DecMap[128] = | |||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
76 | OConfig* OGlobal::_config = 0; | 76 | OConfig* OGlobal::_config = 0; |
77 | OConfig* OGlobal::_qpe_config = 0; | 77 | OConfig* OGlobal::_qpe_config = 0; |
78 | 78 | ||
79 | void OGlobal::clean_up() { | ||
80 | qWarning( "Oglobal clean up" ); | ||
81 | delete OGlobal::_config; | ||
82 | delete OGlobal::_qpe_config; | ||
83 | OGlobal::_config = 0; | ||
84 | OGlobal::_qpe_config = 0; | ||
85 | } | ||
86 | |||
79 | OConfig* OGlobal::config() | 87 | OConfig* OGlobal::config() |
80 | { | 88 | { |
81 | if ( !OGlobal::_config ) | 89 | if ( !OGlobal::_config ) |
82 | { | 90 | { |
83 | // odebug classes are reading config, so can't use them here! | 91 | // odebug classes are reading config, so can't use them here! |
92 | qAddPostRoutine( OGlobal::clean_up ); | ||
84 | qDebug( "OGlobal::creating global configuration instance." ); | 93 | qDebug( "OGlobal::creating global configuration instance." ); |
85 | OGlobal::_config = new OConfig( "global" ); | 94 | OGlobal::_config = new OConfig( "global" ); |
86 | } | 95 | } |
87 | return OGlobal::_config; | 96 | return OGlobal::_config; |
88 | } | 97 | } |
89 | 98 | ||
diff --git a/libopie2/opiecore/oglobal.h b/libopie2/opiecore/oglobal.h index e6a6c46..d79a218 100644 --- a/libopie2/opiecore/oglobal.h +++ b/libopie2/opiecore/oglobal.h | |||
@@ -146,12 +146,13 @@ public: | |||
146 | //@{ | 146 | //@{ |
147 | static Global::Command* builtinCommands(); | 147 | static Global::Command* builtinCommands(); |
148 | static QGuardedPtr<QWidget>* builtinRunning(); | 148 | static QGuardedPtr<QWidget>* builtinRunning(); |
149 | //@} | 149 | //@} |
150 | 150 | ||
151 | private: | 151 | private: |
152 | static void clean_up(); | ||
152 | static OConfig* _config; | 153 | static OConfig* _config; |
153 | static OConfig* _qpe_config; | 154 | static OConfig* _qpe_config; |
154 | class Private; | 155 | class Private; |
155 | Private *d; | 156 | Private *d; |
156 | }; | 157 | }; |
157 | } | 158 | } |