ctkPlugin.h 26 KB

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