ctkQtMobilityServiceFactory.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "ctkQtMobilityServiceFactory_p.h"
  16. #include "ctkQtMobilityServiceRuntime_p.h"
  17. #include "ctkQtMobilityServiceActivator_p.h"
  18. #include <service/log/ctkLogService.h>
  19. #include <ctkPluginException.h>
  20. #include <ctkPluginConstants.h>
  21. #include <QBuffer>
  22. ctkQtMobilityServiceFactory::ctkQtMobilityServiceFactory(
  23. const QServiceInterfaceDescriptor& descr,
  24. ctkQtMobilityServiceRuntime* sr, QSharedPointer<ctkPlugin> p)
  25. : activeCount(0), serviceDescriptor(descr), sr(sr), servicePlugin(p)
  26. {
  27. }
  28. QObject* ctkQtMobilityServiceFactory::getService(
  29. QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration registration)
  30. {
  31. Q_UNUSED(usingPlugin)
  32. Q_UNUSED(registration)
  33. CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService())
  34. << "QtMobSF::getService(), " << serviceDescriptor.serviceName() << " "
  35. << serviceDescriptor.interfaceName() << serviceDescriptor.majorVersion()
  36. << "." << serviceDescriptor.minorVersion() << ", active = " << activeCount;
  37. if (servicePlugin->getState() != ctkPlugin::ACTIVE)
  38. {
  39. try
  40. {
  41. servicePlugin->start(0);
  42. }
  43. catch (const ctkPluginException* e)
  44. {
  45. CTK_ERROR_EXC(ctkQtMobilityServiceActivator::getLogService(), e)
  46. << "Delayed plugin activation failed.";
  47. return 0;
  48. }
  49. }
  50. ++activeCount;
  51. return sr->getQServiceManager().loadInterface(serviceDescriptor);
  52. }
  53. void ctkQtMobilityServiceFactory::ungetService(
  54. QSharedPointer<ctkPlugin> usingPlugin, ctkServiceRegistration registration, QObject* service)
  55. {
  56. Q_UNUSED(usingPlugin)
  57. Q_UNUSED(registration)
  58. Q_UNUSED(service)
  59. CTK_DEBUG(ctkQtMobilityServiceActivator::getLogService())
  60. << "QtMobSF::ungetService(), " << serviceDescriptor.serviceName() << " "
  61. << serviceDescriptor.interfaceName() << serviceDescriptor.majorVersion()
  62. << "." << serviceDescriptor.minorVersion() << ", active = " << activeCount;
  63. --activeCount;
  64. }