ctkDicomExampleHost.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "ctkDicomExampleHost.h"
  2. #include "ctkDicomWG23TypesHelper.h"
  3. #include <QProcess>
  4. #include <QtDebug>
  5. #include <QRect>
  6. #include <iostream>
  7. ctkDicomExampleHost::ctkDicomExampleHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort, int appPort) :
  8. ctkDicomAbstractHost(hostPort, appPort),
  9. placeholderWidget(placeholderWidget),
  10. applicationState(ctkDicomWG23::IDLE)
  11. {
  12. connect(&this->appProcess,SIGNAL(readyReadStandardOutput()),SLOT(forwardConsoleOutput()));
  13. }
  14. void ctkDicomExampleHost::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 ctkDicomExampleHost::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 ctkDicomExampleHost::notifyStateChanged(ctkDicomWG23::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 ctkDicomExampleHost::notifyStatus(const ctkDicomWG23::Status& status){
  43. qDebug()<< "new status received:"<<status.codeMeaning;
  44. emit statusReceived(status);;
  45. }
  46. ctkDicomExampleHost::~ctkDicomExampleHost()
  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 ctkDicomExampleHost::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 ctkDicomExampleHost::notifyDataAvailable(ctkDicomWG23::AvailableData data, bool lastData)
  63. {
  64. return false;
  65. }
  66. QList<ctkDicomWG23::ObjectLocator>* ctkDicomExampleHost::getData(
  67. QList<QUuid> objectUUIDs,
  68. QList<QString> acceptableTransferSyntaxUIDs,
  69. bool includeBulkData)
  70. {
  71. return NULL;
  72. }
  73. void ctkDicomExampleHost::releaseData(QList<QUuid> objectUUIDs)
  74. {
  75. }