Browse Source

Cleanup Plugin and Framework events.

Moved the QSharedData implementation to the cpp file and removed
QObject inheritance.
Sascha Zelzer 14 years ago
parent
commit
50a57d820b

+ 27 - 1
Libs/PluginFramework/ctkPluginEvent.cpp

@@ -21,12 +21,38 @@
 
 #include "ctkPluginEvent.h"
 
+class ctkPluginEventData : public QSharedData
+{
+public:
+
+  ctkPluginEventData(ctkPluginEvent::Type type, ctkPlugin* plugin)
+    : type(type), plugin(plugin)
+  {
+
+  }
+
+  ctkPluginEventData(const ctkPluginEventData& other)
+    : QSharedData(other), type(other.type), plugin(other.plugin)
+  {
+
+  }
+
+  const ctkPluginEvent::Type type;
+  ctkPlugin *const plugin;
+};
+
+
 ctkPluginEvent::ctkPluginEvent()
   : d(0)
 {
 
 }
 
+ctkPluginEvent::~ctkPluginEvent()
+{
+
+}
+
 ctkPluginEvent::ctkPluginEvent(Type type, ctkPlugin* plugin)
   : d(new ctkPluginEventData(type, plugin))
 {
@@ -34,7 +60,7 @@ ctkPluginEvent::ctkPluginEvent(Type type, ctkPlugin* plugin)
 }
 
 ctkPluginEvent::ctkPluginEvent(const ctkPluginEvent& other)
-  : QObject(), d(other.d)
+  : d(other.d)
 {
 
 }

+ 5 - 31
Libs/PluginFramework/ctkPluginEvent.h

@@ -22,7 +22,6 @@
 #ifndef CTKPLUGINEVENT_H
 #define CTKPLUGINEVENT_H
 
-#include <QObject>
 #include <QSharedDataPointer>
 
 #include "CTKPluginFrameworkExport.h"
@@ -35,20 +34,15 @@ class ctkPluginEventData;
  * An event from the Framework describing a plugin lifecycle change.
  * <p>
  * <code>ctkPluginEvent</code> objects are delivered to slots connected
- * to ctkPluginContext::pluginChanged() or to registerd event handlers
- * for the topic "org.commontk/framework/pluginChanged"
- * when a change occurs in a plugins's lifecycle. A type code is used to identify
+ * via ctkPluginContext::connectPluginListener() when a change
+ * occurs in a plugins's lifecycle. A type code is used to identify
  * the event type for future extendability.
  *
  * @see ctkPluginContext#connectPluginListener
  * @see ctkEventBus
  */
-class CTK_PLUGINFW_EXPORT ctkPluginEvent : public QObject
+class CTK_PLUGINFW_EXPORT ctkPluginEvent
 {
-  Q_OBJECT
-  Q_PROPERTY(Type type READ getType CONSTANT)
-  Q_PROPERTY(ctkPlugin* plugin READ getPlugin CONSTANT)
-  Q_ENUMS(Type)
 
   QSharedDataPointer<ctkPluginEventData> d;
 
@@ -72,6 +66,8 @@ public:
    */
   ctkPluginEvent();
 
+  ~ctkPluginEvent();
+
   /**
    * Creates a plugin event of the specified type.
    *
@@ -110,26 +106,4 @@ public:
 
 };
 
-
-class ctkPluginEventData : public QSharedData
-{
-public:
-
-  ctkPluginEventData(ctkPluginEvent::Type type, ctkPlugin* plugin)
-    : type(type), plugin(plugin)
-  {
-
-  }
-
-  ctkPluginEventData(const ctkPluginEventData& other)
-    : QSharedData(other), type(other.type), plugin(other.plugin)
-  {
-
-  }
-
-  const ctkPluginEvent::Type type;
-  ctkPlugin* const plugin;
-};
-
-
 #endif // CTKPLUGINEVENT_H

+ 41 - 1
Libs/PluginFramework/ctkPluginFrameworkEvent.cpp

@@ -21,6 +21,41 @@
 
 #include "ctkPluginFrameworkEvent.h"
 
+#include <QString>
+
+class ctkPluginFrameworkEventData : public QSharedData
+{
+public:
+
+  ctkPluginFrameworkEventData(ctkPluginFrameworkEvent::Type type, ctkPlugin* plugin, const QString& exc)
+    : plugin(plugin), errorString(exc), type(type)
+  {
+
+  }
+
+  ctkPluginFrameworkEventData(const ctkPluginFrameworkEventData& other)
+    : QSharedData(other), plugin(other.plugin), errorString(other.errorString),
+      type(other.type)
+  {
+
+  }
+
+  /**
+   * Plugin related to the event.
+   */
+  ctkPlugin* const	plugin;
+
+  /**
+   * Exception related to the event.
+   */
+  const QString errorString;
+
+  /**
+   * Type of event.
+   */
+  const ctkPluginFrameworkEvent::Type type;
+};
+
 
 ctkPluginFrameworkEvent::ctkPluginFrameworkEvent()
   : d(0)
