瀏覽代碼

Return a QSharedPointer for ctkPlugin in event classes.

Sascha Zelzer 14 年之前
父節點
當前提交
3525fe3fb4

+ 1 - 1
Libs/PluginFramework/Testing/FrameworkTest/ctkPluginFrameworkTestSuite.cpp

@@ -514,7 +514,7 @@ bool ctkPluginFrameworkTestSuite::checkListenerEvents(
   QList<ctkPluginEvent> pEvts;
   QList<ctkServiceEvent> seEvts;
 
-  if (fwexp) fwEvts << ctkPluginFrameworkEvent(fwtype, pluginX.data());
+  if (fwexp) fwEvts << ctkPluginFrameworkEvent(fwtype, pluginX);
   if (pexp) pEvts << ctkPluginEvent(ptype, pluginX);
   if (sexp) seEvts << ctkServiceEvent(stype, *servX);
 

+ 2 - 2
Libs/PluginFramework/ctkPlugin.cpp

@@ -206,7 +206,7 @@ void ctkPlugin::uninstall()
         catch (const std::exception& exception)
         {
           // NYI! not call inside lock
-          d->fwCtx->listeners.frameworkError(this, exception);
+          d->fwCtx->listeners.frameworkError(this->d_func()->q_func(), exception);
         }
       }
     }
@@ -214,7 +214,7 @@ void ctkPlugin::uninstall()
     {
       d->deactivating = false;
       //fwCtx.packages.notifyAll();
-      d->fwCtx->listeners.frameworkError(this, e);
+      d->fwCtx->listeners.frameworkError(this->d_func()->q_func(), e);
     }
     // Fall through
   case RESOLVED:

+ 2 - 2
Libs/PluginFramework/ctkPluginContext.cpp

