ctkPluginPrivate_p.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 CTKPLUGINPRIVATE_P_H
  16. #define CTKPLUGINPRIVATE_P_H
  17. #include "ctkPlugin.h"
  18. #include "ctkPluginException.h"
  19. #include "ctkRequirePlugin_p.h"
  20. #include <QHash>
  21. #include <QPluginLoader>
  22. #include <QDateTime>
  23. #include <QFileInfo>
  24. class ctkPluginActivator;
  25. class ctkPluginArchive;
  26. class ctkPluginFrameworkContext;
  27. /**
  28. * \ingroup PluginFramework
  29. */
  30. class ctkPluginPrivate {
  31. protected:
  32. const QWeakPointer<ctkPlugin> q_ptr;
  33. public:
  34. inline QWeakPointer<ctkPlugin> q_func() { return q_ptr; }
  35. inline QWeakPointer<const ctkPlugin> q_func() const { return q_ptr; }
  36. friend class ctkPlugin;
  37. /**
  38. * Construct a new plugin based on a ctkPluginArchive.
  39. *
  40. * @param fw ctkPluginFrameworkContext for this plugin.
  41. * @param ba ctkPlugin archive representing the shared library and cached data
  42. * @param checkContext AccessConrolContext to do permission checks against.
  43. * @exception std::invalid_argument Faulty manifest for bundle
  44. */
  45. ctkPluginPrivate(QWeakPointer<ctkPlugin> qq, ctkPluginFrameworkContext* fw,
  46. ctkPluginArchive* pa /*, Object checkContext*/);
  47. /**
  48. * Construct a new empty ctkPlugin.
  49. *
  50. * Only called for the system plugin
  51. *
  52. * @param fw Framework for this plugin.
  53. */
  54. ctkPluginPrivate(QWeakPointer<ctkPlugin> qq,
  55. ctkPluginFrameworkContext* fw,
  56. long id,
  57. const QString& loc,
  58. const QString& sym,
  59. const ctkVersion& ver);
  60. virtual ~ctkPluginPrivate();
  61. /**
  62. * Get updated plugin state. That means check if an installed
  63. * plugin has been resolved.
  64. *
  65. * @return ctkPlugin state
  66. */
  67. ctkPlugin::State getUpdatedState();
  68. /**
  69. * Get root for persistent storage area for this plugin.
  70. *
  71. * @return A QDir object representing the data root.
  72. */
  73. QFileInfo getDataRoot();
  74. /**
  75. * Save the autostart setting to the persistent plugin storage.
  76. *
  77. * @param setting The autostart options to save.
  78. */
  79. void setAutostartSetting(const ctkPlugin::StartOptions& setting);
  80. void ignoreAutostartSetting();
  81. void modified();
  82. /**
  83. * Performs the actual activation.
  84. */
  85. void finalizeActivation();
  86. /**
  87. * Performs the actual stopping.
  88. */
  89. void stop0(bool wasStarted);
  90. /**
  91. *
  92. */
  93. QStringList findResourceEntries(const QString& path,
  94. const QString& pattern, bool recurse) const;
  95. /**
  96. * Union of flags allowing plugin class access
  97. */
  98. static const ctkPlugin::States RESOLVED_FLAGS;
  99. ctkPluginFrameworkContext * const fwCtx;
  100. /**
  101. * ctkPlugin identifier
  102. */
  103. const long id;
  104. /**
  105. * ctkPlugin location identifier
  106. */
  107. const QString location;
  108. /**
  109. * ctkPlugin symbolic name
  110. */
  111. QString symbolicName;
  112. /**
  113. * ctkPlugin version
  114. */
  115. ctkVersion version;
  116. /**
  117. * State of the plugin
  118. */
  119. ctkPlugin::State state;
  120. /**
  121. * ctkPlugin archive
  122. */
  123. ctkPluginArchive* archive;
  124. /**
  125. * Directory for plugin data
  126. */
  127. QFileInfo pluginDir;
  128. /**
  129. * ctkPluginContext for the plugin
  130. */
  131. QScopedPointer<ctkPluginContext> pluginContext;
  132. /**
  133. * ctkPluginActivator for the plugin
  134. */
  135. ctkPluginActivator* pluginActivator;
  136. /**
  137. * The Qt plugin loader for the plugin
  138. */
  139. QPluginLoader pluginLoader;
  140. /**
  141. * Time when the plugin was last modified
  142. */
  143. QDateTime lastModified;
  144. /**
  145. * Stores the default locale entries when uninstalled
  146. */
  147. QHash<QString, QString> cachedHeaders;
  148. /**
  149. * Stores the raw manifest headers
  150. */
  151. QHash<QString, QString> cachedRawHeaders;
  152. /**
  153. * True when this plugin has its activation policy
  154. * set to "eager"
  155. */
  156. bool eagerActivation;
  157. /** True during the finalization of an activation. */
  158. bool activating;
  159. /** True during the state change from active to resolved. */
  160. bool deactivating;
  161. /** Saved exception of resolve failure */
  162. //ctkPluginException resolveFailException;
  163. /** List of ctkRequirePlugin entries. */
  164. QList<ctkRequirePlugin*> require;
  165. private:
  166. /**
  167. * Check manifest and cache certain manifest headers as variables.
  168. */
  169. void checkManifestHeaders();
  170. // This could potentially be run in its own thread,
  171. // parallelizing plugin activations
  172. void start0();
  173. void startDependencies();
  174. /**
  175. * Remove a plugins registered listeners, registered services and
  176. * used services.
  177. *
  178. */
  179. void removePluginResources();
  180. };
  181. #endif // CTKPLUGINPRIVATE_P_H