ctkDicomHostServerPrivate.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "ctkDicomHostServerPrivate.h"
  16. #include <ctkDicomHostInterface.h>
  17. #include <QHostAddress>
  18. #include <stdexcept>
  19. #include <ctkDicomWG23TypesHelper.h>
  20. ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port) :
  21. hostInterface(hostInterface), port(port)
  22. {
  23. connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
  24. this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
  25. connect(&server, SIGNAL(incomingWSDLMessage(QString,QString*)),
  26. this, SLOT(incomingWSDLMessage(QString,QString*)));
  27. if (!server.listen(QHostAddress::LocalHost, this->port))
  28. {
  29. qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
  30. }
  31. }
  32. void ctkDicomHostServerPrivate::incomingWSDLMessage(
  33. const QString& message, QString* reply)
  34. {
  35. if (message == "wsdl")
  36. {
  37. QFile wsdlfile(":/dah/HostService.wsdl");
  38. wsdlfile.open(QFile::ReadOnly | QFile::Text);
  39. if(wsdlfile.isOpen())
  40. {
  41. QTextStream textstream(&wsdlfile);
  42. *reply = textstream.readAll();
  43. reply->replace("REPLACE_WITH_ACTUAL_URL","http://127.0.0.1:8080/HostInterface");
  44. reply->replace("HostService_schema1.xsd","http://127.0.0.1:8080/HostInterface?xsd=1");
  45. }
  46. }
  47. }
  48. void ctkDicomHostServerPrivate::incomingSoapMessage(
  49. const QtSoapMessage& message, QtSoapMessage* reply)
  50. {
  51. const QtSoapType& method = message.method();
  52. QString methodName = method.name().name();
  53. qDebug() << "HostServer: Received soap method request: " << methodName;
  54. if (methodName == "getAvailableScreen")
  55. {
  56. processGetAvailableScreen(message, reply);
  57. }
  58. else if (methodName == "notifyStateChanged")
  59. {
  60. processNotifyStateChanged(message, reply);
  61. }
  62. else if (methodName == "notifyStatus")
  63. {
  64. processNotifyStatus(message, reply);
  65. }
  66. else if (methodName == "generateUID")
  67. {
  68. processGenerateUID(message, reply);
  69. }
  70. else if (methodName == "getOutputLocation")
  71. {
  72. processGetOutputLocation(message, reply);
  73. }
  74. else
  75. {
  76. // error
  77. reply->setFaultCode( QtSoapMessage::Server );
  78. reply->setFaultString( "Unknown method." );
  79. }
  80. }
  81. void ctkDicomHostServerPrivate::processGetAvailableScreen(
  82. const QtSoapMessage &message, QtSoapMessage *reply) const
  83. {
  84. const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
  85. const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(preferredScreenType);
  86. const QRect result = hostInterface->getAvailableScreen(preferredScreen);
  87. reply->setMethod("getAvailableScreenResponse");
  88. QtSoapStruct* availableScreenType = new ctkDicomSoapRectangle("availableScreen",result);
  89. reply->addMethodArgument(availableScreenType);
  90. }
  91. void ctkDicomHostServerPrivate::processNotifyStateChanged(
  92. const QtSoapMessage &message, QtSoapMessage * /* reply */) const
  93. {
  94. const QtSoapType& stateType = message.method()["state"];
  95. hostInterface->notifyStateChanged(ctkDicomSoapState::getState(stateType));
  96. }
  97. void ctkDicomHostServerPrivate::processNotifyStatus(
  98. const QtSoapMessage &message, QtSoapMessage * /* reply */) const
  99. {
  100. const QtSoapType& status = message.method()["status"];
  101. hostInterface->notifyStatus(ctkDicomSoapStatus::getStatus(status));
  102. }
  103. void ctkDicomHostServerPrivate::processGenerateUID(
  104. const QtSoapMessage& message, QtSoapMessage* reply) const
  105. {
  106. const QString uid = hostInterface->generateUID();
  107. reply->setMethod("generateUID");
  108. QtSoapType* type = new ctkDicomSoapUID("uid",uid);
  109. reply->addMethodArgument(type);
  110. }
  111. void ctkDicomHostServerPrivate::processGetOutputLocation(
  112. const QtSoapMessage& message, QtSoapMessage* reply) const
  113. {
  114. const QtSoapType& inputType = message.method()["preferredProtocols"];
  115. const QStringList* preferredProtocols = ctkDicomSoapArrayOfString::getArray(
  116. dynamic_cast<const QtSoapArray&>(inputType));
  117. const QString result = hostInterface->getOutputLocation(*preferredProtocols);
  118. reply->setMethod("getOutputLocation");
  119. QtSoapType* resultType = new QtSoapSimpleType ( QtSoapQName("preferredProtocols"), result );
  120. reply->addMethodArgument(resultType);
  121. }