@@ -192,7 +192,7 @@ void ctkPluginContext::connectServiceListener(QObject* receiver, const char* slo
 {
   Q_D(ctkPluginContext);
   d->isPluginContextValid();
-  d->plugin->fwCtx->listeners.addServiceSlot(getPlugin().data(), receiver, slot, filter);
+  d->plugin->fwCtx->listeners.addServiceSlot(getPlugin(), receiver, slot, filter);
 }
 
 void ctkPluginContext::disconnectServiceListener(QObject* receiver,
@@ -200,5 +200,5 @@ void ctkPluginContext::disconnectServiceListener(QObject* receiver,
 {
   Q_D(ctkPluginContext);
   d->isPluginContextValid();
-  d->plugin->fwCtx->listeners.removeServiceSlot(getPlugin().data(), receiver, slot);
+  d->plugin->fwCtx->listeners.removeServiceSlot(getPlugin(), receiver, slot);
 }

+ 2 - 2
Libs/PluginFramework/ctkPluginFramework.cpp

@@ -87,7 +87,7 @@ void ctkPluginFramework::start(const ctkPlugin::StartOptions& options)
   QStringListIterator i(pluginsToStart);
   while (i.hasNext())
   {
-    ctkPlugin* plugin = d->fwCtx->plugins->getPlugin(i.next());
+    QSharedPointer<ctkPlugin> plugin = d->fwCtx->plugins->getPlugin(i.next());
     try {
       const int autostartSetting = plugin->d_func()->archive->getAutostartSetting();
       // Launch must not change the autostart setting of a plugin
@@ -110,7 +110,7 @@ void ctkPluginFramework::start(const ctkPlugin::StartOptions& options)
     d->state = ACTIVE;
     d->activating = false;
     d->fwCtx->listeners.emitFrameworkEvent(
-        ctkPluginFrameworkEvent(ctkPluginFrameworkEvent::STARTED, this));
+        ctkPluginFrameworkEvent(ctkPluginFrameworkEvent::STARTED, this->d_func()->q_func()));
   }
 }
 

+ 2 - 2
Libs/PluginFramework/ctkPluginFrameworkContext.cpp

@@ -91,7 +91,7 @@ void ctkPluginFrameworkContext::init()
   for (int i = 0; i < allPAs.size(); ++i)
   {
     ctkPluginArchive* pa = allPAs[i];
-    ctkPlugin* plugin = plugins->getPlugin(pa->getPluginLocation().toString());
+    QSharedPointer<ctkPlugin> plugin = plugins->getPlugin(pa->getPluginLocation().toString());
     log() << " #" << plugin->getPluginId() << " " << plugin->getSymbolicName() << ":"
         << plugin->getVersion() << " location:" << plugin->getLocation();
   }
@@ -154,7 +154,7 @@ void ctkPluginFrameworkContext::resolvePlugin(ctkPluginPrivate* plugin)
   if (tempResolved.size() > 0 && !tempResolved.contains(plugin))
   {
     ctkPluginException pe("resolve: InternalError1!", ctkPluginException::RESOLVE_ERROR);
-    listeners.frameworkError(plugin->q_func().data(), pe);
+    listeners.frameworkError(plugin->q_func(), pe);
     throw pe;
   }
 

+ 6 - 6
Libs/PluginFramework/ctkPluginFrameworkEvent.cpp

@@ -30,7 +30,7 @@ class ctkPluginFrameworkEventData : public QSharedData
 {
 public:
 
-  ctkPluginFrameworkEventData(ctkPluginFrameworkEvent::Type type, ctkPlugin* plugin, const QString& exc)
+  ctkPluginFrameworkEventData(ctkPluginFrameworkEvent::Type type, QSharedPointer<ctkPlugin> plugin, const QString& exc)
     : plugin(plugin), errorString(exc), type(type)
   {
 
@@ -46,7 +46,7 @@ public:
   /**
    * Plugin related to the event.
    */
-  ctkPlugin* const	plugin;
+  const QSharedPointer<ctkPlugin>	plugin;
 
   /**
    * Exception related to the event.
@@ -76,13 +76,13 @@ bool ctkPluginFrameworkEvent::isNull() const
   return !d;
 }
 
-ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin, const std::exception& fwException)
+ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin, const std::exception& fwException)
   : d(new ctkPluginFrameworkEventData(type, plugin, fwException.what()))
 {
 
 }
 
-ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin)
+ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin)
   : d(new ctkPluginFrameworkEventData(type, plugin, QString()))
 {
 
@@ -105,7 +105,7 @@ QString ctkPluginFrameworkEvent::getErrorString() const
   return d->errorString;
 }
 
-ctkPlugin* ctkPluginFrameworkEvent::getPlugin() const
+QSharedPointer<ctkPlugin> ctkPluginFrameworkEvent::getPlugin() const
 {
   return d->plugin;
 }
@@ -135,7 +135,7 @@ QDebug operator<<(QDebug dbg, const ctkPluginFrameworkEvent& event)
 {
   if (event.isNull()) return dbg << "NONE";
 
-  ctkPlugin* p = event.getPlugin();
+  ctkPlugin* p = event.getPlugin().data();
   QString err = event.getErrorString();
 
   dbg.nospace() << event.getType() << " #" << p->getPluginId() << " ("

+ 4 - 3
Libs/PluginFramework/ctkPluginFrameworkEvent.h

@@ -23,6 +23,7 @@
 #define CTKPLUGINFRAMEWORKEVENT_H
 
 #include <QSharedDataPointer>
+#include <QSharedPointer>
 
 #include "ctkPluginFrameworkExport.h"
 
@@ -140,7 +141,7 @@ public:
    * @param plugin The event source.
    * @param fwException The related exception.
    */
-  ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin, const std::exception& fwException);
+  ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin, const std::exception& fwException);
 
   /**
    * Creates a Framework event regarding the specified plugin.
@@ -148,7 +149,7 @@ public:
    * @param type The event type.
    * @param plugin The event source.
    */
-  ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin);
+  ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin);
 
   ctkPluginFrameworkEvent(const ctkPluginFrameworkEvent& other);
 
@@ -167,7 +168,7 @@ public:
    *
    * @return The plugin associated with the event.
    */
