ctkPlugin.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  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 CTKPLUGIN_H
  16. #define CTKPLUGIN_H
  17. #include <QHash>
  18. #include <QWeakPointer>
  19. #include <QMetaType>
  20. #include <QUrl>
  21. #include "ctkVersion.h"
  22. #include "ctkPluginLocalization.h"
  23. #include "ctkPluginConstants.h"
  24. #include "service/log/ctkLogStream.h"
  25. class ctkPluginContext;
  26. class ctkPluginArchive;
  27. class ctkPluginFrameworkContext;
  28. class ctkPluginPrivate;
  29. /**
  30. * \ingroup PluginFramework
  31. *
  32. * An installed plugin in the Framework.
  33. *
  34. * <p>
  35. * A <code>%ctkPlugin</code> object is the access point to define the lifecycle of
  36. * an installed plugin. Each plugin installed in the plugin environment must have
  37. * an associated <code>%ctkPlugin</code> object.
  38. *
  39. * <p>
  40. * A plugin must have a unique identity, a <code>long</code>, chosen by the
  41. * Framework. This identity must not change during the lifecycle of a plugin,
  42. * even when the plugin is updated. Uninstalling and then reinstalling the
  43. * plugin must create a new unique identity.
  44. *
  45. * <p>
  46. * A plugin can be in one of six states:
  47. * <ul>
  48. * <li>{@link #UNINSTALLED}
  49. * <li>{@link #INSTALLED}
  50. * <li>{@link #RESOLVED}
  51. * <li>{@link #STARTING}
  52. * <li>{@link #STOPPING}
  53. * <li>{@link #ACTIVE}
  54. * </ul>
  55. * <p>
  56. * They can be ORed together using the <code>States</code> type to
  57. * determine if a plugin is in one of the valid states.
  58. *
  59. * <p>
  60. * A plugin should only execute code when its state is one of
  61. * <code>STARTING</code>, <code>ACTIVE</code>, or <code>STOPPING</code>.
  62. * An <code>UNINSTALLED</code> plugin can not be set to another state; it is a
  63. * zombie and can only be reached because references are kept somewhere.
  64. *
  65. * <p>
  66. * The Framework is the only entity that is allowed to create
  67. * <code>%ctkPlugin</code> objects, and these objects are only valid within the
  68. * Framework that created them.
  69. *
  70. * @remarks This class is thread safe.
  71. */
  72. class CTK_PLUGINFW_EXPORT ctkPlugin {
  73. Q_DECLARE_PRIVATE(ctkPlugin)
  74. Q_DISABLE_COPY(ctkPlugin)
  75. public:
  76. enum State {
  77. /**
  78. * The plugin is uninstalled and may not be used.
  79. *
  80. * <p>
  81. * The <code>UNINSTALLED</code> state is only visible after a plugin is
  82. * uninstalled; the plugin is in an unusable state but references to the
  83. * <code>%ctkPlugin</code> object may still be available and used for
  84. * introspection.
  85. */
  86. UNINSTALLED = 0x00000001,
  87. /**
  88. * The plugin is installed but not yet resolved.
  89. *
  90. * <p>
  91. * A plugin is in the <code>INSTALLED</code> state when it has been
  92. * installed in the Framework but is not or cannot be resolved.
  93. * <p>
  94. * This state is visible if the plugin's code dependencies are not resolved.
  95. * The Framework may attempt to resolve an <code>INSTALLED</code> plugin's
  96. * code dependencies and move the plugin to the <code>RESOLVED</code>
  97. * state.
  98. */
  99. INSTALLED = 0x00000002,
  100. /**
  101. * The plugin is resolved and is able to be started.
  102. *
  103. * <p>
  104. * A plugin is in the <code>RESOLVED</code> state when the Framework has
  105. * successfully resolved the plugin's code dependencies. These dependencies
  106. * include:
  107. * <ul>
  108. * <li>The plugin's required plugin dependencies from its
  109. * {@link ctkPluginConstants::REQUIRE_PLUGIN} Manifest header.
  110. * </ul>
  111. * <p>
  112. * Note that the plugin is not active yet. A plugin must be put in the
  113. * <code>RESOLVED</code> state before it can be started. The Framework may
  114. * attempt to resolve a plugin at any time.
  115. */
  116. RESOLVED = 0x00000004,
  117. /**
  118. * The plugin is in the process of starting.
  119. *
  120. * <p>
  121. * A plugin is in the <code>STARTING</code> state when its
  122. * {@link #start(const StartOptions&) start} method is active. A plugin must be in this
  123. * state when the plugin's {@link ctkPluginActivator::start} method is called. If the
  124. * <code>ctkPluginActivator::start</code> method completes without exception,
  125. * then the plugin has successfully started and must move to the
  126. * <code>ACTIVE</code> state.
  127. * <p>
  128. * If the plugin does not have a
  129. * {@link ctkPluginConstants#ACTIVATION_EAGER eager activation policy}, then the
  130. * plugin may remain in this state for some time until the activation is
  131. * triggered.
  132. */
  133. STARTING = 0x00000008,
  134. /**
  135. * The plugin is in the process of stopping.
  136. *
  137. * <p>
  138. * A plugin is in the <code>STOPPING</code> state when its
  139. * {@link #stop(const StopOptions&) stop} method is active. A plugin must be in this state
  140. * when the plugin's {@link ctkPluginActivator::stop} method is called. When the
  141. * <code>ctkPluginActivator::stop</code> method completes the plugin is
  142. * stopped and must move to the <code>RESOLVED</code> state.
  143. */
  144. STOPPING = 0x00000010,
  145. /**
  146. * The plugin is now running.
  147. *
  148. * <p>
  149. * A plugin is in the <code>ACTIVE</code> state when it has been
  150. * successfully started and activated.
  151. */
  152. ACTIVE = 0x00000020
  153. };
  154. /**
  155. * Represents an ORed combination of plugin states.
  156. *
  157. * @see #State
  158. */
  159. Q_DECLARE_FLAGS(States, State)
  160. enum StartOption {
  161. /**
  162. * The plugin start operation is transient and the persistent autostart
  163. * setting of the plugin is not modified.
  164. *
  165. * <p>
  166. * This option may be set when calling {@link #start(const StartOptions&)} to notify the
  167. * framework that the autostart setting of the plugin must not be modified.
  168. * If this option is not set, then the autostart setting of the plugin is
  169. * modified.
  170. *
  171. * @see #start(const StartOptions&)
  172. */
  173. START_TRANSIENT = 0x00000001,
  174. /**
  175. * The plugin start operation must activate the plugin according to the
  176. * plugin's declared
  177. * {@link ctkPluginConstants#PLUGIN_ACTIVATIONPOLICY activation policy}.
  178. *
  179. * <p>
  180. * This bit may be set when calling {@link #start(const StartOptions&)} to notify the
  181. * framework that the plugin must be activated using the plugin's declared
  182. * activation policy.
  183. *
  184. * @see ctkPluginConstants#PLUGIN_ACTIVATIONPOLICY
  185. * @see #start(const StartOptions&)
  186. */
  187. START_ACTIVATION_POLICY = 0x00000002
  188. };
  189. /**
  190. * Represents an ORed combination of start options.
  191. *
  192. * @see #StartOption
  193. */
  194. Q_DECLARE_FLAGS(StartOptions, StartOption)
  195. enum StopOption {
  196. /**
  197. * The plugin stop is transient and the persistent autostart setting of the
  198. * plugin is not modified.
  199. *
  200. * <p>
  201. * This option may be set when calling {@link #stop(const StopOptions&)} to notify the
  202. * framework that the autostart setting of the plugin must not be modified.
  203. * If this option is not set, then the autostart setting of the plugin is
  204. * modified.
  205. *
  206. * @see #stop(const StopOptions&)
  207. */
  208. STOP_TRANSIENT = 0x00000001
  209. };
  210. /**
  211. * Represents an ORed combination of stop options.
  212. *
  213. * @see #StopOption
  214. */
  215. Q_DECLARE_FLAGS(StopOptions, StopOption)
  216. virtual ~ctkPlugin();
  217. /**
  218. * Returns this plugin's current state.
  219. *
  220. * <p>
  221. * A plugin can be in only one state at any time.
  222. *
  223. * @return An element of <code>UNINSTALLED</code>,<code>INSTALLED</code>,
  224. * <code>RESOLVED</code>,<code>STARTING</code>,
  225. * <code>STOPPING</code>,<code>ACTIVE</code>.
  226. */
  227. State getState() const;
  228. /**
  229. * Starts this plugin.
  230. *
  231. * <p>
  232. * If this plugin's state is <code>UNINSTALLED</code> then an
  233. * <code>ctkIllegalStateException</code> is thrown.
  234. * <p>
  235. * The following steps are required to start this bundle:
  236. * <ol>
  237. * <li>If this plugin is in the process of being activated or deactivated
  238. * then this method must wait for activation or deactivation to complete
  239. * before continuing. If this does not occur in a reasonable time, a
  240. * <code>ctkPluginException</code> is thrown to indicate this plugin was unable
  241. * to be started.
  242. *
  243. * <li>If this plugin's state is <code>ACTIVE</code> then this method
  244. * returns immediately.
  245. *
  246. * <li>If the {@link #START_TRANSIENT} option is not set then set this
  247. * plugin's autostart setting to <em>Started with declared activation</em>
  248. * if the {@link #START_ACTIVATION_POLICY} option is set or
  249. * <em>Started with lazy activation</em> if not set. When the Framework is
  250. * restarted and this plugin's autostart setting is not <em>Stopped</em>,
  251. * this plugin must be automatically started.
  252. *
  253. * <li>If this plugin's state is not <code>RESOLVED</code>, an attempt is
  254. * made to resolve this plugin. If the Framework cannot resolve this plugin,
  255. * a <code>ctkPluginException</code> is thrown.
  256. *
  257. * <li>If the {@link #START_ACTIVATION_POLICY} option is not set then:
  258. * <ul>
  259. * <li>If this plugin's state is <code>STARTING</code> then this method
  260. * returns immediately.
  261. * <li>This plugin's state is set to <code>STARTING</code>.
  262. * <li>A plugin event of type {@link ctkPluginEvent::LAZY_ACTIVATION} is fired.
  263. * <li>This method returns immediately and the remaining steps will be
  264. * followed when this plugin's activation is later triggered.
  265. * </ul>
  266. * If the {@link #START_ACTIVATION_POLICY} option is set and this
  267. * plugin's declared activation policy is {@link ctkPluginConstants#ACTIVATION_EAGER
  268. * eager} then:
  269. * <i></i>
  270. * <li>This plugin's state is set to <code>STARTING</code>.
  271. *
  272. * <li>A plugin event of type {@link ctkPluginEvent::STARTING} is fired.
  273. *
  274. * <li>The {@link ctkPluginActivator::start} method of this plugin's
  275. * <code>ctkPluginActivator</code>, is called. If the
  276. * <code>ctkPluginActivator</code> throws an exception then:
  277. * <ul>
  278. * <li>This plugin's state is set to <code>STOPPING</code>.
  279. * <li>A plugin event of type {@link ctkPluginEvent::STOPPING} is fired.
  280. * <li>Any services registered by this plugin must be unregistered.
  281. * <li>Any services used by this plugin must be released.
  282. * <li>Any listeners registered by this plugin must be removed.
  283. * <li>This plugin's state is set to <code>RESOLVED</code>.
  284. * <li>A plugin event of type {@link ctkPluginEvent::STOPPED} is fired.
  285. * <li>A <code>ctkPluginException</code> is then thrown.
  286. * </ul>
  287. * <i></i>
  288. * <li>If this plugin's state is <code>UNINSTALLED</code>, because this
  289. * plugin was uninstalled while the <code>ctkPluginActivator::start</code>
  290. * method was running, a <code>ctkPluginException</code> is thrown.
  291. *
  292. * <li>This plugin's state is set to <code>ACTIVE</code>.
  293. *
  294. * <li>A plugin event of type {@link ctkPluginEvent::STARTED} is fired.
  295. * </ol>
  296. *
  297. * <b>Preconditions </b>
  298. * <ul>
  299. * <li><code>getState()</code> in { <code>INSTALLED</code>,
  300. * <code>RESOLVED</code>, <code>STARTING</code> }
  301. * or { <code>INSTALLED</code>, <code>RESOLVED</code> }
  302. * if this plugin has a eager activation policy.
  303. * </ul>
  304. * <b>Postconditions, no exceptions thrown </b>
  305. * <ul>
  306. * <li>Plugin autostart setting is modified unless the
  307. * {@link #START_TRANSIENT} option was set.
  308. * <li><code>getState()</code> in { <code>ACTIVE</code> }
  309. * if the eager activation policy was used.
  310. * <li><code>ctkPluginActivator::start()</code> has been called and did not
  311. * throw an exception if the eager policy was used.
  312. * </ul>
  313. * <b>Postconditions, when an exception is thrown </b>
  314. * <ul>
  315. * <li>Depending on when the exception occurred, plugin autostart setting is
  316. * modified unless the {@link #START_TRANSIENT} option was set.
  317. * <li><code>getState()</code> not in { <code>STARTING</code>,
  318. * <code>ACTIVE</code> }.
  319. * </ul>
  320. *
  321. * @param options The options for starting this plugin. See
  322. * {@link #START_TRANSIENT} and {@link #START_ACTIVATION_POLICY}. The
  323. * Framework must ignore unrecognized options.
  324. * @throws ctkPluginException If this plugin could not be started. This could
  325. * be because a code dependency could not be resolved or the
  326. * <code>ctkPluginActivator</code> could not be loaded or
  327. * threw an exception.
  328. * @throws ctkIllegalStateException If this plugin has been uninstalled or this
  329. * plugin tries to change its own state.
  330. */
  331. virtual void start(const StartOptions& options = START_ACTIVATION_POLICY);
  332. /**
  333. * Stops this plugin.
  334. *
  335. * <p>
  336. * The following steps are required to stop a plugin:
  337. * <ol>
  338. * <li>If this plugin's state is <code>UNINSTALLED</code> then an
  339. * <code>ctkIllegalStateException</code> is thrown.
  340. *
  341. * <li>If this plugin is in the process of being activated or deactivated
  342. * then this method must wait for activation or deactivation to complete
  343. * before continuing. If this does not occur in a reasonable time, a
  344. * <code>ctkPluginException</code> is thrown to indicate this plugin was unable
  345. * to be stopped.
  346. * <li>If the {@link #STOP_TRANSIENT} option is not set then then set this
  347. * plugin's persistent autostart setting to <em>Stopped</em>. When the
  348. * Framework is restarted and this plugin's autostart setting is
  349. * <em>Stopped</em>, this bundle must not be automatically started.
  350. *
  351. * <li>If this plugin's state is not <code>STARTING</code> or
  352. * <code>ACTIVE</code> then this method returns immediately.
  353. *
  354. * <li>This plugin's state is set to <code>STOPPING</code>.
  355. *
  356. * <li>A plugin event of type {@link ctkPluginEvent::STOPPING} is fired.
  357. *
  358. * <li>If this plugin's state was <code>ACTIVE</code> prior to setting the
  359. * state to <code>STOPPING</code>, the {@link ctkPluginActivator#stop} method
  360. * of this plugin's <code>ctkPluginActivator</code> is
  361. * called. If that method throws an exception, this method must continue to
  362. * stop this plugin and a <code>ctkPluginException</code> must be thrown after
  363. * completion of the remaining steps.
  364. *
  365. * <li>Any services registered by this plugin must be unregistered.
  366. * <li>Any services used by this plugin must be released.
  367. * <li>Any listeners registered by this plugin must be removed.
  368. *
  369. * <li>If this plugin's state is <code>UNINSTALLED</code>, because this
  370. * plugin was uninstalled while the <code>ctkPluginActivator::stop</code> method
  371. * was running, a <code>ctkPluginException</code> must be thrown.
  372. *
  373. * <li>This plugin's state is set to <code>RESOLVED</code>.
  374. *
  375. * <li>A plugin event of type {@link ctkPluginEvent::STOPPED} is fired.
  376. * </ol>
  377. *
  378. * <b>Preconditions </b>
  379. * <ul>
  380. * <li><code>getState()</code> in { <code>ACTIVE</code> }.
  381. * </ul>
  382. * <b>Postconditions, no exceptions thrown </b>
  383. * <ul>
  384. * <li>Plugin autostart setting is modified unless the
  385. * {@link #STOP_TRANSIENT} option was set.
  386. * <li><code>getState()</code> not in &#123; <code>ACTIVE</code>,
  387. * <code>STOPPING</code> &#125;.
  388. * <li><code>ctkPluginActivator::stop</code> has been called and did not throw
  389. * an exception.
  390. * </ul>
  391. * <b>Postconditions, when an exception is thrown </b>
  392. * <ul>
  393. * <li>Plugin autostart setting is modified unless the
  394. * {@link #STOP_TRANSIENT} option was set.
  395. * </ul>
  396. *
  397. * @param options The options for stoping this bundle. See
  398. * {@link #STOP_TRANSIENT}.
  399. * @throws ctkPluginException If this plugin's <code>ctkPluginActivator</code>
  400. * threw an exception.
  401. * @throws ctkIllegalStateException If this plugin has been uninstalled or this
  402. * plugin tries to change its own state.
  403. */
  404. virtual void stop(const StopOptions& options = 0);
  405. /**
  406. * Updates this plugin from a <code>QUrl</code>.
  407. *
  408. * <p>
  409. * If the specified <code>QURl</code> is <code>empty</code>, the
  410. * Framework creates the <code>QUrl</code> from which to read the
  411. * updated plugin by interpreting, in an implementation dependent manner,
  412. * this plugin's {@link ctkPluginConstants#PLUGIN_UPDATELOCATION
  413. * Plugin-UpdateLocation} Manifest header, if present, or this plugin's
  414. * original location.
  415. *
  416. * <p>
  417. * If this plugin's state is <code>ACTIVE</code>, it must be stopped before
  418. * the update and started after the update successfully completes.
  419. *
  420. * <p>
  421. * If this plugin has exported any classes that are used by another
  422. * plugin, these classes remain available until the Framework is relaunched.
  423. *
  424. * <p>
  425. * The following steps are required to update a plugin:
  426. * <ol>
  427. * <li>If this plugin's state is <code>UNINSTALLED</code> then an
  428. * <code>ctkIllegalStateException</code> is thrown.
  429. *
  430. * <li>If this plugin's state is <code>ACTIVE</code>, <code>STARTING</code>
  431. * or <code>STOPPING</code>, this plugin is stopped as described in the
  432. * <code>ctkPlugin::stop()</code> method. If <code>ctkPlugin::stop()</code> throws an
  433. * exception, the exception is rethrown terminating the update.
  434. *
  435. * <li>The updated version of this plugin is read from the URL and
  436. * installed. If the Framework is unable to install the updated version of
  437. * this plugin, the original version of this plugin is restored and a
  438. * <code>ctkPluginException</code> is thrown after completion of the
  439. * remaining steps.
  440. *
  441. * <li>This plugin's state is set to <code>INSTALLED</code>.
  442. *
  443. * <li>If the updated version of this plugin was successfully installed, a
  444. * plugin event of type {@link ctkPluginEvent#UPDATED} is fired.
  445. *
  446. * <li>If this plugin's state was originally <code>ACTIVE</code>, the
  447. * updated plugin is started as described in the <code>ctkPlugin::start()</code>
  448. * method. If <code>ctkPlugin::start()</code> throws an exception, a Framework
  449. * event of type {@link ctkPluginFrameworkEvent#PLUGIN_ERROR} is fired containing the
  450. * exception.
  451. * </ol>
  452. *
  453. * <b>Preconditions </b>
  454. * <ul>
  455. * <li><code>getState()</code> not in &#x007B; <code>UNINSTALLED</code>
  456. * &#x007D;.
  457. * </ul>
  458. * <b>Postconditions, no exceptions thrown </b>
  459. * <ul>
  460. * <li><code>getState()</code> in &#x007B; <code>INSTALLED</code>,
  461. * <code>RESOLVED</code>, <code>ACTIVE</code> &#x007D;.
  462. * <li>This plugin has been updated.
  463. * </ul>
  464. * <b>Postconditions, when an exception is thrown </b>
  465. * <ul>
  466. * <li><code>getState()</code> in &#x007B; <code>INSTALLED</code>,
  467. * <code>RESOLVED</code>, <code>ACTIVE</code> &#x007D;.
  468. * <li>Original plugin is still used; no update occurred.
  469. * </ul>
  470. *
  471. * @param updateLocation The <code>QUrl</code> from which to read the new
  472. * plugin or <code>null</code> to indicate the Framework must create
  473. * the URL from this plugin's
  474. * {@link ctkPluginConstants#PLUGIN_UPDATELOCATION Plugin-UpdateLocation}
  475. * Manifest header, if present, or this plugin's original location.
  476. * @throws ctkPluginException If the update location cannot be read or the update
  477. * fails.
  478. * @throws ctkIllegalStateException If this plugin has been uninstalled or this
  479. * plugin tries to change its own state.
  480. * @see #stop()
  481. * @see #start()
  482. */
  483. void update(const QUrl &updateLocation = QUrl());
  484. /**
  485. * Uninstalls this plugin.
  486. *
  487. * <p>
  488. * This method causes the Plugin Framework to notify other plugins that this
  489. * plugin is being uninstalled, and then puts this plugin into the
  490. * <code>UNINSTALLED</code> state. The Framework must remove any resources
  491. * related to this plugin that it is able to remove.
  492. *
  493. * <p>
  494. * If this plugin is required by other plugins which are already resolved,
  495. * the Framework must keep this plugin loaded until the
  496. * Framework is relaunched.
  497. *
  498. * <p>
  499. * The following steps are required to uninstall a plugin:
  500. * <ol>
  501. * <li>If this plugin's state is <code>UNINSTALLED</code> then an
  502. * <code>ctkIllegalStateException</code> is thrown.
  503. *
  504. * <li>If this plugin's state is <code>ACTIVE</code>, <code>STARTING</code>
  505. * or <code>STOPPING</code>, this plugin is stopped as described in the
  506. * <code>ctkPlugin::stop</code> method. If <code>ctkPlugin::stop</code> throws an
  507. * exception, a Framework event of type ctkPluginFrameworkEvent::PLUGIN_ERROR is
  508. * fired containing the exception.
  509. *
  510. * <li>This plugin's state is set to <code>UNINSTALLED</code>.
  511. *
  512. * <li>A plugin event of type ctkPluginEvent::UNINSTALLED is fired.
  513. *
  514. * <li>This plugin and any persistent storage area provided for this plugin
  515. * by the Framework are removed.
  516. * </ol>
  517. *
  518. * <b>Preconditions </b>
  519. * <ul>
  520. * <li><code>getState()</code> not in &#123; <code>UNINSTALLED</code>
  521. * &#125;.
  522. * </ul>
  523. * <b>Postconditions, no exceptions thrown </b>
  524. * <ul>
  525. * <li><code>getState()</code> in &#123; <code>UNINSTALLED</code>
  526. * &#125;.
  527. * <li>This plugin has been uninstalled.
  528. * </ul>
  529. * <b>Postconditions, when an exception is thrown </b>
  530. * <ul>
  531. * <li><code>getState()</code> not in &#123; <code>UNINSTALLED</code>
  532. * &#125;.
  533. * <li>This plugin has not been uninstalled.
  534. * </ul>
  535. *
  536. * @throws ctkPluginException If the uninstall failed. This can occur if
  537. * another thread is attempting to change this plugin's state and
  538. * does not complete in a timely manner.
  539. * @throws ctkIllegalStateException If this plugin has been uninstalled or this
  540. * plugin tries to change its own state.
  541. * @see #stop()
  542. */
  543. virtual void uninstall();
  544. /**
  545. * Returns this plugin's {@link ctkPluginContext}. The returned
  546. * <code>ctkPluginContext</code> can be used by the caller to act on behalf
  547. * of this plugin.
  548. *
  549. * <p>
  550. * If this plugin is not in the {@link #STARTING}, {@link #ACTIVE}, or
  551. * {@link #STOPPING} states, then this
  552. * plugin has no valid <code>ctkPluginContext</code>. This method will
  553. * return <code>0</code> if this plugin has no valid
  554. * <code>ctkPluginContext</code>.
  555. *
  556. * @return A <code>ctkPluginContext</code> for this plugin or
  557. * <code>0</code> if this plugin has no valid
  558. * <code>ctkPluginContext</code>.
  559. */
  560. ctkPluginContext* getPluginContext() const;
  561. /**
  562. * Returns this plugin's unique identifier. This plugin is assigned a unique
  563. * identifier by the Framework when it was installed in the plugin
  564. * environment.
  565. *
  566. * <p>
  567. * A plugin's unique identifier has the following attributes:
  568. * <ul>
  569. * <li>Is unique and persistent.
  570. * <li>Is a <code>long</code>.
  571. * <li>Its value is not reused for another plugin, even after a plugin is
  572. * uninstalled.
  573. * <li>Does not change while a plugin remains installed.
  574. * <li>Does not change when a plugin is updated.
  575. * </ul>
  576. *
  577. * <p>
  578. * This method must continue to return this plugin's unique identifier while
  579. * this plugin is in the <code>UNINSTALLED</code> state.
  580. *
  581. * @return The unique identifier of this plugin.
  582. */
  583. long getPluginId() const;
  584. /**
  585. * Returns this plugin's location identifier.
  586. *
  587. * <p>
  588. * The location identifier is the location passed to
  589. * <code>ctkPluginContext::installPlugin</code> when a plugin is installed.
  590. * The location identifier does not change while this plugin remains
  591. * installed, even if this plugin is updated.
  592. *
  593. * <p>
  594. * This method must continue to return this plugin's location identifier
  595. * while this plugin is in the <code>UNINSTALLED</code> state.
  596. *
  597. * @return The string representation of this plugin's location identifier.
  598. */
  599. QString getLocation() const;
  600. /**
  601. * Returns this plugin's Manifest headers and values. This method returns
  602. * all the Manifest headers and values from the main section of this
  603. * bundle's Manifest file; that is, all lines prior to the first named section.
  604. *
  605. * TODO: documentation about manifest value internationalization
  606. *
  607. * <p>
  608. * For example, the following Manifest headers and values are included if
  609. * they are present in the Manifest file:
  610. *
  611. * <pre>
  612. * Plugin-Name
  613. * Plugin-Vendor
  614. * Plugin-ctkVersion
  615. * Plugin-Description
  616. * Plugin-DocURL
  617. * Plugin-ContactAddress
  618. * </pre>
  619. *
  620. * <p>
  621. * This method must continue to return Manifest header information while
  622. * this plugin is in the <code>UNINSTALLED</code> state.
  623. *
  624. * @return A <code>QHash<Qstring, QString></code> object containing this plugin's
  625. * Manifest headers and values.
  626. */
  627. virtual QHash<QString, QString> getHeaders();
  628. /**
  629. * Returns the symbolic name of this plugin as specified by its
  630. * <code>Plugin-SymbolicName</code> manifest header. The plugin symbolic
  631. * name together with a version must identify a unique plugin. The plugin
  632. * symbolic name should be based on the reverse domain name naming
  633. * convention like that used for java packages.
  634. *
  635. * <p>
  636. * This method must continue to return this plugin's symbolic name while
  637. * this plugin is in the <code>UNINSTALLED</code> state.
  638. *
  639. * @return The symbolic name of this plugin or a null QString if this
  640. * plugin does not have a symbolic name.
  641. */
  642. QString getSymbolicName() const;
  643. /**
  644. * Returns a list of all the files and directories
  645. * within this plugin whose longest sub-path matches the
  646. * specified path.
  647. * <p>
  648. * The specified path is always relative to the root of this plugin
  649. * (the plugins symbolic name) and may begin with a &quot;/&quot;.
  650. * A path value of &quot;/&quot; indicates the root of this plugin.
  651. * <p>
  652. * Returned paths indicating subdirectory paths end with a &quot;/&quot;.
  653. * The returned paths are all relative to the root of this plugin and must
  654. * not begin with &quot;/&quot;.
  655. * <p>
  656. *
  657. * @param path The path name for which to return resource paths.
  658. * @return A list of the resource paths (<code>QString</code>
  659. * objects) or an empty list if no entry could be found.
  660. * @throws ctkIllegalStateException If this plugin has been
  661. * uninstalled.
  662. */
  663. virtual QStringList getResourceList(const QString& path) const;
  664. /**
  665. * Returns a list of resources in this plugin.
  666. *
  667. * <p>
  668. * This method is intended to be used to obtain configuration, setup,
  669. * localization and other information from this plugin. This method can
  670. * either return only entries in the specified path or recurse into
  671. * subdirectories returning entries in the directory tree beginning at the
  672. * specified path.
  673. *
  674. * <p>
  675. * Examples:
  676. *
  677. * \code
  678. * // List all XML files in the OSGI-INF directory and below
  679. * QStringList r = b->findResources(&quot;OSGI-INF&quot;, &quot;*.xml&quot;, true);
  680. *
  681. * // Find a specific localization file
  682. * QStringList r = b->findResources(&quot;OSGI-INF/l10n&quot;, &quot;plugin_nl_DU.tm&quot;, false);
  683. * \endcode
  684. *
  685. * @param path The path name in which to look. The path is always relative
  686. * to the root of this plugin and may begin with &quot;/&quot;. A
  687. * path value of &quot;/&quot; indicates the root of this plugin.
  688. * @param filePattern The file name pattern for selecting entries in the
  689. * specified path. The pattern is only matched against the last
  690. * element of the entry path. Substring matching is supported, as
  691. * specified in the Filter specification, using the wildcard
  692. * character (&quot;*&quot;). If a null QString is specified, this
  693. * is equivalent to &quot;*&quot; and matches all files.
  694. * @param recurse If <code>true</code>, recurse into subdirectories.
  695. * Otherwise only return entries from the specified path.
  696. * @return A list of QString objects for each matching entry, or
  697. * an empty list if an entry could not be found or if the caller
  698. * does not have the appropriate
  699. * <code>AdminPermission[this,RESOURCE]</code>, and the Plugin
  700. * Framework supports permissions.
  701. * @throws ctkIllegalStateException If this plugin has been uninstalled.
  702. */
  703. virtual QStringList findResources(const QString& path, const QString& filePattern, bool recurse) const;
  704. /**
  705. * Returns a QByteArray containing a Qt resource located at the
  706. * specified path in this plugin.
  707. * <p>
  708. * The specified path is always relative to the root of this plugin
  709. * (the plugins symbolic name) and may
  710. * begin with &quot;/&quot;. A path value of &quot;/&quot; indicates the
  711. * root of this plugin.
  712. * <p>
  713. *
  714. * @param path The path name of the resource.
  715. * @return A QByteArray to the resource, or a null QByteArray if no resource could be
  716. * found.
  717. * @throws ctkIllegalStateException If this plugin has been
  718. * uninstalled.
  719. */
  720. virtual QByteArray getResource(const QString& path) const;
  721. /**
  722. * Returns a <code>ctkPluginLocalization</code> object for the
  723. * specified <code>locale</code>. The translations are loaded from a
  724. * .qm file starting with <code>base</code>.
  725. *
  726. * You can use the returned <code>ctkPluginLocalization</code>
  727. * object to dynamically translate text without changing the current
  728. * locale of the application. This can be used for example to
  729. * provide localized messages to multiple users which use the application
  730. * (maybe some kind of server) simultaneously but require different
  731. * localizations.
  732. *
  733. * @param locale The locale to be used by the returned
  734. * <code>ctkPluginLocalization</code> object.
  735. * @param base The base name of the .qm message file which contains
  736. * translated messages. Defaults to
  737. * <code>ctkPluginConstants::PLUGIN_LOCALIZATION_DEFAULT_BASENAME</code>.
  738. * @return A locale specific <code>ctkPluginLocalization</code> instance.
  739. */
  740. ctkPluginLocalization getPluginLocalization(const QLocale& locale,
  741. const QString& base = ctkPluginConstants::PLUGIN_LOCALIZATION_DEFAULT_BASENAME) const;
  742. /**
  743. * Returns the version of this plugin as specified by its
  744. * <code>Plugin-Version</code> manifest header. If this plugin does not have a
  745. * specified version then {@link ctkVersion#emptyVersion} is returned.
  746. *
  747. * <p>
  748. * This method must continue to return this plugin's version while
  749. * this plugin is in the <code>UNINSTALLED</code> state.
  750. *
  751. * @return The version of this plugin.
  752. */
  753. ctkVersion getVersion() const;
  754. protected:
  755. friend class ctkPluginFramework;
  756. friend class ctkPluginFrameworkPrivate;
  757. friend class ctkPluginFrameworkContext;
  758. friend class ctkPlugins;
  759. friend class ctkServiceReferencePrivate;
  760. // Do NOT change this to QScopedPointer<ctkPluginPrivate>!
  761. // We would need to include ctkPlugin.h (and ctkPluginPrivate_p.h)
  762. // at a lot of places...
  763. ctkPluginPrivate* d_ptr;
  764. ctkPlugin();
  765. void init(ctkPluginPrivate* dd);
  766. void init(const QWeakPointer<ctkPlugin>& self, ctkPluginFrameworkContext* fw, QSharedPointer<ctkPluginArchive> ba);
  767. };
  768. /**
  769. * \ingroup PluginFramework
  770. * @{
  771. */
  772. Q_DECLARE_METATYPE(ctkPlugin*)
  773. Q_DECLARE_METATYPE(QSharedPointer<ctkPlugin>)
  774. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPlugin::States)
  775. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPlugin::StartOptions)
  776. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPlugin::StopOptions)
  777. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, ctkPlugin::State state);
  778. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, const ctkPlugin& plugin);
  779. CTK_PLUGINFW_EXPORT QDebug operator<<(QDebug debug, ctkPlugin const * plugin);
  780. CTK_PLUGINFW_EXPORT ctkLogStream& operator<<(ctkLogStream& stream, ctkPlugin const * plugin);
  781. CTK_PLUGINFW_EXPORT ctkLogStream& operator<<(ctkLogStream& stream, const QSharedPointer<ctkPlugin>& plugin);
  782. /** @}*/
  783. #endif // CTKPLUGIN_H