ctkPluginEvent.h 5.5 KB

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