ctkDicomAppPlugin.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "ctkDicomAppPlugin_p.h"
  16. #include "ctkDicomAppServer_p.h"
  17. #include "ctkDicomHostService_p.h"
  18. #include <QtPlugin>
  19. #include <QStringList>
  20. #include <stdexcept>
  21. ctkDicomAppPlugin* ctkDicomAppPlugin::instance = 0;
  22. ctkDicomAppPlugin::ctkDicomAppPlugin()
  23. : context(0), appServer(0), hostInterface(0)
  24. {
  25. }
  26. ctkDicomAppPlugin::~ctkDicomAppPlugin()
  27. {
  28. }
  29. void ctkDicomAppPlugin::start(ctkPluginContext* context)
  30. {
  31. instance = this;
  32. this->context = context;
  33. QUrl appURL(context->getProperty("dah.appURL").toString());
  34. if (!appURL.isValid())
  35. {
  36. throw std::runtime_error("The plugin framework does not contain a valid \"dah.appURL\" property");
  37. }
  38. QUrl hostURL(context->getProperty("dah.hostURL").toString());
  39. if (!hostURL.isValid())
  40. {
  41. throw std::runtime_error("The plugin framework does not contain a valid \"dah.hostURL\" property");
  42. }
  43. // start the application server
  44. appServer = new ctkDicomAppServer(appURL.port());
  45. // register the host service, providing callbacks to the hosting application
  46. hostInterface = new ctkDicomHostService(QUrl(hostURL).port(), "/HostInterface");
  47. context->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
  48. }
  49. void ctkDicomAppPlugin::stop(ctkPluginContext* context)
  50. {
  51. Q_UNUSED(context)
  52. delete appServer;
  53. delete hostInterface;
  54. }
  55. ctkDicomAppPlugin* ctkDicomAppPlugin::getInstance()
  56. {
  57. return instance;
  58. }
  59. ctkPluginContext* ctkDicomAppPlugin::getPluginContext() const
  60. {
  61. return context;
  62. }
  63. Q_EXPORT_PLUGIN2(org_commontk_dah_app, ctkDicomAppPlugin)