ctkPlugin.h 24 KB

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