ctkDicomAppServerPrivate.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "ctkDicomAppServerPrivate.h"
  16. #include <ctkDicomAppInterface.h>
  17. #include <ctkServiceReference.h>
  18. #include <QHostAddress>
  19. #include <stdexcept>
  20. #include <ctkDicomWG23TypesHelper.h>
  21. #include <ctkDicomWG23AppPlugin_p.h>
  22. ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
  23. appInterface(0), port(port)
  24. {
  25. connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
  26. this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
  27. if (!server.listen(QHostAddress::LocalHost, this->port))
  28. {
  29. qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
  30. }
  31. ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
  32. ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomAppInterface");
  33. if (!serviceRef)
  34. {
  35. // this will change after merging changes from branch plugin_framework
  36. throw std::runtime_error("No Dicom App Service found");
  37. }
  38. appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
  39. }
  40. void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
  41. QtSoapMessage* reply)
  42. {
  43. const QtSoapType& method = message.method();
  44. QString methodName = method.name().name();
  45. qDebug() << "Received soap method request: " << methodName;
  46. if (methodName == "getState")
  47. {
  48. processGetState(message, reply);
  49. }
  50. if (methodName == "setState")
  51. {
  52. processSetState(message, reply);
  53. }
  54. if (methodName == "bringToFront")
  55. {
  56. processBringToFront(message, reply);
  57. }
  58. }
  59. void ctkDicomAppServerPrivate::processGetState(
  60. const QtSoapMessage &message, QtSoapMessage *reply)
  61. {
  62. const ctkDicomWG23::State result = appInterface->getState();
  63. reply->setMethod("GetState");
  64. QtSoapSimpleType* stateType = new ctkDicomSoapState("state",result);
  65. reply->addMethodArgument(stateType);
  66. }
  67. void ctkDicomAppServerPrivate::processSetState(
  68. const QtSoapMessage &message, QtSoapMessage *reply)
  69. {
  70. const QtSoapType& stateType = message.method()["state"];
  71. appInterface->setState(ctkDicomSoapState::getState(stateType));
  72. }
  73. void ctkDicomAppServerPrivate::processBringToFront(
  74. const QtSoapMessage &message, QtSoapMessage *reply)
  75. {
  76. const QtSoapType& requestedScreenAreaType = message.method()["requestedScreenArea"];
  77. const QRect requestedScreenArea = ctkDicomSoapRectangle::getQRect(requestedScreenAreaType);
  78. appInterface->bringToFront(requestedScreenArea);
  79. }