ctkConfigurationAdminFactory.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #include "ctkConfigurationAdminFactory_p.h"
  16. #include <service/log/ctkLogService.h>
  17. #include "ctkConfigurationAdminImpl_p.h"
  18. #include "ctkConfigurationImpl_p.h"
  19. ctkConfigurationAdminFactory::ctkConfigurationAdminFactory(ctkPluginContext* context, ctkLogService* log)
  20. : eventDispatcher(context, log), pluginManager(context), logService(log),
  21. configurationStore(this, context),
  22. managedServiceTracker(this, &configurationStore, context),
  23. managedServiceFactoryTracker(this, &configurationStore, context)
  24. {
  25. }
  26. ctkConfigurationAdminFactory::~ctkConfigurationAdminFactory()
  27. {
  28. qDeleteAll(configAdmins);
  29. }
  30. void ctkConfigurationAdminFactory::start()
  31. {
  32. eventDispatcher.start();
  33. pluginManager.start();
  34. managedServiceTracker.open();
  35. managedServiceFactoryTracker.open();
  36. }
  37. void ctkConfigurationAdminFactory::stop()
  38. {
  39. managedServiceTracker.close();
  40. managedServiceFactoryTracker.close();
  41. eventDispatcher.stop();
  42. pluginManager.stop();
  43. }
  44. QObject* ctkConfigurationAdminFactory::getService(QSharedPointer<ctkPlugin> plugin,
  45. ctkServiceRegistration registration)
  46. {
  47. ctkServiceReference reference = registration.getReference();
  48. eventDispatcher.setServiceReference(reference);
  49. ctkConfigurationAdminImpl* configAdmin = new ctkConfigurationAdminImpl(this, &configurationStore, plugin);
  50. configAdmins.push_back(configAdmin);
  51. return configAdmin;
  52. }
  53. void ctkConfigurationAdminFactory::ungetService(QSharedPointer<ctkPlugin> plugin,
  54. ctkServiceRegistration registration, QObject* service)
  55. {
  56. Q_UNUSED(plugin)
  57. Q_UNUSED(registration)
  58. Q_UNUSED(service)
  59. // do nothing
  60. }
  61. void ctkConfigurationAdminFactory::pluginChanged(const ctkPluginEvent& event)
  62. {
  63. if (event.getType() == ctkPluginEvent::UNINSTALLED)
  64. {
  65. configurationStore.unbindConfigurations(event.getPlugin());
  66. }
  67. }
  68. void ctkConfigurationAdminFactory::checkConfigurationPermission()
  69. {
  70. //TODO security
  71. // SecurityManager sm = System.getSecurityManager();
  72. // if (sm != null)
  73. // sm.checkPermission(configurationPermission);
  74. }
  75. ctkLogService* ctkConfigurationAdminFactory::getLogService() const
  76. {
  77. return logService;
  78. }
  79. void ctkConfigurationAdminFactory::dispatchEvent(ctkConfigurationEvent::Type type, const QString& factoryPid, const QString& pid)
  80. {
  81. eventDispatcher.dispatchEvent(type, factoryPid, pid);
  82. }
  83. void ctkConfigurationAdminFactory::notifyConfigurationUpdated(ctkConfigurationImpl* config, bool isFactory)
  84. {
  85. if (isFactory)
  86. {
  87. managedServiceFactoryTracker.notifyUpdated(config);
  88. }
  89. else
  90. {
  91. managedServiceTracker.notifyUpdated(config);
  92. }
  93. }
  94. void ctkConfigurationAdminFactory::notifyConfigurationDeleted(ctkConfigurationImpl* config, bool isFactory)
  95. {
  96. if (isFactory)
  97. {
  98. managedServiceFactoryTracker.notifyDeleted(config);
  99. }
  100. else
  101. {
  102. managedServiceTracker.notifyDeleted(config);
  103. }
  104. }
  105. void ctkConfigurationAdminFactory::modifyConfiguration(const ctkServiceReference& reference,
  106. ctkDictionary& properties)
  107. {
  108. pluginManager.modifyConfiguration(reference, properties);
  109. }