[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [path] litte kDebug extension
From:       Ralf Habacker <ralf.habacker () freenet ! de>
Date:       2007-09-14 7:35:48
Message-ID: 46EA39D4.6090001 () freenet ! de
[Download RAW message or body]

Olivier Goffart schrieb:
> Le mercredi 12 septembre 2007, Ralf Habacker a écrit :
>
>   
>> The use case for this functionality makes sense for KDE apps which uses
>> simply kDebug() and friend with the default area. (I have found this in
>> umbrello).
>>     
>
> This is perfectly fine for applications to use the default area (0).
> area are there for libraries, or for big application that have several parts. 
> It is used when you want to filter the part you are actually debugging.
>
> When you debug an application, you just start one per console, so the main 
> application debug area can have 0.
>   
this may be the use case for unix but not for windows. On windows all 
debug messages of *all* running gui applications are merged into one 
output and could only be displayed with DbgView.

Say I am debugging an application with kdevelop and have some other 
applications open. Kdevelop, the debuggee and all open applications will 
print its debug messages to area 0. I can only switch all or nothing 
on/off.

>   
>> Any objectivities ?
>>     
>
> (Your code is not thread safe)
>   
thanks for this pointer, i've updated the patch.

Ralf



["kdelibs-kdecore-kdebug-setdefaultarea-2.patch" (text/plain)]

Index: io/kdebug.cpp
===================================================================
--- io/kdebug.cpp	(revision 710630)
+++ io/kdebug.cpp	(working copy)
@@ -202,7 +202,7 @@
     typedef QHash<unsigned int, Area> Cache;
 
     KDebugPrivate()
-        : config(0), kDebugDBusIface(0)
+        : config(0), kDebugDBusIface(0), defaultArea(0)
     {
         Q_ASSERT(int(QtDebugMsg) == 0);
         Q_ASSERT(int(QtFatalMsg) == 3);
@@ -359,6 +359,9 @@
             loadAreaNames();
         }
 
+        if (defaultArea != 0 && num == 0)
+            num = defaultArea; 
+            
         if (!cache.contains(num))
             // unknown area
             return cache.find(0);
@@ -558,6 +561,7 @@
     KFileDebugStream filewriter;
     KMessageBoxDebugStream messageboxwriter;
     KLineEndStrippingDebugStream lineendstrippingwriter;
+    int defaultArea;
 };
 
 K_GLOBAL_STATIC(KDebugPrivate, kDebug_data)
@@ -592,6 +596,21 @@
     return QDebug(&kDebug_data->devnull);
 }
 
+void kDebugSetDefaultArea(int area)
+{
+    if (!kDebug_data) 
+        return;
+    QMutexLocker locker(&kDebug_data->mutex);
+    kDebug_data->defaultArea = area;
+}
+
+int kDebugDefaultArea()
+{
+    if (!kDebug_data) 
+        return 0;
+    return kDebug_data->defaultArea;
+}
+
 QDebug kDebugStream(QtMsgType level, int area, const char *file, int line, const char *funcinfo)
 {
     if (kDebug_data.isDestroyed()) {
Index: io/kdebug.h
===================================================================
--- io/kdebug.h	(revision 710630)
+++ io/kdebug.h	(working copy)
@@ -103,6 +103,19 @@
  */
 KDECORE_EXPORT void kClearDebugConfig();
 
+/**
+ * \relates KGlobal
+ * set the default debug area to a different value
+ * @param area an id to identify the default area for output
+ */
+KDECORE_EXPORT void kDebugSetDefaultArea(int area);
+
+/**
+ * \relates KGlobal
+ * return the currently set default debug area 
+ */
+KDECORE_EXPORT int kDebugDefaultArea();
+
 #if !defined(KDE_NO_DEBUG_OUTPUT)
 /**
  * \relates KGlobal


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic