ctkPluginPrivate.cxx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #include "ctkPluginPrivate_p.h"
  16. #include "ctkPluginConstants.h"
  17. #include "ctkPluginArchive_p.h"
  18. #include "ctkPluginFrameworkContextPrivate_p.h"
  19. namespace ctk {
  20. const Plugin::States PluginPrivate::RESOLVED_FLAGS = Plugin::RESOLVED | Plugin::STARTING | Plugin::ACTIVE | Plugin::STOPPING;
  21. PluginPrivate::PluginPrivate(
  22. Plugin& qq,
  23. PluginFrameworkContextPrivate* fw,
  24. PluginArchive* pa)
  25. : q_ptr(&qq), fwCtx(fw), id(pa->getPluginId()),
  26. location(pa->getPluginLocation().toString()), state(Plugin::INSTALLED),
  27. archive(pa), pluginContext(0), pluginActivator(0), lastModified(0),
  28. lazyActivation(true), activating(false), deactivating(false),
  29. resolveFailException("")
  30. {
  31. //TODO
  32. //checkCertificates(pa);
  33. checkManifestHeaders();
  34. }
  35. PluginPrivate::PluginPrivate(Plugin& qq,
  36. PluginFrameworkContextPrivate* fw,
  37. int id, const QString& loc, const QString& sym, const Version& ver)
  38. : q_ptr(&qq), fwCtx(fw), id(id), location(loc), symbolicName(sym), version(ver),
  39. state(Plugin::INSTALLED), archive(0), pluginContext(0),
  40. pluginActivator(0), lastModified(0),
  41. lazyActivation(true), activating(false), deactivating(false),
  42. resolveFailException("")
  43. {
  44. }
  45. PluginPrivate::~PluginPrivate()
  46. {
  47. }
  48. QHash<QString, QString> PluginPrivate::getHeaders(const QString& locale)
  49. {
  50. return QHash<QString, QString>();
  51. }
  52. Plugin::States PluginPrivate::getUpdatedState()
  53. {
  54. if (state & Plugin::INSTALLED)
  55. {
  56. bool wasResolved = false;
  57. try
  58. {
  59. if (state == Plugin::INSTALLED)
  60. {
  61. fwCtx->resolvePlugin(this);
  62. wasResolved = true;
  63. state = Plugin::RESOLVED;
  64. }
  65. }
  66. catch (const PluginException& pe)
  67. {
  68. // TODO
  69. //fwCtx.listeners.frameworkError(this, be);
  70. }
  71. if (wasResolved)
  72. {
  73. // TODO
  74. // fwCtx.listeners.bundleChanged(new BundleEvent(BundleEvent.RESOLVED, this));
  75. }
  76. }
  77. return state;
  78. }
  79. void PluginPrivate::checkManifestHeaders()
  80. {
  81. symbolicName = archive->getAttribute(PluginConstants::PLUGIN_SYMBOLICNAME);
  82. if (symbolicName.isEmpty())
  83. {
  84. throw std::invalid_argument(std::string("Plugin has no symbolic name, location=") +
  85. qPrintable(location));
  86. }
  87. QString mpv = archive->getAttribute(PluginConstants::PLUGIN_VERSION);
  88. if (!mpv.isEmpty())
  89. {
  90. try
  91. {
  92. version = Version(mpv);
  93. }
  94. catch (const std::exception& e)
  95. {
  96. throw std::invalid_argument(std::string("Plugin does not specify a valid ") +
  97. qPrintable(PluginConstants::PLUGIN_VERSION) + " header. Got exception: " + e.what());
  98. }
  99. }
  100. QString ap = archive->getAttribute(PluginConstants::PLUGIN_ACTIVATIONPOLICY);
  101. if (PluginConstants::ACTIVATION_EAGER == ap)
  102. {
  103. lazyActivation = false;
  104. }
  105. }
  106. }