ctkDicomAbstractHost.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. // CTK includes
  16. #include "ctkDicomAppService.h"
  17. #include "ctkDicomAbstractHost.h"
  18. #include "ctkDicomHostServer.h"
  19. #include <ctkDicomObjectLocatorCache.h>
  20. class ctkDicomAbstractHostPrivate
  21. {
  22. public:
  23. ctkDicomAbstractHostPrivate(ctkDicomAbstractHost* hostInterface, int HostPort, int AppPort);
  24. ~ctkDicomAbstractHostPrivate();
  25. int HostPort;
  26. int AppPort;
  27. ctkDicomHostServer* Server;
  28. ctkDicomAppInterface* AppService;
  29. ctkDicomObjectLocatorCache ObjectLocatorCache;
  30. // ctkDicomAppHosting::Status
  31. };
  32. //----------------------------------------------------------------------------
  33. // ctkDicomAbstractHostPrivate methods
  34. //----------------------------------------------------------------------------
  35. ctkDicomAbstractHostPrivate::ctkDicomAbstractHostPrivate(
  36. ctkDicomAbstractHost* hostInterface, int hostPort, int appPort) : HostPort(hostPort), AppPort(appPort)
  37. {
  38. // start server
  39. if (this->HostPort == 0)
  40. {
  41. this->HostPort = 8080;
  42. }
  43. if (this->AppPort == 0)
  44. {
  45. this->AppPort = 8081;
  46. }
  47. this->Server = new ctkDicomHostServer(hostInterface,hostPort);
  48. this->AppService = new ctkDicomAppService(appPort, "/ApplicationInterface");
  49. }
  50. //----------------------------------------------------------------------------
  51. ctkDicomAbstractHostPrivate::~ctkDicomAbstractHostPrivate()
  52. {
  53. delete this->Server;
  54. this->Server = 0;
  55. //do not delete AppService, deleted somewhere else before?
  56. //delete this->AppService;
  57. //this->AppService = 0;
  58. }
  59. //----------------------------------------------------------------------------
  60. // ctkDicomAbstractHost methods
  61. //----------------------------------------------------------------------------
  62. ctkDicomAbstractHost::ctkDicomAbstractHost(int hostPort, int appPort) :
  63. d_ptr(new ctkDicomAbstractHostPrivate(this, hostPort, appPort))
  64. {
  65. }
  66. //----------------------------------------------------------------------------
  67. ctkDicomAbstractHost::~ctkDicomAbstractHost()
  68. {
  69. }
  70. //----------------------------------------------------------------------------
  71. int ctkDicomAbstractHost::getHostPort() const
  72. {
  73. Q_D(const ctkDicomAbstractHost);
  74. return d->HostPort;
  75. }
  76. //----------------------------------------------------------------------------
  77. int ctkDicomAbstractHost::getAppPort() const
  78. {
  79. Q_D(const ctkDicomAbstractHost);
  80. return d->AppPort;
  81. }
  82. //----------------------------------------------------------------------------
  83. ctkDicomAppInterface* ctkDicomAbstractHost::getDicomAppService() const
  84. {
  85. Q_D(const ctkDicomAbstractHost);
  86. return d->AppService;
  87. }
  88. //----------------------------------------------------------------------------
  89. QList<ctkDicomAppHosting::ObjectLocator> ctkDicomAbstractHost::getData(
  90. const QList<QUuid>& objectUUIDs,
  91. const QList<QString>& acceptableTransferSyntaxUIDs,
  92. bool includeBulkData)
  93. {
  94. return this->objectLocatorCache()->getData(objectUUIDs, acceptableTransferSyntaxUIDs, includeBulkData);
  95. }
  96. //----------------------------------------------------------------------------
  97. ctkDicomObjectLocatorCache* ctkDicomAbstractHost::objectLocatorCache()const
  98. {
  99. Q_D(const ctkDicomAbstractHost);
  100. return const_cast<ctkDicomObjectLocatorCache*>(&d->ObjectLocatorCache);
  101. }
  102. //----------------------------------------------------------------------------
  103. bool ctkDicomAbstractHost::publishData(const ctkDicomAppHosting::AvailableData& availableData, bool lastData)
  104. {
  105. if (!this->objectLocatorCache()->isCached(availableData))
  106. {
  107. return false;
  108. }
  109. bool success = this->getDicomAppService()->notifyDataAvailable(availableData, lastData);
  110. if(!success)
  111. {
  112. return false;
  113. }
  114. return true;
  115. }