ctkPluginContext.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 "ctkPluginFrameworkContextPrivate_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()
  33. {
  34. if (!plugin) {
  35. throw std::logic_error("This plugin context is no longer valid");
  36. }
  37. }
  38. };
  39. PluginContext::PluginContext(PluginPrivate* plugin)
  40. : d_ptr(new PluginContextPrivate(plugin))
  41. {}
  42. PluginContext::~PluginContext()
  43. {
  44. Q_D(PluginContext);
  45. delete d;
  46. }
  47. Plugin* PluginContext::getPlugin(int id) const
  48. {
  49. Q_D(const PluginContext);
  50. return d->plugin->fwCtx->plugins->getPlugin(id);
  51. }
  52. QList<Plugin*> PluginContext::getPlugins() const
  53. {
  54. Q_D(const PluginContext);
  55. return d->plugin->fwCtx->plugins->getPlugins();
  56. }
  57. Plugin* PluginContext::installPlugin(const QUrl& location, QIODevice* in)
  58. {
  59. Q_D(PluginContext);
  60. d->isPluginContextValid();
  61. return d->plugin->fwCtx->plugins->install(location, in);
  62. }
  63. ServiceRegistration PluginContext::registerService(const QStringList& clazzes, QObject* service, const ServiceProperties& properties)
  64. {
  65. }
  66. QList<ServiceReference> PluginContext::getServiceReferences(const QString& clazz, const QString& filter)
  67. {
  68. }
  69. ServiceReference PluginContext::getServiceReference(const QString& clazz)
  70. {
  71. }
  72. QObject* PluginContext::getService(const ServiceReference& reference)
  73. {
  74. }
  75. }