ctkExampleDicomHost.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. ApplicationState(ctkDicomAppHosting::IDLE)
  29. {
  30. //connect(&this->AppProcess,SIGNAL(readyReadStandardOutput()),SLOT(forwardConsoleOutput()));
  31. }
  32. //----------------------------------------------------------------------------
  33. void ctkExampleDicomHost::StartApplication(QString AppPath)
  34. {
  35. QStringList arguments;
  36. arguments.append("--hostURL");
  37. arguments.append(QString("http://localhost:") + QString::number(this->getHostPort()) + "/HostInterface" );
  38. arguments.append("--applicationURL");
  39. arguments.append(QString("http://localhost:") + QString::number(this->getAppPort()) + "/ApplicationInterface" );
  40. //by default, the ctkExampleHostedApp uses the org.commontk.dah.exampleapp plugin
  41. //arguments.append("dicomapp"); // the app plugin to use - has to be changed later
  42. //if (!QProcess::startDetached (
  43. //{
  44. // qCritical() << "application failed to start!";
  45. //}
  46. //qDebug() << "starting application: " << AppPath << " " << arguments;
  47. qDebug() << "starting application: " << AppPath << " " << arguments;
  48. this->AppProcess.setProcessChannelMode(QProcess::MergedChannels);
  49. this->AppProcess.start(AppPath, arguments);
  50. }
  51. //----------------------------------------------------------------------------
  52. QRect ctkExampleDicomHost::getAvailableScreen(const QRect& preferredScreen)
  53. {
  54. qDebug()<< "Application asked for this area:"<< preferredScreen;
  55. QRect rect (this->PlaceholderWidget->getAbsolutePosition());
  56. emit giveAvailableScreen(rect);
  57. return rect;
  58. }
  59. //----------------------------------------------------------------------------
  60. void ctkExampleDicomHost::notifyStateChanged(ctkDicomAppHosting::State state)
  61. {
  62. qDebug()<< "new state received:"<< static_cast<int>(state);
  63. qDebug()<< "new state received:"<< ctkDicomSoapState::toStringValue(state);
  64. emit stateChangedReceived(state);
  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. void ctkExampleDicomHost::forwardConsoleOutput()
  82. {
  83. while( this->AppProcess.bytesAvailable() )
  84. {
  85. QString line( this->AppProcess.readLine() );
  86. line.prepend(">>>> ");
  87. std::cout << line.toStdString();
  88. }
  89. }
  90. //----------------------------------------------------------------------------
  91. bool ctkExampleDicomHost::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
  92. {
  93. Q_UNUSED(data)
  94. Q_UNUSED(lastData)
  95. return false;
  96. }
  97. //----------------------------------------------------------------------------
  98. QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomHost::getData(
  99. const QList<QUuid>& objectUUIDs,
  100. const QList<QString>& acceptableTransferSyntaxUIDs,
  101. bool includeBulkData)
  102. {
  103. Q_UNUSED(includeBulkData)
  104. Q_UNUSED(acceptableTransferSyntaxUIDs)
  105. //stupid test: only works with one uuid
  106. QList<ctkDicomAppHosting::ObjectLocator> locators;
  107. QUuid uuid;
  108. QUuid testUuid("{11111111-1111-1111-1111-111111111111}");
  109. foreach(uuid, objectUUIDs)
  110. {
  111. //stupid test: only works with one uuid
  112. if (uuid == testUuid)
  113. {
  114. ctkDicomAppHosting::ObjectLocator objectLocator;
  115. objectLocator.locator = QUuid();
  116. objectLocator.source = QUuid();
  117. //need to filter transfert syntax with acceptable ones
  118. objectLocator.transferSyntax = "transSyntaxUId";
  119. objectLocator.length = 0;
  120. objectLocator.offset = 0;
  121. objectLocator.URI = "testFile.txt";
  122. locators.append (objectLocator);
  123. }
  124. return locators;
  125. }
  126. return QList<ctkDicomAppHosting::ObjectLocator>();
  127. }
  128. //----------------------------------------------------------------------------
  129. void ctkExampleDicomHost::releaseData(const QList<QUuid>& objectUUIDs)
  130. {
  131. Q_UNUSED(objectUUIDs)
  132. }