ctkDicomAbstractHost.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. // ctkDicomAppHosting::Status
  33. };
  34. //----------------------------------------------------------------------------
  35. // ctkDicomAbstractHostPrivate methods
  36. //----------------------------------------------------------------------------
  37. ctkDicomAbstractHostPrivate::ctkDicomAbstractHostPrivate(
  38. ctkDicomAbstractHost* hostInterface, int hostPort, int appPort) : HostPort(hostPort), AppPort(appPort), AppState(ctkDicomAppHosting::EXIT)
  39. {
  40. // start server
  41. if (this->HostPort == 0)
  42. {
  43. this->HostPort = 8080;
  44. }
  45. if (this->AppPort == 0)
  46. {
  47. this->AppPort = 8081;
  48. }
  49. this->Server = new ctkDicomHostServer(hostInterface, hostPort, "/HostService-20100825");
  50. this->AppService = new ctkDicomAppService(appPort, "/ApplicationService-20100825"); //ApplicationInterface
  51. }
  52. //----------------------------------------------------------------------------
  53. ctkDicomAbstractHostPrivate::~ctkDicomAbstractHostPrivate()
  54. {
  55. delete this->Server;
  56. this->Server = 0;
  57. //do not delete AppService, deleted somewhere else before?
  58. //delete this->AppService;
  59. //this->AppService = 0;
  60. }
  61. //----------------------------------------------------------------------------
  62. // ctkDicomAbstractHost methods
  63. //----------------------------------------------------------------------------
  64. ctkDicomAbstractHost::ctkDicomAbstractHost(int hostPort, int appPort) :
  65. d_ptr(new ctkDicomAbstractHostPrivate(this, hostPort, appPort))
  66. {
  67. }
  68. //----------------------------------------------------------------------------
  69. ctkDicomAbstractHost::~ctkDicomAbstractHost()
  70. {
  71. }
  72. //----------------------------------------------------------------------------
  73. int ctkDicomAbstractHost::getHostPort() const
  74. {
  75. Q_D(const ctkDicomAbstractHost);
  76. return d->HostPort;
  77. }
  78. //----------------------------------------------------------------------------
  79. int ctkDicomAbstractHost::getAppPort() const
  80. {
  81. Q_D(const ctkDicomAbstractHost);
  82. return d->AppPort;
  83. }
  84. //----------------------------------------------------------------------------
  85. ctkDicomAppInterface* ctkDicomAbstractHost::getDicomAppService() const
  86. {
  87. Q_D(const ctkDicomAbstractHost);
  88. return d->AppService;
  89. }
  90. //----------------------------------------------------------------------------
  91. ctkDicomExchangeInterface* ctkDicomAbstractHost::getOtherSideExchangeService() const
  92. {
  93. return getDicomAppService();
  94. }
  95. //----------------------------------------------------------------------------
  96. void ctkDicomAbstractHost::notifyStateChanged(ctkDicomAppHosting::State newState)
  97. {
  98. qDebug()<< "new state notification received:"<< static_cast<int>(newState);
  99. qDebug()<< "new state notification received:"<< ctkDicomSoapState::toStringValue(newState);
  100. switch (newState){
  101. case ctkDicomAppHosting::IDLE:
  102. if (d_ptr->AppState == ctkDicomAppHosting::COMPLETED)
  103. {
  104. d_ptr->AppState = ctkDicomAppHosting::IDLE;
  105. releaseAvailableResources();
  106. }
  107. else if(d_ptr->AppState == ctkDicomAppHosting::EXIT
  108. || d_ptr->AppState == ctkDicomAppHosting::IDLE
  109. || d_ptr->AppState == ctkDicomAppHosting::CANCELED)
  110. {
  111. d_ptr->AppState = ctkDicomAppHosting::IDLE;
  112. emit appReady();
  113. }
  114. else{
  115. qDebug() << "Wrong transition from" << static_cast<int> (d_ptr->AppState)
  116. << "to:" << static_cast<int>(newState);
  117. }
  118. break;
  119. case ctkDicomAppHosting::INPROGRESS:
  120. if (d_ptr->AppState == ctkDicomAppHosting::IDLE)
  121. {
  122. emit startProgress();
  123. }
  124. else if(d_ptr->AppState == ctkDicomAppHosting::SUSPENDED)
  125. {
  126. //shouldn't be necessary, but can be useful for feedback
  127. emit resumed();
  128. }
  129. else
  130. {
  131. qDebug() << "Wrong transition from" << static_cast<int>(d_ptr->AppState)
  132. << "to:" << static_cast<int>(newState);
  133. }
  134. break;
  135. case ctkDicomAppHosting::COMPLETED:
  136. emit completed();
  137. break;
  138. case ctkDicomAppHosting::SUSPENDED:
  139. //shouldn't be necessary, but can be useful for feedback
  140. emit suspended();
  141. break;
  142. case ctkDicomAppHosting::CANCELED:
  143. //the app is in the process of canceling.
  144. //perhaps filtering for answers to a cancel commands and a cancel because of an error in the client
  145. emit canceled();
  146. break;
  147. case ctkDicomAppHosting::EXIT:
  148. //check if current state is IDLE
  149. emit exited();
  150. break;
  151. default:
  152. //should never happen
  153. qDebug() << "unexisting state Code, do nothing";
  154. }
  155. d_ptr->AppState = newState;
  156. emit stateChangedReceived(newState);
  157. }
  158. ctkDicomAppHosting::State ctkDicomAbstractHost::getApplicationState()const
  159. {
  160. // todo: probably move code from ctkExampleHostWidget::getApplicationState() here
  161. return d_ptr->AppState;
  162. }