[Kde-hardware-devel] KDE/kdelibs/solid/solid/backends/hal

Aaron J. Seigo aseigo at kde.org
Wed Nov 25 21:44:22 CET 2009


SVN commit 1054295 by aseigo:

if a property changes, don't invalidate the whole cache until we actually care about that item. this allows us to keep the cache hot when something irrelevant (to us) is changing behind our backs, resulting in even fewer dbus trips in those situations
CCMAIL:kde-hardware-devel at kde.org


 M  +39 -18    haldevice.cpp  


--- trunk/KDE/kdelibs/solid/solid/backends/hal/haldevice.cpp #1054294:1054295
@@ -105,10 +105,12 @@
                   "org.freedesktop.Hal.Device",
                   QDBusConnection::systemBus()),
           cacheSynced(false), parent(0) { }
+    void checkCache(const QString &key = QString());
 
     QDBusInterface device;
     QMap<QString,QVariant> cache;
     QMap<Solid::DeviceInterface::Type, bool> capListCache;
+    QSet<QString> invalidKeys;
 
     bool cacheSynced;
     HalDevice *parent;
@@ -348,33 +350,47 @@
 
 QVariant HalDevice::property(const QString &key) const
 {
-    return allProperties().value(key);
+    d->checkCache(key);
+    return d->cache.value(key);
 }
 
-QMap<QString, QVariant> HalDevice::allProperties() const
+void HalDevicePrivate::checkCache(const QString &key)
 {
-    if (!d->cacheSynced)
-    {
-        QDBusReply<QVariantMap> reply = d->device.call("GetAllProperties");
-
-        if (reply.isValid()) {
-            d->cache = reply;
-        } else {
-            qWarning() << Q_FUNC_INFO << " error: " << reply.error().name()
-                << ", " << reply.error().message() << endl;
-            d->cache = QVariantMap();
+    if (cacheSynced) {
+        if (key.isEmpty()) {
+            if (invalidKeys.isEmpty()) {
+                return;
+            }
+        } else if (!invalidKeys.contains(key)) {
+            return;
         }
+    }
 
-        d->cacheSynced = true;
-        //qDebug( )<< this << udi() << "failure";
+    QDBusReply<QVariantMap> reply = device.call("GetAllProperties");
+
+    if (reply.isValid()) {
+        cache = reply;
+    } else {
+        qWarning() << Q_FUNC_INFO << " error: " << reply.error().name()
+            << ", " << reply.error().message() << endl;
+        cache = QVariantMap();
     }
 
+    invalidKeys.clear();
+    cacheSynced = true;
+    //qDebug( )<< q << udi() << "failure";
+}
+
+QMap<QString, QVariant> HalDevice::allProperties() const
+{
+    d->checkCache();
     return d->cache;
 }
 
 bool HalDevice::propertyExists(const QString &key) const
 {
-    return allProperties().value(key).isValid();
+    d->checkCache(key);
+    return d->cache.value(key).isValid();
 }
 
 bool HalDevice::queryDeviceInterface(const Solid::DeviceInterface::Type &type) const
@@ -506,12 +522,17 @@
         }
 
         result[key] = type;
+        d->cache.remove(key);
+
+        if (d->cache.isEmpty()) {
+            d->cacheSynced = false;
+            d->invalidKeys.clear();
+        } else {
+            d->invalidKeys.insert(key);
+        }
     }
 
-    d->cache.clear();
     //qDebug() << this << "unsyncing the cache";
-    d->cacheSynced = false;
-
     emit propertyChanged(result);
 }
 


More information about the Kde-hardware-devel mailing list