-  ctkPlugin* getPlugin() const;
+  QSharedPointer<ctkPlugin> getPlugin() const;
 
   /**
    * Returns the type of framework event.

+ 4 - 4
Libs/PluginFramework/ctkPluginFrameworkListeners.cpp

@@ -45,7 +45,7 @@ ctkPluginFrameworkListeners::ctkPluginFrameworkListeners()
 }
 
 void ctkPluginFrameworkListeners::addServiceSlot(
-    ctkPlugin* plugin, QObject* receiver,
+    QSharedPointer<ctkPlugin> plugin, QObject* receiver,
     const char* slot, const QString& filter)
 {
   QMutexLocker lock(&mutex); Q_UNUSED(lock)
@@ -60,7 +60,7 @@ void ctkPluginFrameworkListeners::addServiceSlot(
   connect(receiver, SIGNAL(destroyed(QObject*)), this, SLOT(serviceListenerDestroyed(QObject*)));
 }
 
-void ctkPluginFrameworkListeners::removeServiceSlot(ctkPlugin* plugin,
+void ctkPluginFrameworkListeners::removeServiceSlot(QSharedPointer<ctkPlugin> plugin,
                                                     QObject* receiver,
                                                     const char* slot)
 {
@@ -89,7 +89,7 @@ void ctkPluginFrameworkListeners::removeServiceSlot(ctkPlugin* plugin,
 
 void ctkPluginFrameworkListeners::serviceListenerDestroyed(QObject *listener)
 {
-  this->removeServiceSlot(0, listener, 0);
+  this->removeServiceSlot(QSharedPointer<ctkPlugin>(0), listener, 0);
 }
 
 QSet<ctkServiceSlotEntry> ctkPluginFrameworkListeners::getMatchingServiceSlots(
@@ -138,7 +138,7 @@ QSet<ctkServiceSlotEntry> ctkPluginFrameworkListeners::getMatchingServiceSlots(
   return set;
 }
 
-void ctkPluginFrameworkListeners::frameworkError(ctkPlugin* p, const std::exception& e)
+void ctkPluginFrameworkListeners::frameworkError(QSharedPointer<ctkPlugin> p, const std::exception& e)
 {
   emit frameworkEvent(ctkPluginFrameworkEvent(ctkPluginFrameworkEvent::ERROR, p, e));
 }

+ 3 - 3
Libs/PluginFramework/ctkPluginFrameworkListeners_p.h

@@ -50,7 +50,7 @@ public:
    * @param listener Object to add.
    * @param filter LDAP String used for filtering event before calling listener.
    */
