ctkPlugin.h 25 KB

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