ctkQtMobilityServiceActivator.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /*
  16. * ctkQtMobilityServiceActivator.cxx
  17. *
  18. * Created on: Mar 29, 2010
  19. * Author: zelzer
  20. */
  21. #include "ctkQtMobilityServiceActivator_p.h"
  22. #include "ctkQtMobilityServiceRuntime_p.h"
  23. #include <ctkServiceTracker.h>
  24. #include <ctkServiceException.h>
  25. #include <service/log/ctkLogService.h>
  26. #include <QtPlugin>
  27. ctkQtMobilityServiceActivator::LogTracker* ctkQtMobilityServiceActivator::logTracker = 0;
  28. void ctkQtMobilityServiceActivator::start(ctkPluginContext* context)
  29. {
  30. logTracker = new LogTracker(context);
  31. logTracker->open();
  32. mobsr = new ctkQtMobilityServiceRuntime(context);
  33. mobsr->start();
  34. }
  35. void ctkQtMobilityServiceActivator::stop(ctkPluginContext* context)
  36. {
  37. Q_UNUSED(context)
  38. if (mobsr)
  39. {
  40. mobsr->stop();
  41. delete mobsr;
  42. mobsr = 0;
  43. }
  44. if (logTracker)
  45. {
  46. logTracker->close();
  47. delete logTracker;
  48. logTracker = 0;
  49. }
  50. }
  51. ctkLogService* ctkQtMobilityServiceActivator::getLogService()
  52. {
  53. if (logTracker == 0)
  54. {
  55. return 0;
  56. }
  57. return logTracker->getService();
  58. }
  59. void ctkQtMobilityServiceActivator::logError(ctkPluginContext* pc, const QString& msg, std::exception* e)
  60. {
  61. logPluginContext(pc, ctkLogService::LOG_ERROR, msg, e);
  62. }
  63. void ctkQtMobilityServiceActivator::logWarning(ctkPluginContext* pc, const QString& msg, std::exception* e)
  64. {
  65. logPluginContext(pc, ctkLogService::LOG_WARNING, msg, e);
  66. }
  67. void ctkQtMobilityServiceActivator::logInfo(ctkPluginContext* pc, const QString& msg, std::exception* e)
  68. {
  69. logPluginContext(pc, ctkLogService::LOG_INFO, msg, e);
  70. }
  71. void ctkQtMobilityServiceActivator::logPluginContext(ctkPluginContext* pc, int level, const QString& msg, const std::exception* e)
  72. {
  73. try
  74. {
  75. ctkServiceReference sr = pc->getServiceReference("ctkLogService");
  76. ctkLogService* log = qobject_cast<ctkLogService*>(pc->getService(sr));
  77. if (log)
  78. {
  79. log->log(level, msg, e);
  80. pc->ungetService(sr);
  81. }
  82. }
  83. catch (const ctkServiceException&)
  84. { }
  85. }
  86. Q_EXPORT_PLUGIN2(org_commontk_qtmobility_service, ctkQtMobilityServiceActivator)