ctkPluginFrameworkEvent.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 CTKPLUGINFRAMEWORKEVENT_H
  16. #define CTKPLUGINFRAMEWORKEVENT_H
  17. #include <QSharedDataPointer>
  18. #include <QSharedPointer>
  19. #include <QMetaType>
  20. #include "ctkPluginFrameworkExport.h"
  21. class ctkException;
  22. class ctkPlugin;
  23. class ctkPluginFrameworkEventData;
  24. /**
  25. * \ingroup PluginFramework
  26. *
  27. * A general event from the Framework.
  28. *
  29. * <p>
  30. * <code>ctkPluginFrameworkEvent</code> objects are delivered to slots connected
  31. * via ctkPluginContext::connectFrameworkListener when a general event occurs
  32. * within the plugin environment.
  33. * A type code is used to identify the event type for future extendability.
  34. *
  35. * @see ctkPluginContext#connectFrameworkListener
  36. * @see ctkEventBus
  37. */
  38. class CTK_PLUGINFW_EXPORT ctkPluginFrameworkEvent
  39. {
  40. QSharedDataPointer<ctkPluginFrameworkEventData> d;
  41. public:
  42. enum Type {
  43. /**
  44. * The Framework has started.
  45. *
  46. * <p>
  47. * This event is fired when the Framework has started after all installed
  48. * plugins that are marked to be started have been started and the Framework
  49. * has reached the initial start level. The source of this event is the
  50. * System Plugin.
  51. */
  52. FRAMEWORK_STARTED,
  53. /**
  54. * An error has occurred.
  55. *
  56. * <p>
  57. * There was an error associated with a plugin.
  58. */
  59. PLUGIN_ERROR,
  60. /**
  61. * A warning has occurred.
  62. *
  63. * <p>
  64. * There was a warning associated with a plugin.
  65. */
  66. PLUGIN_WARNING,
  67. /**
  68. * An informational event has occurred.
  69. *
  70. * <p>
  71. * There was an informational event associated with a plugin.
  72. */
  73. PLUGIN_INFO,
  74. /**
  75. * The Framework has stopped.
  76. *
  77. * <p>
  78. * This event is fired when the Framework has been stopped because of a stop
  79. * operation on the system plugin. The source of this event is the System
  80. * Plugin.
  81. */
  82. FRAMEWORK_STOPPED,
  83. /**
  84. * The Framework has stopped during update.
  85. *
  86. * <p>
  87. * This event is fired when the Framework has been stopped because of an
  88. * update operation on the system plugin. The Framework will be restarted
  89. * after this event is fired. The source of this event is the System Plugin.
  90. */
  91. FRAMEWORK_STOPPED_UPDATE,
  92. /**
  93. * The Framework did not stop before the wait timeout expired.
  94. *
  95. * <p>
  96. * This event is fired when the Framework did not stop before the wait
  97. * timeout expired. The source of this event is the System Plugin.
  98. */
  99. FRAMEWORK_WAIT_TIMEDOUT
  100. };
  101. /**
  102. * Default constructor for use with the Qt meta object system.
  103. */
  104. ctkPluginFrameworkEvent();
  105. ~ctkPluginFrameworkEvent();
  106. /**
  107. * Can be used to check if this ctkPluginFrameworkEvent instance is valid,
  108. * or if it has been constructed using the default constructor.
  109. *
  110. * @return <code>true</code> if this event object is valid,
  111. * <code>false</code> otherwise.
  112. */
  113. bool isNull() const;
  114. /**
  115. * Creates a Framework event regarding the specified plugin and exception.
  116. *
  117. * @param type The event type.
  118. * @param plugin The event source.
  119. * @param fwException The related exception.
  120. */
  121. ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin, const ctkException& fwException);
  122. /**
  123. * Creates a Framework event regarding the specified plugin.
  124. *
  125. * @param type The event type.
  126. * @param plugin The event source.
  127. */
  128. ctkPluginFrameworkEvent(Type type, QSharedPointer<ctkPlugin> plugin);
  129. ctkPluginFrameworkEvent(const ctkPluginFrameworkEvent& other);
  130. ctkPluginFrameworkEvent& operator=(const ctkPluginFrameworkEvent& other);
  131. /**
  132. * Returns the exception error string related to this event.
  133. *
  134. * @return The related error string.
  135. */
  136. QString getErrorString() const;
  137. /**
  138. * Returns the plugin associated with the event. This plugin is also the
  139. * source of the event.
  140. *
  141. * @return The plugin associated with the event.
  142. */
  143. QSharedPointer<ctkPlugin> getPlugin() const;
  144. /**
  145. * Returns the type of framework event.
  146. * <p>
  147. * The type values are:
  148. * <ul>
  149. * <li>{@link #FRAMEWORK_STARTED}
  150. * <li>{@link #PLUGIN_ERROR}
  151. * <li>{@link #PLUGIN_WARNING}
  152. * <li>{@link #PLUGIN_INFO}
  153. * <li>{@link #FRAMEWORK_STOPPED}
  154. * <li>{@link #FRAMEWORK_STOPPED_UPDATE}
  155. * <li>{@link #FRAMEWORK_WAIT_TIMEDOUT}
  156. * </ul>
  157. *
  158. * @return The type of state change.
  159. */
  160. Type getType() const;
  161. };
  162. Q_DECLARE_METATYPE(ctkPluginFrameworkEvent);
  163. /**
  164. * \ingroup PluginFramework
  165. * @{
  166. */
  167. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, ctkPluginFrameworkEvent::Type type);
  168. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug dbg, const ctkPluginFrameworkEvent& event);
  169. /** @} */
  170. #endif // CTKPLUGINFRAMEWORKEVENT_H