ctkPluginFrameworkEvent.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 <QObject>
  18. #include <QSharedDataPointer>
  19. #include "CTKPluginFrameworkExport.h"
  20. namespace ctk {
  21. class Plugin;
  22. class PluginFrameworkEventData;
  23. /**
  24. * A general event from the Framework.
  25. *
  26. * <p>
  27. * <code>PluginFrameworkEvent</code> objects are delivered to slots connected
  28. * <code>FrameworkListener</code>s when a general event occurs within the plugin
  29. * environment. A type code is used to identify the event type for future
  30. * extendability.
  31. *
  32. * @see PluginContext#connectFrameworkListener
  33. * @see EventBus
  34. */
  35. class CTK_PLUGINFW_EXPORT PluginFrameworkEvent : public QObject
  36. {
  37. Q_OBJECT
  38. Q_PROPERTY(Type type READ getType CONSTANT)
  39. Q_PROPERTY(Plugin* plugin READ getPlugin CONSTANT)
  40. Q_PROPERTY(QString errorString READ getErrorString CONSTANT)
  41. Q_ENUMS(Type)
  42. QSharedDataPointer<PluginFrameworkEventData> d;
  43. public:
  44. enum Type {
  45. /**
  46. * The Framework has started.
  47. *
  48. * <p>
  49. * This event is fired when the Framework has started after all installed
  50. * plugins that are marked to be started have been started and the Framework
  51. * has reached the initial start level. The source of this event is the
  52. * System Plugin.
  53. */
  54. STARTED,
  55. /**
  56. * An error has occurred.
  57. *
  58. * <p>
  59. * There was an error associated with a plugin.
  60. */
  61. ERROR,
  62. /**
  63. * A warning has occurred.
  64. *
  65. * <p>
  66. * There was a warning associated with a plugin.
  67. */
  68. WARNING,
  69. /**
  70. * An informational event has occurred.
  71. *
  72. * <p>
  73. * There was an informational event associated with a plugin.
  74. */
  75. INFO,
  76. /**
  77. * The Framework has stopped.
  78. *
  79. * <p>
  80. * This event is fired when the Framework has been stopped because of a stop
  81. * operation on the system plugin. The source of this event is the System
  82. * Plugin.
  83. */
  84. STOPPED,
  85. /**
  86. * The Framework has stopped during update.
  87. *
  88. * <p>
  89. * This event is fired when the Framework has been stopped because of an
  90. * update operation on the system plugin. The Framework will be restarted
  91. * after this event is fired. The source of this event is the System Plugin.
  92. */
  93. STOPPED_UPDATE,
  94. /**
  95. * The Framework did not stop before the wait timeout expired.
  96. *
  97. * <p>
  98. * This event is fired when the Framework did not stop before the wait
  99. * timeout expired. The source of this event is the System Plugin.
  100. */
  101. WAIT_TIMEDOUT
  102. };
  103. /**
  104. * Default constructor for use with the Qt meta object system.
  105. */
  106. PluginFrameworkEvent();
  107. /**
  108. * Creates a Framework event regarding the specified plugin and exception.
  109. *
  110. * @param type The event type.
  111. * @param plugin The event source.
  112. * @param fwException The related exception.
  113. */
  114. PluginFrameworkEvent(Type type, Plugin* plugin, const std::exception& fwException);
  115. /**
  116. * Creates a Framework event regarding the specified plugin.
  117. *
  118. * @param type The event type.
  119. * @param plugin The event source.
  120. */
  121. PluginFrameworkEvent(Type type, Plugin* plugin);
  122. PluginFrameworkEvent(const PluginFrameworkEvent& other);
  123. /**
  124. * Returns the exception error string related to this event.
  125. *
  126. * @return The related error string.
  127. */
  128. QString getErrorString() const;
  129. /**
  130. * Returns the plugin associated with the event. This plugin is also the
  131. * source of the event.
  132. *
  133. * @return The plugin associated with the event.
  134. */
  135. Plugin* getPlugin() const;
  136. /**
  137. * Returns the type of framework event.
  138. * <p>
  139. * The type values are:
  140. * <ul>
  141. * <li>{@link #STARTED}
  142. * <li>{@link #ERROR}
  143. * <li>{@link #WARNING}
  144. * <li>{@link #INFO}
  145. * <li>{@link #STARTLEVEL_CHANGED}
  146. * <li>{@link #STOPPED}
  147. * <li>{@link #STOPPED_UPDATE}
  148. * <li>{@link #WAIT_TIMEDOUT}
  149. * </ul>
  150. *
  151. * @return The type of state change.
  152. */
  153. Type getType() const;
  154. };
  155. class PluginFrameworkEventData : public QSharedData
  156. {
  157. public:
  158. PluginFrameworkEventData(PluginFrameworkEvent::Type type, Plugin* plugin, const QString& exc)
  159. : plugin(plugin), errorString(exc), type(type)
  160. {
  161. }
  162. PluginFrameworkEventData(const PluginFrameworkEventData& other)
  163. : QSharedData(other), plugin(other.plugin), errorString(other.errorString),
  164. type(other.type)
  165. {
  166. }
  167. /**
  168. * Plugin related to the event.
  169. */
  170. Plugin* const plugin;
  171. /**
  172. * Exception related to the event.
  173. */
  174. const QString errorString;
  175. /**
  176. * Type of event.
  177. */
  178. const PluginFrameworkEvent::Type type;
  179. };
  180. }
  181. #endif // CTKPLUGINFRAMEWORKEVENT_H