ctkPluginPrivate_p.h 5.0 KB

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