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

List:       kde-panel-devel
Subject:    Re: [Panel-devel] dataengines and timing revisited
From:       Michael Olbrich <michael-olbrich () web ! de>
Date:       2007-09-01 7:51:00
Message-ID: 20070901075100.GA8741 () c027 ! apm ! etc ! tu-bs ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Fri, Aug 31, 2007 at 01:22:47PM -0600, Aaron J. Seigo wrote:
> On Friday 31 August 2007, Michael Olbrich wrote:
> > On Wed, Aug 29, 2007 at 08:40:58PM -0600, Aaron J. Seigo wrote:
> > >    - DataContainers are auto-removed appropriately
> >
> > This does not work right now. The problem is that disconnectNotify() is
> > only called for expicit disconnects and not when the receiver is
> > deleted. Atached is a patch that uses a different method to detect
> > unused DataContainers.
> > It also adds the actual deletion of the DataContainer. Currently the
> > memory is leaking.
> 
> it should still listen disconnectNotify events: an object may disconnect 
> without being deleted, and i don't trust that the only place that will ever 
> happen is in disconnectSource.
> 
> having to use invokeMethod (to queue the call for later) shows how ugly this 
> approach is, actually. there is the issue of items calling query() on a 
> source that isn't connected to anything else (and so gets created and then 
> just hangs out), but i'm really not very comfortable with the usage of 
> invokeMethod there.

New patch is attached. Better? Using invokeMethod is not strictly
necessary, but can avoid unnecessary deletion of the source. It
shouldn't be in any critical path though.

michael


["container-delete2.diff" (text/x-diff)]

Index: dataengine.cpp
===================================================================
--- dataengine.cpp	(revision 707200)
+++ dataengine.cpp	(working copy)
@@ -154,6 +154,7 @@
         return;
     }
 
+    connect(visualization, SIGNAL(destroyed(QObject*)), s, \
SLOT(checkUsage(QObject*)), Qt::QueuedConnection);  connect(s, \
                SIGNAL(updated(QString,Plasma::DataEngine::Data)),
             visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
     QMetaObject::invokeMethod(visualization, "updated",
@@ -171,6 +172,7 @@
 
     disconnect(s, SIGNAL(updated(QString,Plasma::DataEngine::Data)),
                visualization, SLOT(updated(QString,Plasma::DataEngine::Data)));
+    s->checkUsage(0);
 }
 
 void DataEngine::connectAllSources(QObject* visualization) const
@@ -200,7 +202,9 @@
         return DataEngine::Data();
     }
 
-    return s->data();
+    DataEngine::Data data = s->data();
+    s->checkUsage(0);
+    return data;
 }
 
 void DataEngine::startInit()
@@ -296,6 +300,7 @@
     SourceDict::iterator it = d->sources.find(source);
     if (it != d->sources.end()) {
         emit sourceRemoved(it.key());
+        it.value()->deleteLater();
         d->sources.erase(it);
     }
 }
Index: datacontainer.h
===================================================================
--- datacontainer.h	(revision 707200)
+++ datacontainer.h	(working copy)
@@ -80,6 +80,14 @@
          **/
         void checkForUpdate();
 
+    public Q_SLOTS:
+        /**
+         * Check if the DataContainer is still in use.
+         * If not the signal "unused" will be emitted.
+         * Warning: The DataContainer may be invalid after calling this function.
+         */
+        void checkUsage(QObject * obj);
+
     Q_SIGNALS:
         /**
          * Emitted when the data has been updated, allowing visualization to
@@ -93,7 +101,6 @@
         void unused(const QString& source);
 
     protected:
-        void connectNotify(const char *signal);
         void disconnectNotify(const char *signal);
 
     private:
Index: datacontainer.cpp
===================================================================
--- datacontainer.cpp	(revision 707200)
+++ datacontainer.cpp	(working copy)
@@ -33,7 +33,6 @@
         {}
 
         DataEngine::Data data;
-        int connectCount;
         bool dirty : 1;
 };
 
@@ -79,6 +78,16 @@
     d->dirty = true;
 }
 
+void DataContainer::checkUsage(QObject * obj)
+{
+    // Don't use 'obj'. It is either NULL are already deleted.
+    Q_UNUSED(obj);
+    if (receivers(SIGNAL(updated(QString, Plasma::DataEngine::Data))) < 1) {
+        // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED!
+        emit unused(objectName());
+    }
+}
+
 void DataContainer::checkForUpdate()
 {
     if (d->dirty) {
@@ -87,25 +96,9 @@
     }
 }
 
-void DataContainer::connectNotify(const char *signal)
-{
-    if (QLatin1String(signal) == \
QMetaObject::normalizedSignature(SIGNAL(updated(QString, \
                Plasma::DataEngine::Data))).constData()) {
-        ++d->connectCount;
-    }
-}
-
 void DataContainer::disconnectNotify(const char *signal)
 {
-    if (QLatin1String(signal) == \
QMetaObject::normalizedSignature(SIGNAL(updated(QString, \
                Plasma::DataEngine::Data))).constData()) {
-        if (d->connectCount > 0) {
-            --d->connectCount;
-        }
-
-        if (d->connectCount < 1) {
-            // DO NOT CALL ANYTHING AFTER THIS LINE AS IT MAY GET DELETED!
-            emit unused(objectName());
-        }
-    }
+    checkUsage(0);
 }
 
 } // Plasma namespace


["signature.asc" (application/pgp-signature)]

_______________________________________________
Panel-devel mailing list
Panel-devel@kde.org
https://mail.kde.org/mailman/listinfo/panel-devel


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

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