ctkDicomHostServerPrivate.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 "ctkDicomWG23HostPlugin_p.h"
  17. #include <ctkDicomHostInterface.h>
  18. #include <QHostAddress>
  19. #include <stdexcept>
  20. ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(QObject *parent) :
  21. QObject(parent)
  22. {
  23. ctkPluginContext* context = ctkDicomWG23HostPlugin::getInstance()->getPluginContext();
  24. ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomHostInterface");
  25. if (!serviceRef)
  26. {
  27. // this will change after mergin changes from branch plugin_framework
  28. throw std::runtime_error("No Dicom Host Service found");
  29. }
  30. serviceBinding = qobject_cast<ctkDicomHostInterface*>(context->getService(serviceRef));
  31. connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
  32. this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
  33. if (!server.listen(QHostAddress::LocalHost, 8080))
  34. {
  35. qCritical() << "Listening to 127.0.0.1:8080 failed.";
  36. }
  37. }
  38. void ctkDicomHostServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
  39. QtSoapMessage* reply)
  40. {
  41. const QtSoapType& method = message.method();
  42. QString methodName = method.name().name();
  43. qDebug() << "Received soap method request: " << methodName;
  44. if (methodName == "GetAvailableScreen")
  45. {
  46. processGetAvailableScreen(message, reply);
  47. }
  48. }
  49. void ctkDicomHostServerPrivate::processGetAvailableScreen(
  50. const QtSoapMessage &message, QtSoapMessage *reply)
  51. {
  52. const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
  53. QRect preferredScreen(preferredScreenType["RefPointX"].value().toInt(),
  54. preferredScreenType["RefPointY"].value().toInt(),
  55. preferredScreenType["Width"].value().toInt(),
  56. preferredScreenType["Height"].value().toInt());
  57. QRect result = serviceBinding->getAvailableScreen(preferredScreen);
  58. reply->setMethod("GetAvailableScreenResponse");
  59. QtSoapStruct* availableScreenType = new QtSoapStruct(QtSoapQName("availableScreen"));
  60. availableScreenType->insert(new QtSoapSimpleType(QtSoapQName("Height"), result.height()));
  61. availableScreenType->insert(new QtSoapSimpleType(QtSoapQName("Width"), result.width()));
  62. availableScreenType->insert(new QtSoapSimpleType(QtSoapQName("RefPointX"), result.x()));
  63. availableScreenType->insert(new QtSoapSimpleType(QtSoapQName("RefPointY"), result.y()));
  64. reply->addMethodArgument(availableScreenType);
  65. }