ctkDicomHostServerPrivate.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <ctkDicomWG23TypesHelper.h>
  21. ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(QObject *parent) :
  22. QObject(parent)
  23. {
  24. ctkPluginContext* context = ctkDicomWG23HostPlugin::getInstance()->getPluginContext();
  25. ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomHostInterface");
  26. if (!serviceRef)
  27. {
  28. // this will change after mergin changes from branch plugin_framework
  29. throw std::runtime_error("No Dicom Host Service found");
  30. }
  31. serviceBinding = qobject_cast<ctkDicomHostInterface*>(context->getService(serviceRef));
  32. connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
  33. this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
  34. if (!server.listen(QHostAddress::LocalHost, 8080))
  35. {
  36. qCritical() << "Listening to 127.0.0.1:8080 failed.";
  37. }
  38. }
  39. void ctkDicomHostServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
  40. QtSoapMessage* reply)
  41. {
  42. const QtSoapType& method = message.method();
  43. QString methodName = method.name().name();
  44. qDebug() << "Received soap method request: " << methodName;
  45. if (methodName == "GetAvailableScreen")
  46. {
  47. processGetAvailableScreen(message, reply);
  48. }
  49. if (methodName == "notifyStateChanged")
  50. {
  51. processNotifyStateChanged(message, reply);
  52. }
  53. if (methodName == "notifyStatus")
  54. {
  55. processNotifyStatus(message, reply);
  56. }
  57. }
  58. void ctkDicomHostServerPrivate::processGetAvailableScreen(
  59. const QtSoapMessage &message, QtSoapMessage *reply)
  60. {
  61. const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
  62. const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(preferredScreenType);
  63. const QRect result = serviceBinding->getAvailableScreen(preferredScreen);
  64. reply->setMethod("GetAvailableScreenResponse");
  65. QtSoapStruct* availableScreenType = new ctkDicomSoapRectangle("availableScreen",result);
  66. reply->addMethodArgument(availableScreenType);
  67. }
  68. void ctkDicomHostServerPrivate::processNotifyStateChanged(
  69. const QtSoapMessage &message, QtSoapMessage *reply)
  70. {
  71. const QtSoapType& stateType = message.method()["state"];
  72. serviceBinding->notifyStateChanged(ctkDicomSoapState::getState(stateType));
  73. }
  74. void ctkDicomHostServerPrivate::processNotifyStatus(
  75. const QtSoapMessage &message, QtSoapMessage *reply)
  76. {
  77. const QtSoapType& status = message.method()["status"];
  78. serviceBinding->notifyStatus(ctkDicomSoapStatus::getStatus(status));
  79. }