ctkDicomHostServerPrivate.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if (!server.listen(QHostAddress::LocalHost, this->port))
  26. {
  27. qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
  28. }
  29. }
  30. void ctkDicomHostServerPrivate::incomingSoapMessage(
  31. const QtSoapMessage& message, QtSoapMessage* reply)
  32. {
  33. const QtSoapType& method = message.method();
  34. QString methodName = method.name().name();
  35. qDebug() << "HostServer: Received soap method request: " << methodName;
  36. if (methodName == "getAvailableScreen")
  37. {
  38. processGetAvailableScreen(message, reply);
  39. }
  40. else if (methodName == "notifyStateChanged")
  41. {
  42. processNotifyStateChanged(message, reply);
  43. }
  44. else if (methodName == "notifyStatus")
  45. {
  46. processNotifyStatus(message, reply);
  47. }
  48. else if (methodName == "generateUID")
  49. {
  50. processGenerateUID(message, reply);
  51. }
  52. else if (methodName == "getOutputLocation")
  53. {
  54. processGetOutputLocation(message, reply);
  55. }
  56. else
  57. {
  58. // error
  59. reply->setFaultCode( QtSoapMessage::Server );
  60. reply->setFaultString( "Unknown method." );
  61. }
  62. }
  63. void ctkDicomHostServerPrivate::processGetAvailableScreen(
  64. const QtSoapMessage &message, QtSoapMessage *reply) const
  65. {
  66. const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
  67. const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(preferredScreenType);
  68. const QRect result = hostInterface->getAvailableScreen(preferredScreen);
  69. reply->setMethod("getAvailableScreenResponse");
  70. QtSoapStruct* availableScreenType = new ctkDicomSoapRectangle("availableScreen",result);
  71. reply->addMethodArgument(availableScreenType);
  72. }
  73. void ctkDicomHostServerPrivate::processNotifyStateChanged(
  74. const QtSoapMessage &message, QtSoapMessage * /* reply */) const
  75. {
  76. const QtSoapType& stateType = message.method()["state"];
  77. hostInterface->notifyStateChanged(ctkDicomSoapState::getState(stateType));
  78. }
  79. void ctkDicomHostServerPrivate::processNotifyStatus(
  80. const QtSoapMessage &message, QtSoapMessage * /* reply */) const
  81. {
  82. const QtSoapType& status = message.method()["status"];
  83. hostInterface->notifyStatus(ctkDicomSoapStatus::getStatus(status));
  84. }
  85. void ctkDicomHostServerPrivate::processGenerateUID(
  86. const QtSoapMessage& message, QtSoapMessage* reply) const
  87. {
  88. const QString uid = hostInterface->generateUID();
  89. reply->setMethod("generateUID");
  90. QtSoapType* type = new ctkDicomSoapUID("uid",uid);
  91. reply->addMethodArgument(type);
  92. }
  93. void ctkDicomHostServerPrivate::processGetOutputLocation(
  94. const QtSoapMessage& message, QtSoapMessage* reply) const
  95. {
  96. const QtSoapType& inputType = message.method()["preferredProtocols"];
  97. const QStringList* preferredProtocols = ctkDicomSoapArrayOfStringType::getArray(
  98. dynamic_cast<const QtSoapArray&>(inputType));
  99. const QString result = hostInterface->getOutputLocation(*preferredProtocols);
  100. reply->setMethod("getOutputLocation");
  101. QtSoapType* resultType = new QtSoapSimpleType ( QtSoapQName("preferredProtocols"), result );
  102. reply->addMethodArgument(resultType);
  103. }