ctkPluginContext.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 "ctkPluginContext.h"
  16. #include "ctkPluginPrivate_p.h"
  17. #include "ctkPluginFrameworkContext_p.h"
  18. #include "ctkServiceRegistration.h"
  19. #include "ctkServiceReference.h"
  20. #include <stdexcept>
  21. namespace ctk {
  22. class PluginContextPrivate
  23. {
  24. public:
  25. PluginPrivate* plugin;
  26. PluginContextPrivate(PluginPrivate* plugin)
  27. : plugin(plugin)
  28. {}
  29. /**
  30. * Check that the plugin is still valid.
  31. */
  32. void isPluginContextValid() const
  33. {
  34. if (!plugin) {
  35. throw std::logic_error("This plugin context is no longer valid");
  36. }
  37. }
  38. void invalidate()
  39. {
  40. plugin = 0;
  41. }
  42. };
  43. PluginContext::PluginContext(PluginPrivate* plugin)
  44. : d_ptr(new PluginContextPrivate(plugin))
  45. {}
  46. PluginContext::~PluginContext()
  47. {
  48. Q_D(PluginContext);
  49. delete d;
  50. }
  51. Plugin* PluginContext::getPlugin(int id) const
  52. {
  53. Q_D(const PluginContext);
  54. d->isPluginContextValid();
  55. return d->plugin->fwCtx->plugins->getPlugin(id);
  56. }
  57. QList<Plugin*> PluginContext::getPlugins() const
  58. {
  59. Q_D(const PluginContext);
  60. d->isPluginContextValid();
  61. return d->plugin->fwCtx->plugins->getPlugins();
  62. }
  63. Plugin* PluginContext::installPlugin(const QUrl& location, QIODevice* in)
  64. {
  65. Q_D(PluginContext);
  66. d->isPluginContextValid();
  67. return d->plugin->fwCtx->plugins->install(location, in);
  68. }
  69. ServiceRegistration PluginContext::registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties)
  70. {
  71. }
  72. QList<ServiceReference> PluginContext::getServiceReferences(const QString& clazz, const QString& filter)
  73. {
  74. }
  75. ServiceReference PluginContext::getServiceReference(const QString& clazz)
  76. {
  77. }
  78. QObject* PluginContext::getService(const ServiceReference& reference)
  79. {
  80. }
  81. bool PluginContext::connectPluginListener(const QObject* receiver, const char* method,
  82. Qt::ConnectionType type)
  83. {
  84. Q_D(PluginContext);
  85. // TODO check permissions for a direct connection
  86. receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(pluginChanged(PluginEvent)), method, type);
  87. }
  88. bool PluginContext::connectFrameworkListener(const QObject* receiver, const char* method, Qt::ConnectionType type)
  89. {
  90. Q_D(PluginContext);
  91. receiver->connect(&(d->plugin->fwCtx->listeners), SIGNAL(frameworkEvent(PluginFrameworkEvent)), method, type);
  92. }
  93. }