ctkPluginFramework.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 CTKPLUGINFRAMEWORK_H
  16. #define CTKPLUGINFRAMEWORK_H
  17. #include <ctkPluginFrameworkExport.h>
  18. #include "ctkPlugin.h"
  19. #include "ctkPluginFrameworkEvent.h"
  20. class ctkPluginFrameworkContext;
  21. class ctkPluginFrameworkPrivate;
  22. /**
  23. * \ingroup PluginFramework
  24. *
  25. * A %ctkPluginFramework instance. A %ctkPluginFramework is also known as a System %Plugin.
  26. *
  27. * <p>
  28. * %ctkPluginFramework instances are created using a ctkPluginFrameworkFactory. The methods
  29. * of this class can be used to manage and control the created plugin framework
  30. * instance.
  31. *
  32. * @remarks This class is thread safe.
  33. */
  34. class CTK_PLUGINFW_EXPORT ctkPluginFramework : public ctkPlugin
  35. {
  36. Q_DECLARE_PRIVATE(ctkPluginFramework)
  37. Q_DISABLE_COPY(ctkPluginFramework)
  38. public:
  39. /**
  40. * Initialize this %ctkPluginFramework. After calling this method, this %ctkPluginFramework
  41. * must:
  42. * <ul>
  43. * <li>Be in the {@link #STARTING} state.</li>
  44. * <li>Have a valid Plugin Context.</li>
  45. * <li>Be at start level 0.</li>
  46. * <li>Have event handling enabled.</li>
  47. * <li>Have create ctkPlugin objects for all installed plugins.</li>
  48. * <li>Have registered any framework services.</li>
  49. * </ul>
  50. *
  51. * <p>
  52. * This %ctkPluginFramework will not actually be started until {@link #start() start}
  53. * is called.
  54. *
  55. * <p>
  56. * This method does nothing if called when this %ctkPluginFramework is in the
  57. * {@link #STARTING}, {@link #ACTIVE} or {@link #STOPPING} states.
  58. *
  59. * @throws ctkPluginException If this %ctkPluginFramework could not be initialized.
  60. */
  61. void init();
  62. /**
  63. * Wait until this %ctkPluginFramework has completely stopped. The <code>stop</code>
  64. * and <code>update</code> methods perform an asynchronous
  65. * stop of the Framework. This method can be used to wait until the
  66. * asynchronous stop of this Framework has completed. This method will only
  67. * wait if called when this Framework is in the {@link #STARTING},
  68. * {@link #ACTIVE}, or {@link #STOPPING} states. Otherwise it will return
  69. * immediately.
  70. * <p>
  71. * A Framework Event is returned to indicate why this Framework has stopped.
  72. *
  73. * @param timeout Maximum number of milliseconds to wait until this
  74. * Framework has completely stopped. A value of zero will wait
  75. * indefinitely.
  76. * @return A Framework Event indicating the reason this method returned. The
  77. * following <code>ctkPluginFrameworkEvent</code> types may be returned by
  78. * this method.
  79. * <ul>
  80. * <li>{@link ctkPluginFrameworkEvent#FRAMEWORK_STOPPED STOPPED} - This Framework has
  81. * been stopped. </li>
  82. *
  83. * <li>{@link ctkPluginFrameworkEvent#FRAMEWORK_STOPPED_UPDATE STOPPED_UPDATE} - This
  84. * Framework has been updated which has shutdown and will now
  85. * restart.</li>
  86. *
  87. * <li>{@link ctkPluginFrameworkEvent#PLUGIN_ERROR ERROR} - The Framework
  88. * encountered an error while shutting down or an error has occurred
  89. * which forced the framework to shutdown. </li>
  90. *
  91. * <li> {@link ctkPluginFrameworkEvent#FRAMEWORK_WAIT_TIMEDOUT WAIT_TIMEDOUT} - This
  92. * method has timed out and returned before this Framework has
  93. * stopped.</li>
  94. * </ul>
  95. */
  96. ctkPluginFrameworkEvent waitForStop(unsigned long timeout);
  97. /**
  98. * Start this %ctkPluginFramework.
  99. *
  100. * <p>
  101. * The following steps are taken to start this %ctkPluginFramework:
  102. * <ol>
  103. * <li>If this %ctkPluginFramework is not in the {@link #STARTING} state,
  104. * {@link #init() initialize} this %ctkPluginFramework.</li>
  105. * <li>All installed plugins must be started in accordance with each
  106. * plugin's persistent <i>autostart setting</i>. This means some plugins
  107. * will not be started, some will be started with <i>lazy activation</i>
  108. * and some will be started with their <i>declared activation</i> policy.
  109. * Any exceptions that occur during plugin starting must be wrapped in a
  110. * {@link ctkPluginException} and then published as a plugin framework event of type
  111. * {@link ctkPluginFrameworkEvent::PLUGIN_ERROR}</li>
  112. * <li>This %PluinFramework's state is set to {@link #ACTIVE}.</li>
  113. * <li>A plugin framework event of type {@link ctkPluginFrameworkEvent::FRAMEWORK_STARTED} is fired</li>
  114. * </ol>
  115. *
  116. * @param options Ignored. There are no start options for the %ctkPluginFramework.
  117. * @throws ctkPluginException If this %ctkPluginFramework could not be started.
  118. */
  119. void start(const ctkPlugin::StartOptions& options = 0);
  120. /**
  121. * Stop this %ctkPluginFramework.
  122. *
  123. * <p>
  124. * The method returns immediately to the caller after initiating the
  125. * following steps to be taken on another thread.
  126. * <ol>
  127. * <li>This Framework's state is set to {@link #STOPPING}.</li>
  128. * <li>All installed plugins must be stopped without changing each plugin's
  129. * persistent <i>autostart setting</i>. If this Framework implements the
  130. * optional <i>Start Level Service Specification</i>, then the start level
  131. * of this Framework is moved to start level zero (0), as described in the
  132. * <i>Start Level Service Specification</i>. Any exceptions that occur
  133. * during plugin stopping must be wrapped in a {@link ctkPluginException} and
  134. * then published as a framework event of type {@link ctkPluginFrameworkEvent#PLUGIN_ERROR}</li>
  135. * <li>Unregister all services registered by this Framework.</li>
  136. * <li>Event handling is disabled.</li>
  137. * <li>This Framework's state is set to {@link #RESOLVED}.</li>
  138. * <li>All resources held by this Framework are released. This includes
  139. * threads, loaded libraries, open files, etc.</li>
  140. * <li>Notify all threads that are waiting at {@link #waitForStop(unsigned long)
  141. * waitForStop} that the stop operation has completed.</li>
  142. * </ol>
  143. * <p>
  144. * After being stopped, this Framework may be discarded, initialized or
  145. * started.
  146. *
  147. * @param options Ignored. There are no stop options for the Framework.
  148. * @throws ctkPluginException If stopping this Framework could not be
  149. * initiated.
  150. * @see "Start Level Service Specification"
  151. */
  152. void stop(const StopOptions& options = 0);
  153. /**
  154. * The %ctkPluginFramework cannot be uninstalled.
  155. *
  156. * <p>
  157. * This method always throws a ctkPluginException.
  158. *
  159. * @throws ctkPluginException This Framework cannot be uninstalled.
  160. */
  161. void uninstall();
  162. /**
  163. * @see ctkPlugin::getHeaders()
  164. */
  165. QHash<QString, QString> getHeaders();
  166. /**
  167. * @see ctkPlugin::getResourceList()
  168. */
  169. QStringList getResourceList(const QString& path) const;
  170. /**
  171. * @see ctkPlugin::getResource()
  172. */
  173. QByteArray getResource(const QString& path) const;
  174. protected:
  175. friend class ctkPluginFrameworkContext;
  176. ctkPluginFramework();
  177. };
  178. #endif // CTKPLUGINFRAMEWORK_H