ctkDicomAbstractHost.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 "ctkDicomAppService.h"
  20. #include "ctkDicomAppHostingTypesHelper.h"
  21. #include <ctkDicomObjectLocatorCache.h>
  22. class ctkDicomAbstractHostPrivate
  23. {
  24. public:
  25. ctkDicomAbstractHostPrivate(ctkDicomAbstractHost* hostInterface, int HostPort, int AppPort);
  26. ~ctkDicomAbstractHostPrivate();
  27. int HostPort;
  28. int AppPort;
  29. ctkDicomHostServer* Server;
  30. ctkDicomAppInterface* AppService;
  31. ctkDicomAppHosting::State AppState;
  32. ctkDicomObjectLocatorCache ObjectLocatorCache;
  33. // ctkDicomAppHosting::Status
  34. };
  35. //----------------------------------------------------------------------------
  36. // ctkDicomAbstractHostPrivate methods
  37. //----------------------------------------------------------------------------
  38. ctkDicomAbstractHostPrivate::ctkDicomAbstractHostPrivate(
  39. ctkDicomAbstractHost* hostInterface, int hostPort, int appPort) : HostPort(hostPort), AppPort(appPort),AppState(ctkDicomAppHosting::EXIT)
  40. {
  41. // start server
  42. if (this->HostPort == 0)
  43. {
  44. this->HostPort = 8080;
  45. }
  46. if (this->AppPort == 0)
  47. {
  48. this->AppPort = 8081;
  49. }
  50. this->Server = new ctkDicomHostServer(hostInterface, hostPort, "/HostService-20100825");
  51. this->AppService = new ctkDicomAppService(appPort, "/ApplicationService-20100825"); //ApplicationInterface
  52. }
  53. //----------------------------------------------------------------------------
  54. ctkDicomAbstractHostPrivate::~ctkDicomAbstractHostPrivate()
  55. {
  56. delete this->Server;
  57. this->Server = 0;
  58. //do not delete AppService, deleted somewhere else before?
  59. //delete this->AppService;
  60. //this->AppService = 0;
  61. }
  62. //----------------------------------------------------------------------------
  63. // ctkDicomAbstractHost methods
  64. //----------------------------------------------------------------------------
  65. ctkDicomAbstractHost::ctkDicomAbstractHost(int hostPort, int appPort) :
  66. d_ptr(new ctkDicomAbstractHostPrivate(this, hostPort, appPort))
  67. {
  68. }
  69. //----------------------------------------------------------------------------
  70. ctkDicomAbstractHost::~ctkDicomAbstractHost()
  71. {
  72. }
  73. //----------------------------------------------------------------------------
  74. int ctkDicomAbstractHost::getHostPort() const
  75. {
  76. Q_D(const ctkDicomAbstractHost);
  77. return d->HostPort;
  78. }
  79. //----------------------------------------------------------------------------
  80. int ctkDicomAbstractHost::getAppPort() const
  81. {
  82. Q_D(const ctkDicomAbstractHost);
  83. return d->AppPort;
  84. }
  85. //----------------------------------------------------------------------------
  86. ctkDicomAppInterface* ctkDicomAbstractHost::getDicomAppService() const
  87. {
  88. Q_D(const ctkDicomAbstractHost);
  89. return d->AppService;
  90. }
  91. //----------------------------------------------------------------------------
  92. QList<ctkDicomAppHosting::ObjectLocator> ctkDicomAbstractHost::getData(
  93. const QList<QUuid>& objectUUIDs,
  94. const QList<QString>& acceptableTransferSyntaxUIDs,
  95. bool includeBulkData)
  96. {
  97. Q_UNUSED(acceptableTransferSyntaxUIDs);
  98. Q_UNUSED(includeBulkData);
  99. return this->objectLocatorCache()->getData(objectUUIDs);
  100. }
  101. //----------------------------------------------------------------------------
  102. ctkDicomObjectLocatorCache* ctkDicomAbstractHost::objectLocatorCache()const
  103. {
  104. Q_D(const ctkDicomAbstractHost);
  105. return const_cast<ctkDicomObjectLocatorCache*>(&d->ObjectLocatorCache);
  106. }
  107. //----------------------------------------------------------------------------
  108. bool ctkDicomAbstractHost::publishData(const ctkDicomAppHosting::AvailableData& availableData, bool lastData)
  109. {
  110. if (!this->objectLocatorCache()->isCached(availableData))
  111. {
  112. return false;
  113. }
  114. bool success = this->getDicomAppService()->notifyDataAvailable(availableData, lastData);
  115. if(!success)
  116. {
  117. return false;
  118. }
  119. return true;
  120. }
  121. //----------------------------------------------------------------------------
  122. void ctkDicomAbstractHost::notifyStateChanged(ctkDicomAppHosting::State newState)
  123. {
  124. qDebug()<< "new state notification received:"<< static_cast<int>(newState);
  125. qDebug()<< "new state notification received:"<< ctkDicomSoapState::toStringValue(newState);
  126. switch (newState){
  127. case ctkDicomAppHosting::IDLE:
  128. if (d_ptr->AppState == ctkDicomAppHosting::COMPLETED)
  129. {
  130. d_ptr->AppState = ctkDicomAppHosting::IDLE;
  131. releaseAvailableResources();
  132. }
  133. else if(d_ptr->AppState == ctkDicomAppHosting::EXIT
  134. || d_ptr->AppState == ctkDicomAppHosting::IDLE
  135. || d_ptr->AppState == ctkDicomAppHosting::CANCELED)
  136. {
  137. d_ptr->AppState = ctkDicomAppHosting::IDLE;
  138. emit appReady();
  139. }
  140. else{
  141. qDebug() << "Wrong transition from" << static_cast<int> (d_ptr->AppState)
  142. << "to:" << static_cast<int>(newState);
  143. }
  144. break;
  145. case ctkDicomAppHosting::INPROGRESS:
  146. if (d_ptr->AppState == ctkDicomAppHosting::IDLE)
  147. {
  148. emit startProgress();
  149. }
  150. else if(d_ptr->AppState == ctkDicomAppHosting::SUSPENDED)
  151. {
  152. //shouldn't be necessary, but can be useful for feedback
  153. emit resumed();
  154. }
  155. else
  156. {
  157. qDebug() << "Wrong transition from" << static_cast<int>(d_ptr->AppState)
  158. << "to:" << static_cast<int>(newState);
  159. }
  160. break;
  161. case ctkDicomAppHosting::COMPLETED:
  162. emit completed();
  163. break;
  164. case ctkDicomAppHosting::SUSPENDED:
  165. //shouldn't be necessary, but can be useful for feedback
  166. emit suspended();
  167. break;
  168. case ctkDicomAppHosting::CANCELED:
  169. //the app is in the process of canceling.
  170. //perhaps filtering for answers to a cancel commands and a cancel because of an error in the client
  171. emit canceled();
  172. break;
  173. case ctkDicomAppHosting::EXIT:
  174. //check if current state is IDLE
  175. emit exited();
  176. break;
  177. default:
  178. //should never happen
  179. qDebug() << "unexisting state Code, do nothing";
  180. }
  181. d_ptr->AppState = newState;
  182. emit stateChangedReceived(newState);
  183. }
  184. ctkDicomAppHosting::State ctkDicomAbstractHost::getApplicationState()const
  185. {
  186. return d_ptr->AppState;
  187. }