ctkDicomAppPlugin.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // Qt includes
  16. #include <QtPlugin>
  17. #include <QStringList>
  18. // CTK includes
  19. #include "ctkDicomAppPlugin_p.h"
  20. #include "ctkDicomAppServer_p.h"
  21. #include "ctkDicomHostService_p.h"
  22. // STD includes
  23. #include <stdexcept>
  24. #include <iostream>
  25. ctkPluginContext* ctkDicomAppPlugin::Context = 0;
  26. //----------------------------------------------------------------------------
  27. ctkDicomAppPlugin::ctkDicomAppPlugin()
  28. : AppServer(0), HostInterface(0)
  29. {
  30. }
  31. //----------------------------------------------------------------------------
  32. ctkDicomAppPlugin::~ctkDicomAppPlugin()
  33. {
  34. delete this->AppServer;
  35. delete this->HostInterface;
  36. ctkDicomAppPlugin::Context = 0;
  37. }
  38. //----------------------------------------------------------------------------
  39. void ctkDicomAppPlugin::start(ctkPluginContext* context)
  40. {
  41. bool canStart = true;
  42. ctkDicomAppPlugin::Context = context;
  43. QUrl appURL(context->getProperty("dah.appURL").toString());
  44. if (!appURL.isValid())
  45. {
  46. //throw ctkRuntimeException("The plugin framework does not contain a valid \"dah.appURL\" property");
  47. qDebug() << "ctkDicomAppPlugin: The plugin framework does not contain a valid \"dah.appURL\" property";
  48. canStart = false;
  49. }
  50. QUrl hostURL(context->getProperty("dah.hostURL").toString());
  51. if (!hostURL.isValid())
  52. {
  53. //throw ctkRuntimeException("The plugin framework does not contain a valid \"dah.hostURL\" property");
  54. qDebug() << "ctkDicomAppPlugin: The plugin framework does not contain a valid \"dah.hostURL\" property";
  55. canStart = false;
  56. }
  57. if(canStart)
  58. {
  59. // start the application server
  60. this->AppServer = new ctkDicomAppServer(appURL.port(), appURL.path());
  61. // register the host service, providing callbacks to the hosting application
  62. this->HostInterface = new ctkDicomHostService(QUrl(hostURL).port(), hostURL.path());
  63. context->registerService<ctkDicomHostInterface>(HostInterface);
  64. }
  65. }
  66. //----------------------------------------------------------------------------
  67. void ctkDicomAppPlugin::stop(ctkPluginContext* context)
  68. {
  69. Q_UNUSED(context)
  70. delete this->AppServer;
  71. delete this->HostInterface;
  72. this->AppServer = 0;
  73. this->HostInterface = 0;
  74. this->Context = 0;
  75. }
  76. //----------------------------------------------------------------------------
  77. ctkPluginContext* ctkDicomAppPlugin::getPluginContext()
  78. {
  79. return ctkDicomAppPlugin::Context;
  80. }
  81. #if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
  82. Q_EXPORT_PLUGIN2(org_commontk_dah_hostedapp, ctkDicomAppPlugin)
  83. #endif