ctkPluginEvent.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. * An event from the Framework describing a plugin lifecycle change.
  25. * <p>
  26. * <code>ctkPluginEvent</code> objects are delivered to slots connected
  27. * via ctkPluginContext::connectPluginListener() when a change
  28. * occurs in a plugins's lifecycle. A type code is used to identify
  29. * the event type for future extendability.
  30. *
  31. * @see ctkPluginContext#connectPluginListener
  32. */
  33. class CTK_PLUGINFW_EXPORT ctkPluginEvent
  34. {
  35. QSharedDataPointer<ctkPluginEventData> d;
  36. public:
  37. enum Type {
  38. /**
  39. * The plugin has been installed.
  40. *
  41. * @see ctkPluginContext::installBundle(const QString&)
  42. */
  43. INSTALLED,
  44. /**
  45. * The plugin has been started.
  46. * <p>
  47. * The plugin's
  48. * \link ctkPluginActivator::start(ctkPluginContext*) ctkPluginActivator start\endlink method
  49. * has been executed.
  50. *
  51. * @see ctkPlugin::start()
  52. */
  53. STARTED,
  54. /**
  55. * The plugin has been stopped.
  56. * <p>
  57. * The plugin's
  58. * \link ctkPluginActivator::stop(ctkPluginContext*) ctkPluginActivator stop\endlink method
  59. * has been executed.
  60. *
  61. * @see ctkPlugin::stop()
  62. */
  63. STOPPED,
  64. /**
  65. * The plugin has been updated.
  66. *
  67. * @see ctkPlugin::update()
  68. */
  69. UPDATED,
  70. /**
  71. * The plugin has been uninstalled.
  72. *
  73. * @see ctkPlugin::uninstall()
  74. */
  75. UNINSTALLED,
  76. /**
  77. * The plugin has been resolved.
  78. *
  79. * @see ctkPlugin::RESOLVED
  80. */
  81. RESOLVED,
  82. /**
  83. * The plugin has been unresolved.
  84. *
  85. * @see ctkPlugin::INSTALLED
  86. */
  87. UNRESOLVED,
  88. /**
  89. * The plugin is about to be activated.
  90. * <p>
  91. * The plugin's
  92. * \link ctkPluginActivator::start(ctkPluginContext*) ctkPluginActivator start\endlink method
  93. * is about to be called. This
  94. * event is only delivered to synchronuous slots, which have been registered with
  95. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  96. *
  97. * @see ctkPlugin::start()
  98. */
  99. STARTING,
  100. /**
  101. * The plugin is about to deactivated.
  102. * <p>
  103. * The plugin's
  104. * \link ctkPluginActivator::stop(ctkPluginContext*) ctkPluginActivator stop\endlink method
  105. * is about to be called. This
  106. * event is only delivered to synchronuous slots, which have been registered with
  107. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  108. *
  109. * @see ctkPlugin::stop()
  110. */
  111. STOPPING,
  112. /**
  113. * The plugin will be lazily activated.
  114. * <p>
  115. * The plugin has a \link ctkPluginConstant::ACTIVATION_LAZY lazy activation policy\endlink
  116. * and is waiting to be activated. It is now in the
  117. * \link ctkPlugin::STARTING STARTING\endlink state and has a valid
  118. * <code>ctkPluginContext</code>. This
  119. * event is only delivered to synchronuous slots, which have been registered with
  120. * Qt::DirectConnection or Qt::BlockingQueuedConnection in ctkPluginContext::connectPluginListener().
  121. */
  122. LAZY_ACTIVATION
  123. };
  124. /**
  125. * Default constructor for use with the Qt meta object system.
  126. */
  127. ctkPluginEvent();
  128. ~ctkPluginEvent();
  129. /**
  130. * Can be used to check if this ctkPluginEvent instance is valid,
  131. * or if it has been constructed using the default constructor.
  132. *
  133. * @return <code>true</code> if this event object is valid,
  134. * <code>false</code> otherwise.
  135. */
  136. bool isNull() const;
  137. /**
  138. * Creates a plugin event of the specified type.
  139. *
  140. * @param type The event type.
  141. * @param plugin The plugin which had a lifecycle change.
  142. */
  143. ctkPluginEvent(Type type, QSharedPointer<ctkPlugin> plugin);
  144. ctkPluginEvent(const ctkPluginEvent& other);
  145. ctkPluginEvent& operator=(const ctkPluginEvent& other);
  146. /**
  147. * Returns the plugin which had a lifecycle change.
  148. *
  149. * @return The plugin that had a change occur in its lifecycle.
  150. */
  151. QSharedPointer<ctkPlugin> getPlugin() const;
  152. /**
  153. * Returns the type of lifecyle event. The type values are:
  154. * <ul>
  155. * <li>{@link #INSTALLED}
  156. * <li>{@link #RESOLVED}
  157. * <li>{@link #LAZY_ACTIVATION}
  158. * <li>{@link #STARTING}
  159. * <li>{@link #STARTED}
  160. * <li>{@link #STOPPING}
  161. * <li>{@link #STOPPED}
  162. * <li>{@link #UPDATED}
  163. * <li>{@link #UNRESOLVED}
  164. * <li>{@link #UNINSTALLED}
  165. * </ul>
  166. *
  167. * @return The type of lifecycle event.
  168. */
  169. Type getType() const;
  170. };
  171. Q_DECLARE_METATYPE(ctkPluginEvent)
  172. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, ctkPluginEvent::Type eventType);
  173. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, const ctkPluginEvent& event);
  174. #endif // CTKPLUGINEVENT_H