123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /*=============================================================================
- Library: CTK
- Copyright (c) 2010 German Cancer Research Center,
- Division of Medical and Biological Informatics
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- =============================================================================*/
- #include "ctkDicomHostServerPrivate.h"
- #include <ctkDicomHostInterface.h>
- #include <QHostAddress>
- #include <stdexcept>
- #include <ctkDicomWG23TypesHelper.h>
- ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port) :
- hostInterface(hostInterface), port(port)
- {
- connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
- this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
- if (!server.listen(QHostAddress::LocalHost, this->port))
- {
- qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
- }
- }
- void ctkDicomHostServerPrivate::incomingSoapMessage(
- const QtSoapMessage& message, QtSoapMessage* reply)
- {
- const QtSoapType& method = message.method();
- QString methodName = method.name().name();
- qDebug() << "HostServer: Received soap method request: " << methodName;
- if (methodName == "getAvailableScreen")
- {
- processGetAvailableScreen(message, reply);
- }
- else if (methodName == "notifyStateChanged")
- {
- processNotifyStateChanged(message, reply);
- }
- else if (methodName == "notifyStatus")
- {
- processNotifyStatus(message, reply);
- }
- else if (methodName == "generateUID")
- {
- processGenerateUID(message, reply);
- }
- else if (methodName == "getOutputLocation")
- {
- processGetOutputLocation(message, reply);
- }
- else
- {
- // error
- reply->setFaultCode( QtSoapMessage::Server );
- reply->setFaultString( "Unknown method." );
- }
- }
- void ctkDicomHostServerPrivate::processGetAvailableScreen(
- const QtSoapMessage &message, QtSoapMessage *reply) const
- {
- const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
- const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(preferredScreenType);
- const QRect result = hostInterface->getAvailableScreen(preferredScreen);
- reply->setMethod("getAvailableScreenResponse");
- QtSoapStruct* availableScreenType = new ctkDicomSoapRectangle("availableScreen",result);
- reply->addMethodArgument(availableScreenType);
- }
- void ctkDicomHostServerPrivate::processNotifyStateChanged(
- const QtSoapMessage &message, QtSoapMessage * /* reply */) const
- {
- const QtSoapType& stateType = message.method()["state"];
- hostInterface->notifyStateChanged(ctkDicomSoapState::getState(stateType));
- }
- void ctkDicomHostServerPrivate::processNotifyStatus(
- const QtSoapMessage &message, QtSoapMessage * /* reply */) const
- {
- const QtSoapType& status = message.method()["status"];
- hostInterface->notifyStatus(ctkDicomSoapStatus::getStatus(status));
- }
- void ctkDicomHostServerPrivate::processGenerateUID(
- const QtSoapMessage& message, QtSoapMessage* reply) const
- {
- const QString uid = hostInterface->generateUID();
- reply->setMethod("generateUID");
- QtSoapType* type = new ctkDicomSoapUID("uid",uid);
- reply->addMethodArgument(type);
- }
- void ctkDicomHostServerPrivate::processGetOutputLocation(
- const QtSoapMessage& message, QtSoapMessage* reply) const
- {
- const QtSoapType& inputType = message.method()["preferredProtocols"];
- const QStringList* preferredProtocols = ctkDicomSoapArrayOfString::getArray(
- dynamic_cast<const QtSoapArray&>(inputType));
- const QString result = hostInterface->getOutputLocation(*preferredProtocols);
- reply->setMethod("getOutputLocation");
- QtSoapType* resultType = new QtSoapSimpleType ( QtSoapQName("preferredProtocols"), result );
- reply->addMethodArgument(resultType);
- }
|