summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.cpp229
-rw-r--r--libopie2/opiecore/oglobal.cpp9
-rw-r--r--libopie2/opiecore/oglobal.h5
3 files changed, 132 insertions, 111 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
@@ -70,10 +70,2 @@ namespace Core {
70namespace Internal { 70namespace Internal {
71class DebugBackend {
72};
73
74static DebugBackend *backEnd = 0;
75}
76static void clean_up_routine() {
77 delete Internal::backEnd;
78}
79/*====================================================================================== 71/*======================================================================================
@@ -97,4 +89,30 @@ enum DebugLevels {
97 89
98static void oDebugBackend( unsigned short level, unsigned int area, const char *data) 90
99{ 91
92struct 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
102private:
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
117void 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 );
@@ -117,7 +135,5 @@ static void oDebugBackend( unsigned short level, unsigned int area, const char *
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 }
@@ -130,83 +146,67 @@ static void oDebugBackend( unsigned short level, unsigned int area, const char *
130 146
131 // Output 147 switch( m_outp ) {
132 switch( output ) 148 case -1: // ignore
133 { 149 return;
134 case -1: // ignore 150 case 0: // File
135 { 151 return debugFile( areaName, data );
152 case 1: // Message Box
153 return debugMsgB( areaName, data );
154 case 2:
155 return debugShel( areaName,data );
156 case 3: // syslog
157 return debugSysl( priority, data );
158 case 4: // socket
159 return debugSock( areaName, data );
160 }
161}
162
163inline 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) );
136 return; 174 return;
137 } 175 }
138 case 0: // File 176 }
139 {
140 QString outputFilename = OGlobalSettings::debugOutput();
141
142 const int BUFSIZE = 4096;
143 char buf[BUFSIZE] = "";
144 buf[BUFSIZE-1] = '\0';
145 int nSize;
146
147 nSize = snprintf( buf, BUFSIZE-1, "%s: %s", (const char*) 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 }
156 else
157 {
158 outputFile.writeBlock( buf, nSize );
159 }
160 }
161 else
162 {
163 qDebug( "ODebug: can't write to file '%s' (%s)", (const char*) outputFilename, strerror(errno) );
164 }
165 break;
166 } // automatic close of file here
167
168 case 1: // Message Box
169 {
170 // Since we are in opiecore here, we cannot use OMsgBox and use
171 // QMessageBox instead
172 177
173 caption += QString("(") + areaName + ")"; 178 /* go to end of file */
174 QMessageBox::warning( 0L, caption, data, ("&OK") ); // tr? 179 m_file->at( m_file->size() );
175 break; 180 QCString li = line( area, data );
176 } 181 m_file->writeBlock(li.data(), li.length() );
182}
177 183
178 case 2: // Shell 184void DebugBackend::debugMsgB( const QString& area, const QString& data ) {
179 { 185 QMessageBox::warning( 0l, "("+area+")", data, ("Ok") );
180 FILE *output = stderr; 186}
181 fprintf( output, "%s: ", (const char*) areaName );
182 fputs( data, output);
183 break;
184 }
185 187
186 case 3: // syslog 188void DebugBackend::debugShel( const QString& are, const QString& data ) {
187 { 189 FILE *output = stderr;
188 syslog( priority, "%s", data); 190 fprintf( output, "%s: %s", are.local8Bit().data(),
189 break; 191 data.local8Bit().data() );
190 } 192}
191 193
192 case 4: // socket 194void DebugBackend::debugSysl( int prio, const QString& data ) {
193 { 195 ::syslog( prio, "%s", data.local8Bit().data() );
194 QString destination = OGlobalSettings::debugOutput(); 196}
195 if ( destination && destination.find(":") != -1 ) 197
196 { 198void DebugBackend::debugSock( const QString& are, const QString& data ) {
197 QString host = destination.left( destination.find(":") ); 199 if ( m_opened && !m_sock )
198 QString port = destination.right( destination.length()-host.length()-1 ); 200 return;
199 QHostAddress addr; 201 else if ( !m_opened ){
200 addr.setAddress( host ); 202 m_opened = true;
201 // TODO: sanity check the address 203 QString destination = OGlobalSettings::debugOutput();
202 QString line; 204 if ( destination && destination.find(":") != -1 ) {
203 line.sprintf( "%s: %s", (const char*) areaName, (const char*) data ); 205 QString host = destination.left( destination.find(":") );
204 QSocketDevice s( QSocketDevice::Datagram ); 206 m_port = destination.right( destination.length()-host.length()-1 ).toInt();
205 int result = s.writeBlock( (const char*) line, line.length(), addr, port.toInt() ); 207 m_addr.setAddress( host );
206 if ( result == -1 ) 208 m_sock = new QSocketDevice( QSocketDevice::Datagram );
207 { 209 }else{
208 qDebug( "ODebug: can't send to address '%s:%d' (%s)", (const char*) host, port.toInt(), strerror(errno) ); 210 m_sock = 0;
209 } 211 return;
210 }
211 break;
212 } 212 }
@@ -214,13 +214,22 @@ static void oDebugBackend( unsigned short level, unsigned int area, const char *
214 214
215 // check if we should abort 215 QCString li = line( are, data );
216 216 int result = m_sock->writeBlock(li.data(), li.length(), m_addr, m_port );
217 /* 217 if ( result == -1 ) {
218 218 qDebug( "ODebug: can't send to address '"+ m_addr.toString() +":%d' (%s)",
219 if( ( nLevel == ODEBUG_FATAL ) 219 m_port, strerror(errno) );
220 && ( !oDebug_data->config || oDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) ) 220 }
221 abort(); 221}
222 222
223 */ 223QCString DebugBackend::line( const QString& area, const QString& data ) {
224 QString str = area +":"+data;
225 return str.local8Bit();
224} 226}
225 227
228static DebugBackend *backEnd = 0;
229}
230static void clean_up_routine() {
231 qWarning( "Clean up Debug" );
232 delete Internal::backEnd;
233 Internal::backEnd = 0;
234}
226/*====================================================================================== 235/*======================================================================================
@@ -236,3 +245,3 @@ odbgstream odDebug(int area)
236{ 245{
237 return odbgstream(area, ODEBUG_INFO); 246 return odbgstream(area, Internal::ODEBUG_INFO);
238} 247}
@@ -240,3 +249,3 @@ 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);
@@ -246,3 +255,3 @@ odbgstream odError(int area)
246{ 255{
247 return odbgstream("ERROR: ", area, ODEBUG_ERROR); 256 return odbgstream("ERROR: ", area, Internal::ODEBUG_ERROR);
248} 257}
@@ -251,3 +260,3 @@ 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}
@@ -256,3 +265,3 @@ odbgstream odWarning(int area)
256{ 265{
257 return odbgstream("WARNING: ", area, ODEBUG_WARN); 266 return odbgstream("WARNING: ", area, Internal::ODEBUG_WARN);
258} 267}
@@ -261,3 +270,3 @@ 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}
@@ -266,3 +275,3 @@ odbgstream odFatal(int area)
266{ 275{
267 return odbgstream("FATAL: ", area, ODEBUG_FATAL); 276 return odbgstream("FATAL: ", area, Internal::ODEBUG_FATAL);
268} 277}
@@ -271,3 +280,3 @@ 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}
@@ -415,3 +424,7 @@ void odbgstream::flush()
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;
@@ -541,5 +554,4 @@ 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)
@@ -547,3 +559,2 @@ odbgstream& odbgstream::operator<<( const QRegion& reg )
547 *this <<"]"; 559 *this <<"]";
548 */
549 return *this; 560 return *this;
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
@@ -78,2 +78,10 @@ OConfig* OGlobal::_qpe_config = 0;
78 78
79void 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
79OConfig* OGlobal::config() 87OConfig* OGlobal::config()
@@ -83,2 +91,3 @@ OConfig* OGlobal::config()
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." );
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
@@ -89,3 +89,3 @@ public:
89 /** the content of TEMP 89 /** the content of TEMP
90 * reads the environment variable TEMP and returns the content. 90 * reads the environment variable TEMP and returns the content.
91 * if not set returns "/tmp" 91 * if not set returns "/tmp"
@@ -95,3 +95,3 @@ public:
95 /** the content of HOME 95 /** the content of HOME
96 * reads the environment variable HOME and returns the content. 96 * reads the environment variable HOME and returns the content.
97 * if not set returns "/" 97 * if not set returns "/"
@@ -151,2 +151,3 @@ public:
151private: 151private:
152 static void clean_up();
152 static OConfig* _config; 153 static OConfig* _config;