ctkEAPluginEventAdapter.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "ctkEAPluginEventAdapter_p.h"
  16. #include <ctkPluginContext.h>
  17. #include <service/event/ctkEventConstants.h>
  18. #include <service/event/ctkEvent.h>
  19. ctkEAPluginEventAdapter::ctkEAPluginEventAdapter(ctkPluginContext* context, ctkEventAdmin* admin)
  20. : ctkEAAbstractAdapter(admin)
  21. {
  22. context->connectPluginListener(this, SLOT(pluginChanged(ctkPluginEvent)));
  23. }
  24. void ctkEAPluginEventAdapter::destroy(ctkPluginContext* context)
  25. {
  26. Q_UNUSED(context)
  27. }
  28. void ctkEAPluginEventAdapter::pluginChanged(const ctkPluginEvent& event)
  29. {
  30. ctkDictionary properties;
  31. properties.insert(ctkEventConstants::EVENT, QVariant::fromValue(event));
  32. properties.insert("plugin.id", QVariant::fromValue<long>(event.getPlugin()->getPluginId()));
  33. const QString symbolicName = event.getPlugin()->getSymbolicName();
  34. if (!symbolicName.isEmpty())
  35. {
  36. properties.insert(ctkEventConstants::PLUGIN_SYMBOLICNAME,
  37. symbolicName);
  38. }
  39. properties.insert("plugin", QVariant::fromValue(event.getPlugin()));
  40. QString topic("org/commontk/PluginEvent/");
  41. switch (event.getType())
  42. {
  43. case ctkPluginEvent::INSTALLED:
  44. topic.append("INSTALLED");
  45. break;
  46. case ctkPluginEvent::STARTED:
  47. topic.append("STARTED");
  48. break;
  49. case ctkPluginEvent::STOPPED:
  50. topic.append("STOPPED");
  51. break;
  52. case ctkPluginEvent::UPDATED:
  53. topic.append("UPDATED");
  54. break;
  55. case ctkPluginEvent::UNINSTALLED:
  56. topic.append("UNINSTALLED");
  57. break;
  58. case ctkPluginEvent::RESOLVED:
  59. topic.append("RESOLVED");
  60. break;
  61. case ctkPluginEvent::UNRESOLVED:
  62. topic.append("UNRESOLVED");
  63. break;
  64. default:
  65. return; // IGNORE EVENT
  66. };
  67. try
  68. {
  69. getEventAdmin()->postEvent(ctkEvent(topic, properties));
  70. }
  71. catch (const ctkIllegalStateException& )
  72. {
  73. // This is o.k. - indicates that we are stopped.
  74. }
  75. }