@@ -28,6 +63,11 @@ ctkPluginFrameworkEvent::ctkPluginFrameworkEvent()
 
 }
 
+ctkPluginFrameworkEvent::~ctkPluginFrameworkEvent()
+{
+
+}
+
 ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin, const std::exception& fwException)
   : d(new ctkPluginFrameworkEventData(type, plugin, fwException.what()))
 {
@@ -41,7 +81,7 @@ ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin)
 }
 
 ctkPluginFrameworkEvent::ctkPluginFrameworkEvent(const ctkPluginFrameworkEvent& other)
-  : QObject(), d(other.d)
+  : d(other.d)
 {
 
 }

+ 116 - 154
Libs/PluginFramework/ctkPluginFrameworkEvent.h

@@ -22,198 +22,160 @@
 #ifndef CTKPLUGINFRAMEWORKEVENT_H
 #define CTKPLUGINFRAMEWORKEVENT_H
 
-#include <QObject>
 #include <QSharedDataPointer>
 
 #include "CTKPluginFrameworkExport.h"
 
+#include <stdexcept>
 
-  class ctkPlugin;
-  class ctkPluginFrameworkEventData;
+class ctkPlugin;
+class ctkPluginFrameworkEventData;
 
-  /**
-   * A general event from the Framework.
-   *
-   * <p>
-   * <code>ctkPluginFrameworkEvent</code> objects are delivered to slots connected
-   * <code>FrameworkListener</code>s when a general event occurs within the plugin
-   * environment. A type code is used to identify the event type for future
-   * extendability.
-   *
-   * @see ctkPluginContext#connectFrameworkListener
-   * @see ctkEventBus
-   */
-  class CTK_PLUGINFW_EXPORT ctkPluginFrameworkEvent : public QObject
-  {
-    Q_OBJECT
-    Q_PROPERTY(Type type READ getType CONSTANT)
-    Q_PROPERTY(ctkPlugin* plugin READ getPlugin CONSTANT)
-    Q_PROPERTY(QString errorString READ getErrorString CONSTANT)
-    Q_ENUMS(Type)
-
-    QSharedDataPointer<ctkPluginFrameworkEventData> d;
-
-  public:
-
-    enum Type {
-      /**
-       * The Framework has started.
-       *
-       * <p>
-       * This event is fired when the Framework has started after all installed
-       * plugins that are marked to be started have been started and the Framework
-       * has reached the initial start level. The source of this event is the
-       * System Plugin.
-       */
-      STARTED,
-
-      /**
-       * An error has occurred.
-       *
-       * <p>
-       * There was an error associated with a plugin.
-       */
-      ERROR,
-
-      /**
-       * A warning has occurred.
-       *
-       * <p>
-       * There was a warning associated with a plugin.
-       */
-      WARNING,
-
-      /**
-       * An informational event has occurred.
-       *
-       * <p>
-       * There was an informational event associated with a plugin.
-       */
-      INFO,
-
-      /**
-       * The Framework has stopped.
-       *
-       * <p>
-       * This event is fired when the Framework has been stopped because of a stop
-       * operation on the system plugin. The source of this event is the System
-       * Plugin.
-       */
-      STOPPED,
-
-      /**
-       * The Framework has stopped during update.
-       *
-       * <p>
-       * This event is fired when the Framework has been stopped because of an
-       * update operation on the system plugin. The Framework will be restarted
-       * after this event is fired. The source of this event is the System Plugin.
-       */
-      STOPPED_UPDATE,
-
-      /**
-       * The Framework did not stop before the wait timeout expired.
-       *
-       * <p>
-       * This event is fired when the Framework did not stop before the wait
-       * timeout expired. The source of this event is the System Plugin.
-       */
-      WAIT_TIMEDOUT
-
-    };
+/**
+ * A general event from the Framework.
+ *
+ * <p>
+ * <code>ctkPluginFrameworkEvent</code> objects are delivered to slots connected
+ * via ctkPluginContext::connectFrameworkListener when a general event occurs
+ * within the plugin environment.
+ * A type code is used to identify the event type for future extendability.
+ *
+ * @see ctkPluginContext#connectFrameworkListener
+ * @see ctkEventBus
+ */
+class CTK_PLUGINFW_EXPORT ctkPluginFrameworkEvent
+{
+
+  QSharedDataPointer<ctkPluginFrameworkEventData> d;
 
+public:
+
+  enum Type {
     /**
-     * Default constructor for use with the Qt meta object system.
+     * The Framework has started.
+     *
+     * <p>
+     * This event is fired when the Framework has started after all installed
+     * plugins that are marked to be started have been started and the Framework
+     * has reached the initial start level. The source of this event is the
+     * System Plugin.
      */
-    ctkPluginFrameworkEvent();
+    STARTED,
 
     /**
-     * Creates a Framework event regarding the specified plugin and exception.
+     * An error has occurred.
      *
-     * @param type The event type.
-     * @param plugin The event source.
-     * @param fwException The related exception.
+     * <p>
+     * There was an error associated with a plugin.
      */
-    ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin, const std::exception& fwException);
+    ERROR,
 
     /**
-     * Creates a Framework event regarding the specified plugin.
+     * A warning has occurred.
      *
-     * @param type The event type.
-     * @param plugin The event source.
+     * <p>
+     * There was a warning associated with a plugin.
      */
-    ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin);
-
-    ctkPluginFrameworkEvent(const ctkPluginFrameworkEvent& other);
+    WARNING,
 
     /**
-     * Returns the exception error string related to this event.
+     * An informational event has occurred.
      *
-     * @return The related error string.
+     * <p>
+     * There was an informational event associated with a plugin.
      */
-    QString getErrorString() const;
+    INFO,
 
     /**
-     * Returns the plugin associated with the event. This plugin is also the
-     * source of the event.
+     * The Framework has stopped.
      *
-     * @return The plugin associated with the event.
+     * <p>
+     * This event is fired when the Framework has been stopped because of a stop
+     * operation on the system plugin. The source of this event is the System
+     * Plugin.
      */
-    ctkPlugin* getPlugin() const;
+    STOPPED,
 
     /**
-     * Returns the type of framework event.
-     * <p>
-     * The type values are:
-     * <ul>
-     * <li>{@link #STARTED}
-     * <li>{@link #ERROR}
-     * <li>{@link #WARNING}
-     * <li>{@link #INFO}
-     * <li>{@link #STARTLEVEL_CHANGED}
-     * <li>{@link #STOPPED}
-     * <li>{@link #STOPPED_UPDATE}
-     * <li>{@link #WAIT_TIMEDOUT}
-     * </ul>
+     * The Framework has stopped during update.
      *
-     * @return The type of state change.
+     * <p>
+     * This event is fired when the Framework has been stopped because of an
+     * update operation on the system plugin. The Framework will be restarted
+     * after this event is fired. The source of this event is the System Plugin.
      */
-    Type getType() const;
-  };
+    STOPPED_UPDATE,
 
