ctkEAFrameworkEventAdapter.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "ctkEAFrameworkEventAdapter_p.h"
  16. #include <ctkPluginContext.h>
  17. #include <service/event/ctkEventConstants.h>
  18. ctkEAFrameworkEventAdapter::ctkEAFrameworkEventAdapter(ctkPluginContext* context, ctkEventAdmin* admin)
  19. : ctkEAAbstractAdapter(admin)
  20. {
  21. context->connectFrameworkListener(this, SLOT(frameworkEvent(ctkPluginFrameworkEvent)));
  22. }
  23. void ctkEAFrameworkEventAdapter::destroy(ctkPluginContext* context)
  24. {
  25. Q_UNUSED(context)
  26. //context->removeFrameworkListener(this);
  27. }
  28. void ctkEAFrameworkEventAdapter::frameworkEvent(const ctkPluginFrameworkEvent& event)
  29. {
  30. ctkDictionary properties;
  31. properties.insert(ctkEventConstants::EVENT, QVariant::fromValue(event));
  32. QSharedPointer<ctkPlugin> plugin = event.getPlugin();
  33. if (plugin)
  34. {
  35. properties.insert("plugin.id", QVariant::fromValue<long>(plugin->getPluginId()));
  36. const QString symbolicName = plugin->getSymbolicName();
  37. if (!symbolicName.isEmpty())
  38. {
  39. properties.insert(ctkEventConstants::PLUGIN_SYMBOLICNAME,
  40. symbolicName);
  41. }
  42. properties.insert("plugin", QVariant::fromValue(plugin));
  43. }
  44. const QString message = event.getErrorString();
  45. if (!message.isEmpty())
  46. {
  47. // properties.put(EventConstants.EXCEPTION_CLASS,
  48. // thrown.getClass().getName());
  49. // final String message = thrown.getMessage();
  50. properties.insert(ctkEventConstants::EXCEPTION_MESSAGE,
  51. message);
  52. //properties.put(EventConstants.EXCEPTION, thrown);
  53. }
  54. QString topic = "org/commontk/PluginFrameworkEvent/";
  55. switch (event.getType())
  56. {
  57. case ctkPluginFrameworkEvent::FRAMEWORK_STARTED:
  58. topic.append("STARTED");
  59. break;
  60. case ctkPluginFrameworkEvent::PLUGIN_ERROR:
  61. topic.append("ERROR");
  62. break;
  63. // case ctkPluginFrameworkEvent::STARTLEVEL_CHANGED:
  64. // topic.append("STARTLEVEL_CHANGED");
  65. // break;
  66. case ctkPluginFrameworkEvent::PLUGIN_WARNING:
  67. topic.append("WARNING");
  68. break;
  69. case ctkPluginFrameworkEvent::PLUGIN_INFO:
  70. topic.append("INFO");
  71. break;
  72. default:
  73. return; // IGNORE EVENT
  74. }
  75. try
  76. {
  77. getEventAdmin()->postEvent(ctkEvent(topic, properties));
  78. }
  79. catch(const std::logic_error& )
  80. {
  81. // This is o.k. - indicates that we are stopped.
  82. }
  83. }