-  void addServiceSlot(ctkPlugin* plugin, QObject* receiver,
+  void addServiceSlot(QSharedPointer<ctkPlugin> plugin, QObject* receiver,
                       const char* slot, const QString& filter);
 
   /**
@@ -60,7 +60,7 @@ public:
    * @param receiver The receiver containing the slot.
    * @param slot The slot in the receiver.
    */
-  void removeServiceSlot(ctkPlugin* plugin, QObject* receiver,
+  void removeServiceSlot(QSharedPointer<ctkPlugin> plugin, QObject* receiver,
                          const char* slot);
 
   /**
@@ -77,7 +77,7 @@ public:
    * @param p Plugin which caused the error.
    * @param e The exception.
    */
-  void frameworkError(ctkPlugin* p, const std::exception& e);
+  void frameworkError(QSharedPointer<ctkPlugin> p, const std::exception& e);
 
   /**
    * Receive notification that a service has had a change occur in its lifecycle.

+ 3 - 3
Libs/PluginFramework/ctkPluginPrivate.cpp

@@ -128,7 +128,7 @@ ctkPlugin::State ctkPluginPrivate::getUpdatedState()
     }
     catch (const ctkPluginException& pe)
     {
-      this->fwCtx->listeners.frameworkError(this->q_func().data(), pe);
+      this->fwCtx->listeners.frameworkError(this->q_func(), pe);
       throw;
     }
   }
@@ -151,7 +151,7 @@ void ctkPluginPrivate::setAutostartSetting(const ctkPlugin::StartOptions& settin
   }
   catch (const ctkPluginDatabaseException& e)
   {
-    this->fwCtx->listeners.frameworkError(this->q_func().data(), e);
+    this->fwCtx->listeners.frameworkError(this->q_func(), e);
   }
 }
 
@@ -166,7 +166,7 @@ void ctkPluginPrivate::ignoreAutostartSetting()
   }
   catch (const ctkPluginDatabaseException& e)
   {
-    this->fwCtx->listeners.frameworkError(this->q_func().data(), e);
+    this->fwCtx->listeners.frameworkError(this->q_func(), e);
   }
 }
 

+ 7 - 7
Libs/PluginFramework/ctkPlugins.cpp

@@ -167,7 +167,7 @@ QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(int id) const
   return QSharedPointer<ctkPlugin>();
 }
 
-ctkPlugin* ctkPlugins::getPlugin(const QString& location) const
+QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& location) const
 {
   if (!fwCtx)
   { // This plugins instance has been closed!
@@ -176,11 +176,11 @@ ctkPlugin* ctkPlugins::getPlugin(const QString& location) const
 
   QReadLocker lock(&pluginsLock);
   QHash<QString, QSharedPointer<ctkPlugin> >::const_iterator it = plugins.find(location);
-  if (it != plugins.end()) return it.value().data();
-  return 0;
+  if (it != plugins.end()) return it.value();
+  return QSharedPointer<ctkPlugin>(0);
 }
 
-ctkPlugin* ctkPlugins::getPlugin(const QString& name, const ctkVersion& version) const
+QSharedPointer<ctkPlugin> ctkPlugins::getPlugin(const QString& name, const ctkVersion& version) const
 {
   if (!fwCtx)
   { // This ctkPlugins instance has been closed!
@@ -196,11 +196,11 @@ ctkPlugin* ctkPlugins::getPlugin(const QString& name, const ctkVersion& version)
       QSharedPointer<ctkPlugin> plugin = it.next().value();
       if ((name == plugin->getSymbolicName()) && (version == plugin->getVersion()))
       {
-        return plugin.data();
+        return plugin;
       }
     }
   }
-  return 0;
+  return QSharedPointer<ctkPlugin>(0);
 }
 
 QList<QSharedPointer<ctkPlugin> > ctkPlugins::getPlugins() const
@@ -345,7 +345,7 @@ void ctkPlugins::startPlugins(const QList<ctkPlugin*>& slist) const
       }
       catch (const ctkPluginException& pe)
       {
-        pp->fwCtx->listeners.frameworkError(plugin, pe);
+        pp->fwCtx->listeners.frameworkError(pp->q_func(), pe);
       }
     }
   }

+ 2 - 2
Libs/PluginFramework/ctkPlugins_p.h

@@ -104,7 +104,7 @@
      * @return ctkPlugin or null
      *         if the plugin was not found.
      */
-    ctkPlugin* getPlugin(const QString& location) const;
+    QSharedPointer<ctkPlugin> getPlugin(const QString& location) const;
 
 
     /**
@@ -114,7 +114,7 @@
      * @param version The plugin version of the plugin to get.
      * @return ctkPlugin or null.
      */
-    ctkPlugin* getPlugin(const QString& name, const ctkVersion& version) const;
+    QSharedPointer<ctkPlugin> getPlugin(const QString& name, const ctkVersion& version) const;
 
 
     /**

+ 4 - 4
Libs/PluginFramework/ctkServiceReferencePrivate.cpp

@@ -63,14 +63,14 @@ QObject* ctkServiceReferencePrivate::getService(QSharedPointer<ctkPlugin> plugin
             ctkServiceException se("ctkServiceFactory throw an exception",
                                    ctkServiceException::FACTORY_EXCEPTION, &pe);
             plugin->d_func()->fwCtx->listeners.frameworkError
-                (registration->plugin->q_func().data(), se);
+                (registration->plugin->q_func(), se);
             return 0;
           }
           if (s == 0) {
             ctkServiceException se("ctkServiceFactory produced null",
                                    ctkServiceException::FACTORY_ERROR);
             plugin->d_func()->fwCtx->listeners.frameworkError
-                (registration->plugin->q_func().data(), se);
+                (registration->plugin->q_func(), se);
             return 0;
           }
           for (QStringListIterator i(classes); i.hasNext(); )
@@ -82,7 +82,7 @@ QObject* ctkServiceReferencePrivate::getService(QSharedPointer<ctkPlugin> plugin
                                      "that did not implement: " + cls,
                                      ctkServiceException::FACTORY_ERROR);
               plugin->d_func()->fwCtx->listeners.frameworkError
-                  (registration->plugin->q_func().data(), se);
+                  (registration->plugin->q_func(), se);
               return 0;
             }
           }
@@ -151,7 +151,7 @@ bool ctkServiceReferencePrivate::ungetService(QSharedPointer<ctkPlugin> plugin,
       }
       catch (const std::exception& e)
       {
-        plugin->d_func()->fwCtx->listeners.frameworkError(registration->plugin->q_func().data(), e);
+        plugin->d_func()->fwCtx->listeners.frameworkError(registration->plugin->q_func(), e);
       }
     }
     registration->dependents.remove(plugin);

+ 1 - 1
Libs/PluginFramework/ctkServiceRegistration.cpp

@@ -170,7 +170,7 @@ void ctkServiceRegistration::unregister()
           }
           catch (const std::exception& ue)
           {
-            ctkPluginFrameworkEvent pfwEvent(ctkPluginFrameworkEvent::ERROR, d->plugin->q_func().data(), ue);
+            ctkPluginFrameworkEvent pfwEvent(ctkPluginFrameworkEvent::ERROR, d->plugin->q_func(), ue);
             d->plugin->fwCtx->listeners
                 .emitFrameworkEvent(pfwEvent);
           }

+ 5 - 5
Libs/PluginFramework/ctkServiceSlotEntry.cpp

@@ -33,7 +33,7 @@ class ctkServiceSlotEntryData : public QSharedData
 {
 public:
 
-  ctkServiceSlotEntryData(ctkPlugin* p, QObject* receiver,
+  ctkServiceSlotEntryData(QSharedPointer<ctkPlugin> p, QObject* receiver,
                           const char* slot)
     : plugin(p), receiver(receiver),
       slot(slot), removed(false)
@@ -63,7 +63,7 @@ public:
   ctkLDAPExpr::LocalCache local_cache;
 
   ctkLDAPExpr ldap;
-  ctkPlugin* plugin;
+  QSharedPointer<ctkPlugin> plugin;
   QObject* receiver;
   const char* slot;
   bool removed;
@@ -71,7 +71,7 @@ public:
 };
 
 ctkServiceSlotEntry::ctkServiceSlotEntry(
-    ctkPlugin* p, QObject* receiver, const char* slot, const QString& filter)
+    QSharedPointer<ctkPlugin> p, QObject* receiver, const char* slot, const QString& filter)
   : d(new ctkServiceSlotEntryData(p, receiver, slot))
 {
   if (!filter.isNull())
@@ -87,7 +87,7 @@ ctkServiceSlotEntry::ctkServiceSlotEntry(const ctkServiceSlotEntry& other)
 }
 
 ctkServiceSlotEntry::ctkServiceSlotEntry()
-  : d(new ctkServiceSlotEntryData(0, 0, 0))
+  : d(new ctkServiceSlotEntryData(QSharedPointer<ctkPlugin>(0), 0, 0))
 {
 
 }
@@ -134,7 +134,7 @@ bool ctkServiceSlotEntry::isRemoved() const
   return d->removed;
 }
 
-ctkPlugin* ctkServiceSlotEntry::getPlugin() const
+QSharedPointer<ctkPlugin> ctkServiceSlotEntry::getPlugin() const
 {
   return d->plugin;
 }

+ 2 - 2
Libs/PluginFramework/ctkServiceSlotEntry_p.h

@@ -48,7 +48,7 @@ class ctkServiceSlotEntry
 
 public:
 
-  ctkServiceSlotEntry(ctkPlugin* p, QObject* receiver, const char* slot,
+  ctkServiceSlotEntry(QSharedPointer<ctkPlugin> p, QObject* receiver, const char* slot,
                       const QString& filter = QString());
 
   ctkServiceSlotEntry(const ctkServiceSlotEntry& other);
@@ -68,7 +68,7 @@ public:
 
   bool isRemoved() const;
 
-  ctkPlugin* getPlugin() const;
+  QSharedPointer<ctkPlugin> getPlugin() const;
 
   ctkLDAPExpr getLDAPExpr() const;