ctkPlugin.h 28 KB

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