ctkPluginFrameworkEvent.h 5.7 KB

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