ctkPluginEvent.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKPLUGINEVENT_H
  16. #define CTKPLUGINEVENT_H
  17. #include <QSharedDataPointer>
  18. #include <QSharedPointer>
  19. #include <QMetaType>
  20. #include "ctkPluginFrameworkExport.h"
  21. class ctkPlugin;
  22. class ctkPluginEventData;
  23. /**
  24. * \ingroup PluginFramework
  25. *
  26. * An event from the Framework describing a plugin lifecycle change.
  27. * <p>
  28. * <code>ctkPluginEvent</code> objects are delivered to slots connected
  29. * via ctkPluginContext::connectPluginListener() when a change
  30. * occurs in a plugins's lifecycle. A type code is used to identify
  31. * the event type for future extendability.
  32. *
  33. * @see ctkPluginContext#connectPluginListener
  34. */
  35. class CTK_PLUGINFW_EXPORT ctkPluginEvent
  36. {
  37. QSharedDataPointer<ctkPluginEventData> d;
  38. public:
  39. enum Type {
  40. /**
  41. * The plugin has been installed.
  42. *
  43. * @see ctkPluginContext::installBundle(const QString&)
  44. */
  45. INSTALLED,
  46. /**
  47. * The plugin has been started.
  48. * <p>
  49. * The plugin's
  50. * \link ctkPluginActivator::start(ctkPluginContext*) ctkPluginActivator start\endlink method
  51. * has been executed.
  52. *
  53. * @see ctkPlugin::start()
  54. */
  55. STARTED,
  56. /**
  57. * The plugin has been stopped.
  58. * <p>
  59. * The plugin's
  60. * \link ctkPluginActivator::stop(ctkPluginContext*) ctkPluginActivator stop\endlink method
  61. * has been executed.
  62. *
  63. * @see ctkPlugin::stop()
  64. */
  65. STOPPED,
  66. /**
  67. * The plugin has been updated.
  68. *
  69. * @see ctkPlugin::update()
  70. */
  71. UPDATED,
  72. /**
  73. * The plugin has been uninstalled.
  74. *
  75. * @see ctkPlugin::uninstall()
  76. */
  77. UNINSTALLED,
  78. /**
  79. * The plugin has been resolved.
  80. *
  81. * @see ctkPlugin::RESOLVED
  82. */
  83. RESOLVED,
  84. /**
  85. * The plugin has been unresolved.
  86. *
  87. * @see ctkPlugin::INSTALLED
  88. */
  89. UNRESOLVED,
  90. /**
  91. * The plugin is about to be activated.
  92. * <p>
  93. * The plugin's
  94. * \link ctkPluginActivator::start(ctkPluginContext*) ctkPluginActivator start\endlink method
  95. * is about to be called. This
  96. * event is only delivered to synchronuous slots, which have been registered with
  97. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  98. *
  99. * @see ctkPlugin::start()
  100. */
  101. STARTING,
  102. /**
  103. * The plugin is about to deactivated.
  104. * <p>
  105. * The plugin's
  106. * \link ctkPluginActivator::stop(ctkPluginContext*) ctkPluginActivator stop\endlink method
  107. * is about to be called. This
  108. * event is only delivered to synchronuous slots, which have been registered with
  109. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  110. *
  111. * @see ctkPlugin::stop()
  112. */
  113. STOPPING,
  114. /**
  115. * The plugin will be lazily activated.
  116. * <p>
  117. * The plugin has a \link ctkPluginConstants::ACTIVATION_LAZY lazy activation policy\endlink
  118. * and is waiting to be activated. It is now in the
  119. * \link ctkPlugin::STARTING STARTING\endlink state and has a valid
  120. * <code>ctkPluginContext</code>. This
  121. * event is only delivered to synchronuous slots, which have been registered with
  122. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  123. */
  124. LAZY_ACTIVATION
  125. };
  126. /**
  127. * Default constructor for use with the Qt meta object system.
  128. */
  129. ctkPluginEvent();
  130. ~ctkPluginEvent();
  131. /**
  132. * Can be used to check if this ctkPluginEvent instance is valid,
  133. * or if it has been constructed using the default constructor.
  134. *
  135. * @return <code>true</code> if this event object is valid,
  136. * <code>false</code> otherwise.
  137. */
  138. bool isNull() const;
  139. /**
  140. * Creates a plugin event of the specified type.
  141. *
  142. * @param type The event type.
  143. * @param plugin The plugin which had a lifecycle change.
  144. */
  145. ctkPluginEvent(Type type, QSharedPointer<ctkPlugin> plugin);
  146. ctkPluginEvent(const ctkPluginEvent& other);
  147. ctkPluginEvent& operator=(const ctkPluginEvent& other);
  148. /**
  149. * Returns the plugin which had a lifecycle change.
  150. *
  151. * @return The plugin that had a change occur in its lifecycle.
  152. */
  153. QSharedPointer<ctkPlugin> getPlugin() const;
  154. /**
  155. * Returns the type of lifecyle event. The type values are:
  156. * <ul>
  157. * <li>{@link #INSTALLED}
  158. * <li>{@link #RESOLVED}
  159. * <li>{@link #LAZY_ACTIVATION}
  160. * <li>{@link #STARTING}
  161. * <li>{@link #STARTED}
  162. * <li>{@link #STOPPING}
  163. * <li>{@link #STOPPED}
  164. * <li>{@link #UPDATED}
  165. * <li>{@link #UNRESOLVED}
  166. * <li>{@link #UNINSTALLED}
  167. * </ul>
  168. *
  169. * @return The type of lifecycle event.
  170. */
  171. Type getType() const;
  172. };
  173. Q_DECLARE_METATYPE(ctkPluginEvent)
  174. /**
  175. * \ingroup PluginFramework
  176. * @{
  177. */
  178. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, ctkPluginEvent::Type eventType);
  179. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, const ctkPluginEvent& event);
  180. /** @}*/
  181. #endif // CTKPLUGINEVENT_H