ctkExampleDicomHost.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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 <QProcess>
  17. #include <QtDebug>
  18. #include <QRect>
  19. // CTK includes
  20. #include "ctkExampleDicomHost.h"
  21. #include "ctkDicomAppHostingTypesHelper.h"
  22. // STD includes
  23. #include <iostream>
  24. //----------------------------------------------------------------------------
  25. ctkExampleDicomHost::ctkExampleDicomHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort, int appPort) :
  26. ctkDicomAbstractHost(hostPort, appPort),
  27. PlaceholderWidget(placeholderWidget),
  28. exitingApplication(false)
  29. {
  30. connect(this,SIGNAL(appReady()),SLOT(onAppReady()));
  31. connect(this,SIGNAL(startProgress()),this,SLOT(onStartProgress()));
  32. connect(this,SIGNAL(releaseAvailableResources()),this,SLOT(onReleaseAvailableResources()));
  33. connect(this,SIGNAL(resumed()),this,SLOT(onResumed()));
  34. connect(this,SIGNAL(completed()),this,SLOT(onCompleted()));
  35. connect(this,SIGNAL(suspended()),this,SLOT(onSuspended()));
  36. connect(this,SIGNAL(canceled()),this,SLOT(onCanceled()));
  37. connect(this,SIGNAL(exited()),this,SLOT(onExited()));
  38. }
  39. //----------------------------------------------------------------------------
  40. void ctkExampleDicomHost::StartApplication(QString AppPath)
  41. {
  42. QStringList arguments;
  43. arguments.append("--hostURL");
  44. arguments.append(QString("http://localhost:") + QString::number(this->getHostPort()) + "/HostInterface" );
  45. arguments.append("--applicationURL");
  46. arguments.append(QString("http://localhost:") + QString::number(this->getAppPort()) + "/ApplicationInterface" );
  47. //by default, the ctkExampleHostedApp uses the org.commontk.dah.exampleapp plugin
  48. //arguments.append("dicomapp"); // the app plugin to use - has to be changed later
  49. //if (!QProcess::startDetached (
  50. //{
  51. // qCritical() << "application failed to start!";
  52. //}
  53. //qDebug() << "starting application: " << AppPath << " " << arguments;
  54. qDebug() << "starting application: " << AppPath << " " << arguments;
  55. this->AppProcess.setProcessChannelMode(QProcess::MergedChannels);
  56. this->AppProcess.start(AppPath, arguments);
  57. }
  58. //----------------------------------------------------------------------------
  59. QRect ctkExampleDicomHost::getAvailableScreen(const QRect& preferredScreen)
  60. {
  61. qDebug()<< "Application asked for this area:"<< preferredScreen;
  62. QRect rect (this->PlaceholderWidget->getAbsolutePosition());
  63. emit giveAvailableScreen(rect);
  64. return rect;
  65. }
  66. //----------------------------------------------------------------------------
  67. void ctkExampleDicomHost::notifyStatus(const ctkDicomAppHosting::Status& status)
  68. {
  69. qDebug()<< "new status received:"<<status.codeMeaning;
  70. emit statusReceived(status);;
  71. }
  72. //----------------------------------------------------------------------------
  73. ctkExampleDicomHost::~ctkExampleDicomHost()
  74. {
  75. qDebug() << "Exiting host: trying to terminate app";
  76. this->AppProcess.terminate();
  77. qDebug() << "Exiting host: trying to kill app";
  78. this->AppProcess.kill();
  79. }
  80. //----------------------------------------------------------------------------
  81. bool ctkExampleDicomHost::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
  82. {
  83. Q_UNUSED(data)
  84. Q_UNUSED(lastData)
  85. return false;
  86. }
  87. //----------------------------------------------------------------------------
  88. void ctkExampleDicomHost::onAppReady()
  89. {
  90. //prepare some resources...
  91. //tell app to start
  92. //getDicomAppService()->setState(ctkDicomAppHosting::INPROGRESS);
  93. qDebug() << "App ready to work";
  94. if (this->exitingApplication)
  95. {
  96. this->exitingApplication = false;
  97. getDicomAppService ()->setState (ctkDicomAppHosting::EXIT);
  98. }
  99. }
  100. //----------------------------------------------------------------------------
  101. void ctkExampleDicomHost::onStartProgress()
  102. {
  103. ctkDicomAppHosting::ObjectDescriptor ourObjectDescriptor;
  104. QList<ctkDicomAppHosting::Study> studies;
  105. ctkDicomAppHosting::AvailableData data;
  106. ctkDicomAppHosting::Patient patient;
  107. patient.name = "John Doe";
  108. patient.id = "0000";
  109. patient.assigningAuthority = "authority";
  110. patient.sex = "male";
  111. patient.birthDate = "today";
  112. patient.objectDescriptors = QList<ctkDicomAppHosting::ObjectDescriptor>();
  113. patient.studies = studies;
  114. ourObjectDescriptor.descriptorUUID = QUuid("{11111111-1111-1111-1111-111111111111}");
  115. ourObjectDescriptor.mimeType = "text/plain";
  116. ourObjectDescriptor.classUID = "lovelyClass";
  117. ourObjectDescriptor.transferSyntaxUID = "transSyntaxUId";
  118. ourObjectDescriptor.modality = "modMod";
  119. data.objectDescriptors = QList<ctkDicomAppHosting::ObjectDescriptor>();
  120. data.objectDescriptors.append (ourObjectDescriptor);
  121. data.patients = QList<ctkDicomAppHosting::Patient>();
  122. data.patients.append (patient);
  123. qDebug()<<"send dataDescriptors";
  124. bool reply = getDicomAppService()->notifyDataAvailable (data,true);
  125. qDebug() << " notifyDataAvailable(1111) returned: " << reply;
  126. }
  127. //----------------------------------------------------------------------------
  128. void ctkExampleDicomHost::onResumed()
  129. {
  130. qDebug() << "App resumed work";
  131. }
  132. //----------------------------------------------------------------------------
  133. void ctkExampleDicomHost::onCompleted()
  134. {
  135. qDebug() << "App finished processing";
  136. }
  137. //----------------------------------------------------------------------------
  138. void ctkExampleDicomHost::onSuspended()
  139. {
  140. qDebug() << "App paused";
  141. }
  142. //----------------------------------------------------------------------------
  143. void ctkExampleDicomHost::onCanceled()
  144. {
  145. qDebug() << "App canceled";
  146. }
  147. //----------------------------------------------------------------------------
  148. void ctkExampleDicomHost::onExited()
  149. {
  150. qDebug() << "App exited";
  151. }
  152. //----------------------------------------------------------------------------
  153. void ctkExampleDicomHost::onReleaseAvailableResources()
  154. {
  155. qDebug() << "Should release resources put at the disposition of the app";
  156. }
  157. //----------------------------------------------------------------------------
  158. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomHost::getData(
  159. const QList<QUuid>& objectUUIDs,
  160. const QList<QString>& acceptableTransferSyntaxUIDs,
  161. bool includeBulkData)
  162. {
  163. Q_UNUSED(includeBulkData)
  164. Q_UNUSED(acceptableTransferSyntaxUIDs)
  165. //stupid test: only works with one uuid
  166. QList<ctkDicomAppHosting::ObjectLocator> locators;
  167. QUuid uuid;
  168. QUuid testUuid("{11111111-1111-1111-1111-111111111111}");
  169. foreach(uuid, objectUUIDs)
  170. {
  171. //stupid test: only works with one uuid
  172. if (uuid == testUuid)
  173. {
  174. ctkDicomAppHosting::ObjectLocator objectLocator;
  175. objectLocator.locator = QUuid();
  176. objectLocator.source = QUuid();
  177. //need to filter transfert syntax with acceptable ones
  178. objectLocator.transferSyntax = "transSyntaxUId";
  179. objectLocator.length = 0;
  180. objectLocator.offset = 0;
  181. objectLocator.URI = "testFile.txt";
  182. locators.append (objectLocator);
  183. }
  184. return locators;
  185. }
  186. return QList<ctkDicomAppHosting::ObjectLocator>();
  187. }
  188. //----------------------------------------------------------------------------
  189. void ctkExampleDicomHost::releaseData(const QList<QUuid>& objectUUIDs)
  190. {
  191. Q_UNUSED(objectUUIDs)
  192. }
  193. void ctkExampleDicomHost::exitApplication()
  194. {
  195. this->exitingApplication=true;
  196. getDicomAppService ()->setState (ctkDicomAppHosting::CANCELED);
  197. }