ctkExampleDicomHost.cpp 3.0 KB

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