ctkDicomExampleHost.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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()) );
  18. l.append("--applicationURL");
  19. l.append(QString("http://localhost:") + QString::number(this->getAppPort()));
  20. l.append("dicomapp"); // the app plugin to use - has to be changed later
  21. qDebug() << "starting application: " << AppPath << " " << l;
  22. this->appProcess.setProcessChannelMode(QProcess::MergedChannels);
  23. this->appProcess.start(AppPath,l);
  24. }
  25. QRect ctkDicomExampleHost::getAvailableScreen(const QRect& preferredScreen){
  26. qDebug()<< "Application asked for this area:"<< preferredScreen;
  27. QRect rect (this->placeholderWidget->getAbsolutePosition());
  28. emit giveAvailableScreen(rect);
  29. return rect;
  30. }
  31. void ctkDicomExampleHost::notifyStateChanged(ctkDicomWG23::State state){
  32. qDebug()<< "new state received:"<< ctkDicomSoapState::toStringValue(state);
  33. emit stateChangedReceived(state);
  34. }
  35. void ctkDicomExampleHost::notifyStatus(const ctkDicomWG23::Status& status){
  36. qDebug()<< "new status received:"<<status.codeMeaning;
  37. emit statusReceived(status);;
  38. }
  39. ctkDicomExampleHost::~ctkDicomExampleHost()
  40. {
  41. qDebug() << "Exiting host: trying to terminate app";
  42. this->appProcess.terminate();
  43. qDebug() << "Exiting host: trying to kill app";
  44. this->appProcess.kill();
  45. }
  46. void ctkDicomExampleHost::forwardConsoleOutput()
  47. {
  48. while( this->appProcess.bytesAvailable() )
  49. {
  50. QString line( this->appProcess.readLine() );
  51. line.prepend(">>>> ");
  52. std::cout << line.toStdString();
  53. }
  54. }