Browse Source

Merge branch 'service-tracker-tests'

* service-tracker-tests:
  Fixed recursive mutex lock.
Sascha Zelzer 13 years ago
parent
commit
99f169a7fe

+ 4 - 4
Libs/PluginFramework/ctkPluginFrameworkListeners.cpp

@@ -100,7 +100,7 @@ void ctkPluginFrameworkListeners::serviceListenerDestroyed(QObject *listener)
 
 //----------------------------------------------------------------------------
 QSet<ctkServiceSlotEntry> ctkPluginFrameworkListeners::getMatchingServiceSlots(
-    const ctkServiceReference& sr)
+    const ctkServiceReference& sr, bool lockProps)
 {
   QMutexLocker lock(&mutex); Q_UNUSED(lock);
 
@@ -123,20 +123,20 @@ QSet<ctkServiceSlotEntry> ctkPluginFrameworkListeners::getMatchingServiceSlots(
   }
 
   // Check the cache
-  QStringList c = sr.getProperty(ctkPluginConstants::OBJECTCLASS).toStringList();
+  QStringList c = sr.d_func()->getProperty(ctkPluginConstants::OBJECTCLASS, lockProps).toStringList();
   foreach (QString objClass, c)
   {
     addToSet(set, OBJECTCLASS_IX, objClass);
   }
 
   bool ok = false;
-  qlonglong service_id = sr.getProperty(ctkPluginConstants::SERVICE_ID).toLongLong(&ok);
+  qlonglong service_id = sr.d_func()->getProperty(ctkPluginConstants::SERVICE_ID, lockProps).toLongLong(&ok);
   if (ok)
   {
     addToSet(set, SERVICE_ID_IX, QString::number(service_id));
   }
 
-  QStringList service_pids = sr.getProperty(ctkPluginConstants::SERVICE_PID).toStringList();
+  QStringList service_pids = sr.d_func()->getProperty(ctkPluginConstants::SERVICE_PID, lockProps).toStringList();
   foreach (QString service_pid, service_pids)
   {
     addToSet(set, SERVICE_PID_IX, service_pid);

+ 4 - 2
Libs/PluginFramework/ctkPluginFrameworkListeners_p.h

@@ -69,10 +69,12 @@ public:
   /**
    * Gets the slots interested in modifications of the service reference
    *
-   * @param The reference related to the event describing the service modification.
+   * @param sr The reference related to the event describing the service modification.
+   * @param lockProps If access to the properties of the service object referenced by sr
+   *        should be synchronized.
    * @return A set of listeners to notify.
    */
-  QSet<ctkServiceSlotEntry> getMatchingServiceSlots(const ctkServiceReference& sr);
+  QSet<ctkServiceSlotEntry> getMatchingServiceSlots(const ctkServiceReference& sr, bool lockProps = true);
 
   /**
    * Convenience method for throwing framework error event.

+ 11 - 0
Libs/PluginFramework/ctkServiceReferencePrivate.cpp

@@ -167,3 +167,14 @@ ctkDictionary ctkServiceReferencePrivate::getProperties() const
 {
   return registration->properties;
 }
+
+//----------------------------------------------------------------------------
+QVariant ctkServiceReferencePrivate::getProperty(const QString& key, bool lock) const
+{
+  if (lock)
+  {
+    QMutexLocker lock(&registration->propsLock);
+    return registration->properties.value(key);
+  }
+  return registration->properties.value(key);
+}

+ 22 - 0
Libs/PluginFramework/ctkServiceReferencePrivate.h

@@ -73,6 +73,28 @@ public:
   ctkDictionary getProperties() const;
 
   /**
+   * Returns the property value to which the specified property key is mapped
+   * in the properties <code>ctkDictionary</code> object of the service
+   * referenced by this <code>ctkServiceReference</code> object.
+   *
+   * <p>
+   * Property keys are case-insensitive.
+   *
+   * <p>
+   * This method must continue to return property values after the service has
+   * been unregistered. This is so references to unregistered services can
+   * still be interrogated.
+   *
+   * @param key The property key.
+   * @param lock If <code>true</code>, access of the properties of the service
+   *        referenced by this <code>ctkServiceReference</code> object will be
+   *        synchronized.
+   * @return The property value to which the key is mapped; an invalid QVariant
+   *         if there is no property named after the key.
+   */
+  QVariant getProperty(const QString& key, bool lock) const;
+
+  /**
    * Reference count for implicitly shared private implementation.
    */
   QAtomicInt ref;

+ 1 - 1
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -118,7 +118,7 @@ void ctkServiceRegistration::setProperties(const ctkDictionary& props)
     {
       // NYI! Optimize the MODIFIED_ENDMATCH code
       int old_rank = d->properties.value(ctkPluginConstants::SERVICE_RANKING).toInt();
-      before = d->plugin->fwCtx->listeners.getMatchingServiceSlots(d->reference);
+      before = d->plugin->fwCtx->listeners.getMatchingServiceSlots(d->reference, false);
       QStringList classes = d->properties.value(ctkPluginConstants::OBJECTCLASS).toStringList();
       qlonglong sid = d->properties.value(ctkPluginConstants::SERVICE_ID).toLongLong();
       d->properties = ctkServices::createServiceProperties(props, classes, sid);