Browse Source

Send certain plugin events only to synchronuous listeners.

ctkPluginEvent's of type STARTING, STOPPING, or LAZY_ACTIVATION
should only be send to slots with a direct connection.
Sascha Zelzer 14 years ago
parent
commit
f044601a25

+ 12 - 1
Libs/PluginFramework/ctkPluginContext.cpp

@@ -134,7 +134,18 @@ bool ctkPluginContext::connectPluginListener(const QObject* receiver, const char
   Q_D(ctkPluginContext);
   d->isPluginContextValid();
   // TODO check permissions for a direct connection
-  return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChanged(ctkPluginEvent)), method, type);
+  if (type == Qt::DirectConnection || type == Qt::BlockingQueuedConnection)
+  {
+    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedDirect(ctkPluginEvent)), method, type);
+  }
+  else if (type == Qt::QueuedConnection)
+  {
+    return receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChangedQueued(ctkPluginEvent)), method, type);
+  }
+  else
+  {
+    throw std::invalid_argument("Only Qt::DirectConnection, Qt::QueuedConnection, or Qt::BlockingQueuedConnection are allowed as type argument.");
+  }
 }
 
 bool ctkPluginContext::connectFrameworkListener(const QObject* receiver, const char* method, Qt::ConnectionType type)

+ 2 - 1
Libs/PluginFramework/ctkPluginContext.h

@@ -458,7 +458,8 @@
      *
      * @param receiver The object to connect to.
      * @param slot The slot to be connected.
-     * @param type The Qt connection type.
+     * @param type The Qt connection type. Only Qt::DirectConnection,
+     *        Qt::QueuedConnection, or Qt::BlockingQueuedConnection is allowed.
      * @throws std::logic_error If this ctkPluginContext is no
      *         longer valid.
      * @see ctkPluginEvent

+ 8 - 1
Libs/PluginFramework/ctkPluginFrameworkListeners.cpp

@@ -138,7 +138,14 @@ void ctkPluginFrameworkListeners::emitFrameworkEvent(const ctkPluginFrameworkEve
 
 void ctkPluginFrameworkListeners::emitPluginChanged(const ctkPluginEvent& event)
 {
-  emit pluginChanged(event);
+  emit pluginChangedDirect(event);
+
+  if (!(event.getType() == ctkPluginEvent::STARTING ||
+      event.getType() == ctkPluginEvent::STOPPING ||
+      event.getType() == ctkPluginEvent::LAZY_ACTIVATION))
+  {
+    emit pluginChangedQueued(event);
+  }
 }
 
 void ctkPluginFrameworkListeners::serviceChanged(

+ 2 - 1
Libs/PluginFramework/ctkPluginFrameworkListeners_p.h

@@ -95,7 +95,8 @@ public:
 
 signals:
 
-  void pluginChanged(const ctkPluginEvent& event);
+  void pluginChangedDirect(const ctkPluginEvent& event);
+  void pluginChangedQueued(const ctkPluginEvent& event);
 
   void frameworkEvent(const ctkPluginFrameworkEvent& event);