ctkPlugin.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 "ctkPluginContext.h"
  18. #include "ctkVersion.h"
  19. namespace ctk {
  20. class PluginArchive;
  21. class PluginFrameworkContextPrivate;
  22. class PluginPrivate;
  23. class CTK_CORE_EXPORT Plugin {
  24. Q_DECLARE_PRIVATE(Plugin)
  25. public:
  26. enum State {
  27. UNINSTALLED,
  28. INSTALLED,
  29. RESOLVED,
  30. STARTING,
  31. STOPPING,
  32. ACTIVE
  33. };
  34. Q_DECLARE_FLAGS(States, State)
  35. virtual ~Plugin();
  36. /**
  37. * Returns this plugin's current state.
  38. *
  39. * <p>
  40. * A plugin can be in only one state at any time.
  41. *
  42. * @return An element of <code>UNINSTALLED</code>,<code>INSTALLED</code>,
  43. * <code>RESOLVED</code>,<code>STARTING</code>,
  44. * <code>STOPPING</code>,<code>ACTIVE</code>.
  45. */
  46. State getState() const;
  47. virtual void start();
  48. virtual void stop();
  49. PluginContext* getPluginContext() const;
  50. int getPluginId() const;
  51. /**
  52. * Returns this plugin's location identifier.
  53. *
  54. * <p>
  55. * The location identifier is the location passed to
  56. * <code>PluginContext::installPlugin</code> when a plugin is installed.
  57. * The location identifier does not change while this plugin remains
  58. * installed, even if this plugin is updated.
  59. *
  60. * <p>
  61. * This method must continue to return this plugin's location identifier
  62. * while this plugin is in the <code>UNINSTALLED</code> state.
  63. *
  64. * @return The string representation of this plugin's location identifier.
  65. */
  66. QString getLocation() const;
  67. QString getSymbolicName() const;
  68. /**
  69. * Returns a list of all the files and directories
  70. * within this plugin whose longest sub-path matches the
  71. * specified path.
  72. * <p>
  73. * The specified path is always relative to the root of this plugin
  74. * (the plugins symbolic name) and may begin with a &quot;/&quot;.
  75. * A path value of &quot;/&quot; indicates the root of this plugin.
  76. * <p>
  77. * Returned paths indicating subdirectory paths end with a &quot;/&quot;.
  78. * The returned paths are all relative to the root of this plugin and must
  79. * not begin with &quot;/&quot;.
  80. * <p>
  81. *
  82. * @param path The path name for which to return resource paths.
  83. * @return A list of the resource paths (<code>QString</code>
  84. * objects) or an empty list if no entry could be found.
  85. * @throws std::logic_error If this plugin has been
  86. * uninstalled.
  87. */
  88. virtual QStringList getResourceList(const QString& path) const;
  89. /**
  90. * Returns a QByteArray containing a Qt resource located at the
  91. * specified path in this plugin.
  92. * <p>
  93. * The specified path is always relative to the root of this plugin
  94. * (the plugins symbolic name) and may
  95. * begin with &quot;/&quot;. A path value of &quot;/&quot; indicates the
  96. * root of this plugin.
  97. * <p>
  98. *
  99. * @param path The path name of the resource.
  100. * @return A QString to the resource, or a null QString if no resource could be
  101. * found.
  102. * @throws std::logic_error If this plugin has been
  103. * uninstalled.
  104. */
  105. virtual QByteArray getResource(const QString& path) const;
  106. Version getVersion() const;
  107. protected:
  108. friend class PluginFrameworkContextPrivate;
  109. friend class Plugins;
  110. PluginPrivate * const d_ptr;
  111. Plugin(PluginFrameworkContextPrivate* fw, PluginArchive* ba);
  112. Plugin(PluginPrivate& dd);
  113. };
  114. }
  115. Q_DECLARE_OPERATORS_FOR_FLAGS(ctk::Plugin::States)
  116. #endif // CTKPLUGIN_H