+    /**
+     * The Framework did not stop before the wait timeout expired.
+     *
+     * <p>
+     * This event is fired when the Framework did not stop before the wait
+     * timeout expired. The source of this event is the System Plugin.
+     */
+    WAIT_TIMEDOUT
 
-  class ctkPluginFrameworkEventData : public QSharedData
-  {
-  public:
+  };
 
-    ctkPluginFrameworkEventData(ctkPluginFrameworkEvent::Type type, ctkPlugin* plugin, const QString& exc)
-      : plugin(plugin), errorString(exc), type(type)
-    {
+  /**
+   * Default constructor for use with the Qt meta object system.
+   */
+  ctkPluginFrameworkEvent();
 
-    }
+  ~ctkPluginFrameworkEvent();
 
-    ctkPluginFrameworkEventData(const ctkPluginFrameworkEventData& other)
-      : QSharedData(other), plugin(other.plugin), errorString(other.errorString),
-        type(other.type)
-    {
+  /**
+   * Creates a Framework event regarding the specified plugin and exception.
+   *
+   * @param type The event type.
+   * @param plugin The event source.
+   * @param fwException The related exception.
+   */
+  ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin, const std::exception& fwException);
 
-    }
+  /**
+   * Creates a Framework event regarding the specified plugin.
+   *
+   * @param type The event type.
+   * @param plugin The event source.
+   */
+  ctkPluginFrameworkEvent(Type type, ctkPlugin* plugin);
 
-    /**
-     * Plugin related to the event.
-     */
-    ctkPlugin* const	plugin;
+  ctkPluginFrameworkEvent(const ctkPluginFrameworkEvent& other);
 
-    /**
-     * Exception related to the event.
-     */
-    const QString errorString;
+  /**
+   * Returns the exception error string related to this event.
+   *
+   * @return The related error string.
+   */
+  QString getErrorString() const;
 
-    /**
-     * Type of event.
-     */
-    const ctkPluginFrameworkEvent::Type type;
-  };
+  /**
+   * Returns the plugin associated with the event. This plugin is also the
+   * source of the event.
+   *
+   * @return The plugin associated with the event.
+   */
+  ctkPlugin* getPlugin() const;
 
+  /**
+   * Returns the type of framework event.
+   * <p>
+   * The type values are:
+   * <ul>
+   * <li>{@link #STARTED}
+   * <li>{@link #ERROR}
+   * <li>{@link #WARNING}
+   * <li>{@link #INFO}
+   * <li>{@link #STARTLEVEL_CHANGED}
+   * <li>{@link #STOPPED}
+   * <li>{@link #STOPPED_UPDATE}
+   * <li>{@link #WAIT_TIMEDOUT}
+   * </ul>
+   *
+   * @return The type of state change.
+   */
+  Type getType() const;
+};
 
 #endif // CTKPLUGINFRAMEWORKEVENT_H