ctkDicomHostServicePrivate.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 "ctkDicomHostServicePrivate.h"
  16. #include <QApplication>
  17. #include <QCursor>
  18. #include <QNetworkReply>
  19. #include <stdexcept>
  20. ctkDicomHostService::ctkDicomHostService()
  21. {
  22. connect(&http, SIGNAL(responseReady()), this, SLOT(responseReady()));
  23. http.setHost("127.0.0.1", false, 8080);
  24. }
  25. void ctkDicomHostService::responseReady()
  26. {
  27. blockingLoop.exit();
  28. }
  29. QString ctkDicomHostService::generateUID()
  30. {
  31. return QString();
  32. }
  33. QRect ctkDicomHostService::getAvailableScreen(const QRect& preferredScreen)
  34. {
  35. http.setAction("GetAvailableScreen");
  36. QtSoapMessage request;
  37. request.setMethod("GetAvailableScreen");
  38. QtSoapStruct* preferredScreenType = new QtSoapStruct(QtSoapQName("preferredScreen"));
  39. preferredScreenType->insert(new QtSoapSimpleType(QtSoapQName("Height"), preferredScreen.height()));
  40. preferredScreenType->insert(new QtSoapSimpleType(QtSoapQName("Width"), preferredScreen.width()));
  41. preferredScreenType->insert(new QtSoapSimpleType(QtSoapQName("RefPointX"), preferredScreen.x()));
  42. preferredScreenType->insert(new QtSoapSimpleType(QtSoapQName("RefPointY"), preferredScreen.y()));
  43. request.addMethodArgument(preferredScreenType);
  44. http.submitRequest(request, "/IHostService");
  45. qDebug() << "Submitted request GetAvailableScreen";
  46. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  47. blockingLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);
  48. QApplication::restoreOverrideCursor();
  49. //qDebug() << "Reply error: " << reply->errorString();
  50. //qDebug() << reply->readAll();
  51. const QtSoapMessage& response = http.getResponse();
  52. if (response.isFault())
  53. {
  54. throw std::runtime_error("server error");
  55. }
  56. qDebug() << "Response: " << response.toXmlString();
  57. const QtSoapType &meth = response.method();
  58. if (!meth.isValid() || meth.type() != QtSoapType::Struct)
  59. qDebug() << "SOAP returning NIL: invalid or type != Struct";
  60. const QtSoapStruct &m = dynamic_cast<const QtSoapStruct &>(meth);
  61. if (m.count() == 0)
  62. qDebug() << "SOAP returning NIL: count == 0";
  63. const QtSoapType& screenResult = response.returnValue();
  64. if (!screenResult.isValid())
  65. {
  66. //throw std::runtime_error("invalid return value");
  67. qDebug() << response.errorString() << response.faultString().toString();
  68. qDebug() << response.toXmlString();
  69. return QRect();
  70. }
  71. qDebug() << screenResult.count() << screenResult["Height"].typeName();
  72. QRect resultRect;
  73. resultRect.setHeight(screenResult["Height"].toInt());
  74. resultRect.setWidth(screenResult["Width"].toInt());
  75. resultRect.setX(screenResult["RefPointX"].toInt());
  76. resultRect.setY(screenResult["RefPointY"].toInt());
  77. qDebug() << "x:" << resultRect.x() << " y:" << resultRect.y();
  78. return resultRect;
  79. }
  80. QString ctkDicomHostService::getOutputLocation(const QStringList& preferredProtocols)
  81. {
  82. Q_UNUSED(preferredProtocols)
  83. return QString();
  84. }
  85. void ctkDicomHostService::notifyStateChanged(ctkDicomWG23::State state)
  86. {
  87. Q_UNUSED(state)
  88. }
  89. void ctkDicomHostService::notifyStatus(const ctkDicomWG23::Status& status)
  90. {
  91. Q_UNUSED(status)
  92. }