ctkExampleDicomHost.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include "ctkExampleDicomHost.h"
  16. #include "ctkDicomAppHostingTypesHelper.h"
  17. #include <QProcess>
  18. #include <QtDebug>
  19. #include <QRect>
  20. #include <iostream>
  21. ctkExampleDicomHost::ctkExampleDicomHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort, int appPort) :
  22. ctkDicomAbstractHost(hostPort, appPort),
  23. placeholderWidget(placeholderWidget),
  24. applicationState(ctkDicomAppHosting::IDLE)
  25. {
  26. connect(&this->appProcess,SIGNAL(readyReadStandardOutput()),SLOT(forwardConsoleOutput()));
  27. }
  28. void ctkExampleDicomHost::StartApplication(QString AppPath)
  29. {
  30. QStringList l;
  31. l.append("--hostURL");
  32. l.append(QString("http://localhost:") + QString::number(this->getHostPort()) + "/HostInterface" );
  33. l.append("--applicationURL");
  34. l.append(QString("http://localhost:") + QString::number(this->getAppPort()) + "/ApplicationInterface" );
  35. //by default, the ctkExampleHostedApp uses the org.commontk.dah.exampleapp plugin
  36. //l.append("dicomapp"); // the app plugin to use - has to be changed later
  37. //if (!QProcess::startDetached (
  38. //{
  39. // qCritical() << "application failed to start!";
  40. //}
  41. //qDebug() << "starting application: " << AppPath << " " << l;
  42. qDebug() << "starting application: " << AppPath << " " << l;
  43. this->appProcess.setProcessChannelMode(QProcess::MergedChannels);
  44. this->appProcess.start(AppPath,l);
  45. }
  46. QRect ctkExampleDicomHost::getAvailableScreen(const QRect& preferredScreen)
  47. {
  48. qDebug()<< "Application asked for this area:"<< preferredScreen;
  49. QRect rect (this->placeholderWidget->getAbsolutePosition());
  50. emit giveAvailableScreen(rect);
  51. return rect;
  52. }
  53. void ctkExampleDicomHost::notifyStateChanged(ctkDicomAppHosting::State state)
  54. {
  55. qDebug()<< "new state received:"<< static_cast<int>(state);
  56. qDebug()<< "new state received:"<< ctkDicomSoapState::toStringValue(state);
  57. emit stateChangedReceived(state);
  58. }
  59. void ctkExampleDicomHost::notifyStatus(const ctkDicomAppHosting::Status& status)
  60. {
  61. qDebug()<< "new status received:"<<status.codeMeaning;
  62. emit statusReceived(status);;
  63. }
  64. ctkExampleDicomHost::~ctkExampleDicomHost()
  65. {
  66. qDebug() << "Exiting host: trying to terminate app";
  67. this->appProcess.terminate();
  68. qDebug() << "Exiting host: trying to kill app";
  69. this->appProcess.kill();
  70. }
  71. void ctkExampleDicomHost::forwardConsoleOutput()
  72. {
  73. while( this->appProcess.bytesAvailable() )
  74. {
  75. QString line( this->appProcess.readLine() );
  76. line.prepend(">>>> ");
  77. std::cout << line.toStdString();
  78. }
  79. }
  80. bool ctkExampleDicomHost::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
  81. {
  82. Q_UNUSED(data)
  83. Q_UNUSED(lastData)
  84. return false;
  85. }
  86. QList<ctkDicomAppHosting::ObjectLocator>* ctkExampleDicomHost::getData(
  87. QList<QUuid> objectUUIDs,
  88. QList<QString> acceptableTransferSyntaxUIDs,
  89. bool includeBulkData)
  90. {
  91. Q_UNUSED(objectUUIDs)
  92. Q_UNUSED(acceptableTransferSyntaxUIDs)
  93. Q_UNUSED(includeBulkData)
  94. return NULL;
  95. }
  96. void ctkExampleDicomHost::releaseData(QList<QUuid> objectUUIDs)
  97. {
  98. Q_UNUSED(objectUUIDs)
  99. }