ctkDicomServicePrivate.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "ctkDicomServicePrivate.h"
  16. #include "ctkDicomAppHostingTypesHelper.h"
  17. #include <QApplication>
  18. #include <QCursor>
  19. #include <QNetworkReply>
  20. #include <stdexcept>
  21. #include <iostream>
  22. ctkDicomServicePrivate::ctkDicomServicePrivate(int port, QString path) : path(path)
  23. {
  24. connect(&http, SIGNAL(responseReady()), this, SLOT(responseReady()));
  25. http.setHost("127.0.0.1", false, port);
  26. }
  27. void ctkDicomServicePrivate::responseReady()
  28. {
  29. blockingLoop.exit();
  30. }
  31. const QtSoapType & ctkDicomServicePrivate::askHost(const QString& methodName,
  32. QtSoapType* soapType )
  33. {
  34. QList<QtSoapType*> list;
  35. list.append(soapType);
  36. return askHost(methodName,list);
  37. }
  38. const QtSoapType & ctkDicomServicePrivate::askHost(const QString& methodName,
  39. const QList<QtSoapType*>& soapTypes )
  40. {
  41. QString action="\"";
  42. //action.append(methodName);
  43. action.append("\"");
  44. http.setAction(action);
  45. std::cout << "Submitting action " << action.toStdString() << " method " << methodName.toStdString() << " to path " << path.toStdString();
  46. QtSoapMessage request;
  47. request.setMethod(QtSoapQName(methodName,"http://wg23.dicom.nema.org/"));
  48. if( !soapTypes.isEmpty())
  49. {
  50. for (QList<QtSoapType*>::ConstIterator it = soapTypes.begin();
  51. it < soapTypes.constEnd(); it++){
  52. request.addMethodArgument(*it);
  53. qDebug() << " Argument type added " << (*it)->typeName() << ". Argument name is " << (*it)->name().name();;
  54. }
  55. }
  56. qDebug() << request.toXmlString();
  57. http.submitRequest(request, path);;
  58. qDebug() << "Submitted request " << methodName ;
  59. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  60. blockingLoop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);
  61. QApplication::restoreOverrideCursor();
  62. //qDebug() << "Reply error: " << reply->errorString();
  63. //qDebug() << reply->readAll();
  64. const QtSoapMessage& response = http.getResponse();
  65. if (response.isFault())
  66. {
  67. qCritical() << "ctkDicomServicePrivate: server error (response.IsFault())";
  68. qDebug() << response.faultString().toString().toLatin1().constData() << endl;
  69. qDebug() << response.toXmlString();
  70. return response.returnValue();
  71. // throw std::runtime_error("ctkDicomServicePrivate: server error (response.IsFault())");
  72. }
  73. qDebug() << "Response: " << response.toXmlString();
  74. const QtSoapType &returnValue = response.returnValue();
  75. qDebug() << " Is returnValue valid:" << returnValue.isValid();
  76. qDebug() << " Name of returnValue:" << returnValue.name().name();
  77. qDebug() << " Value of returnValue:" << returnValue.value().toString();
  78. return returnValue;
  79. }