ソースを参照

ENH: refactored App/Host Servers and added MessageProcessors.

Yves 14 年 前
コミット
b27e060b30

+ 1 - 0
Plugins/org.commontk.dicom.wg23.app/CMakeLists.txt

@@ -13,6 +13,7 @@ SET(PLUGIN_SRCS
   ctkDicomWG23AppPlugin.cpp
   ctkDicomAbstractApp.cpp
   ctkDicomHostService.cpp
+  ctkAppSoapMessageProcessor.cpp
 )
 
 # Files which should be processed by Qts moc

+ 101 - 0
Plugins/org.commontk.dicom.wg23.app/ctkAppSoapMessageProcessor.cpp

@@ -0,0 +1,101 @@
+/*=============================================================================
+
+  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 "ctkAppSoapMessageProcessor.h"
+
+#include <ctkDicomWG23TypesHelper.h>
+#include "ctkPluginContext.h"
+#include "ctkDicomWG23AppPlugin_p.h"
+
+ctkAppSoapMessageProcessor::ctkAppSoapMessageProcessor(ctkDicomAppInterface* inter)
+: appInterface(inter)
+{}
+
+bool ctkAppSoapMessageProcessor::process(
+	const QtSoapMessage& message,
+	QtSoapMessage* reply ) const
+{
+  // TODO check for NULL appInterface?
+  
+  const QtSoapType& method = message.method();
+  QString methodName = method.name().name();
+
+  qDebug() << "AppMessageProcessor: Received soap method request: " << methodName;
+
+  bool foundMethod = false;
+  
+  if (methodName == "getState")
+  {
+    processGetState(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "setState")
+  {
+    processSetState(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "bringToFront")
+  {
+    processBringToFront(message, reply);
+    foundMethod = true;
+  }
+  
+  return foundMethod;
+}
+		
+void ctkAppSoapMessageProcessor::processGetState(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message: nothing to be done
+  // query interface
+  const ctkDicomWG23::State result = appInterface->getState();
+  // set reply message
+  reply->setMethod("getState");
+  QtSoapSimpleType* resultType = new ctkDicomSoapState("state",result);
+  reply->addMethodArgument(resultType);
+}
+
+void ctkAppSoapMessageProcessor::processSetState(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["state"];
+  // query interface
+  bool result = appInterface->setState(ctkDicomSoapState::getState(inputType));
+  // set reply message
+  reply->setMethod("setState");
+  QtSoapType* resultType = new ctkDicomSoapBool("stateLegal",result);
+  reply->addMethodArgument(resultType);
+}
+
+void ctkAppSoapMessageProcessor::processBringToFront(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["requestedScreenArea"];
+  const QRect requestedScreenArea = ctkDicomSoapRectangle::getQRect(inputType);
+  // query interface
+  bool result = appInterface->bringToFront(requestedScreenArea);
+  // set reply message
+  reply->setMethod("bringToFront");
+  QtSoapType* resultType = new ctkDicomSoapBool("received",result);
+  reply->addMethodArgument(resultType);
+}

+ 52 - 0
Plugins/org.commontk.dicom.wg23.app/ctkAppSoapMessageProcessor.h

@@ -0,0 +1,52 @@
+/*=============================================================================
+
+  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.
+
+=============================================================================*/
+
+#ifndef CTKAPPSOAPMESSAGEPROCESSOR_H
+#define CTKAPPSOAPMESSAGEPROCESSOR_H
+
+#include "ctkSoapMessageProcessor.h"
+#include "ctkDicomAppInterface.h"
+
+class ctkAppSoapMessageProcessor : public ctkSoapMessageProcessor
+{
+
+public:
+
+  ctkAppSoapMessageProcessor( ctkDicomAppInterface* inter );
+
+  bool process(
+    const QtSoapMessage& message,
+    QtSoapMessage* reply) const;
+    
+private:
+
+  void processGetState(const QtSoapMessage& message,
+                       QtSoapMessage* reply) const;
+  void processSetState(const QtSoapMessage& message,
+                       QtSoapMessage* reply) const;
+  void processBringToFront(const QtSoapMessage& message,
+                           QtSoapMessage* reply) const;
+               
+  ctkDicomAppInterface* appInterface;
+
+};
+
+#endif // CTKSOAPMESSAGEPROCESSORLIST_H

+ 13 - 52
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.cpp

@@ -31,8 +31,11 @@
 #include <ctkDicomWG23TypesHelper.h>
 #include <ctkDicomWG23AppPlugin_p.h>
 
+#include <ctkExchangeSoapMessageProcessor.h>
+#include "ctkAppSoapMessageProcessor.h"
+
 ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
-    appInterface(0), port(port)
+      appInterface(0), port(port)
 {
   connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
           this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
@@ -43,14 +46,10 @@ ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
   }
 }
 
-void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
-                                              QtSoapMessage* reply)
+void ctkDicomAppServerPrivate::incomingSoapMessage(
+  const QtSoapMessage& message,
+  QtSoapMessage* reply)
 {
-  const QtSoapType& method = message.method();
-  QString methodName = method.name().name();
-
-  qDebug() << "AppServer: Received soap method request: " << methodName;
-
   if(appInterface == NULL)
   {
     ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
@@ -61,51 +60,13 @@ void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
       throw std::runtime_error("No Dicom App Service found");
     }
     appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
+    
+    ctkAppSoapMessageProcessor appProcessor( appInterface );
+    processors.push_back(appProcessor);
+    //ctkExchangeSoapMessageProcessor exchangeProcessor( appInterface );
+    //processors.push_back(exchangeProcessor);
   }
-
-  if (methodName == "getState")
-  {
-    processGetState(message, reply);
-  }
-  if (methodName == "setState")
-  {
-    processSetState(message, reply);
-  }
-  if (methodName == "bringToFront")
-  {
-    processBringToFront(message, reply);
-  }
-}
-
-void ctkDicomAppServerPrivate::processGetState(
-    const QtSoapMessage &message, QtSoapMessage *reply)
-{
-    const ctkDicomWG23::State result = appInterface->getState();
-
-    reply->setMethod("GetState");
-    QtSoapSimpleType* stateType = new ctkDicomSoapState("state",result);
-    reply->addMethodArgument(stateType);
-}
-
-void ctkDicomAppServerPrivate::processSetState(
-    const QtSoapMessage &message, QtSoapMessage *reply)
-{
-    const QtSoapType& stateType = message.method()["state"];
-    bool result = appInterface->setState(ctkDicomSoapState::getState(stateType));
   
-    reply->setMethod("SetState");
-    QtSoapType* stateLegal = new ctkDicomSoapBool("stateLegal",result);
-    reply->addMethodArgument(stateLegal);
+  processors.process(message, reply);
 }
 
-void ctkDicomAppServerPrivate::processBringToFront(
-    const QtSoapMessage &message, QtSoapMessage *reply)
-{
-   const QtSoapType& requestedScreenAreaType = message.method()["requestedScreenArea"];
-   const QRect requestedScreenArea = ctkDicomSoapRectangle::getQRect(requestedScreenAreaType);
-
-   reply->setMethod("bringToFront");
-   bool result = appInterface->bringToFront(requestedScreenArea);
-   QtSoapType* received = new ctkDicomSoapBool("received",result);
-   reply->addMethodArgument(received);
-}

+ 3 - 7
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.h

@@ -27,6 +27,7 @@
 #include <QtSoapMessage>
 
 #include <ctkSimpleSoapServer.h>
+#include <ctkSoapMessageProcessorList.h>
 
 class ctkDicomAppInterface;
 
@@ -38,7 +39,6 @@ public:
   ctkDicomAppServerPrivate(int port);
 
   ctkSimpleSoapServer server;
-  ctkDicomAppInterface* appInterface;
   int port;
 
 public slots:
@@ -48,12 +48,8 @@ public slots:
 
 private:
 
-  void processGetState(const QtSoapMessage& message,
-                       QtSoapMessage* reply);
-  void processSetState(const QtSoapMessage& message,
-                       QtSoapMessage* reply);
-  void processBringToFront(const QtSoapMessage& message,
-                           QtSoapMessage* reply);
+  ctkSoapMessageProcessorList processors;
+  ctkDicomAppInterface* appInterface;
 
 };
 

+ 3 - 1
Plugins/org.commontk.dicom.wg23.core/CMakeLists.txt

@@ -23,7 +23,9 @@ SET(PLUGIN_SRCS
   ctkDicomWG23Types.h
   ctkDicomWG23TypesHelper.h
   ctkDicomExchangeService.cpp
-  )
+  ctkSoapMessageProcessorList.cpp
+  ctkExchangeSoapMessageProcessor.cpp
+)
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS

+ 108 - 0
Plugins/org.commontk.dicom.wg23.core/ctkExchangeSoapMessageProcessor.cpp

@@ -0,0 +1,108 @@
+/*=============================================================================
+
+  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 "ctkExchangeSoapMessageProcessor.h"
+
+#include <ctkDicomWG23TypesHelper.h>
+
+ctkExchangeSoapMessageProcessor::ctkExchangeSoapMessageProcessor(ctkDicomExchangeInterface* inter)
+: exchangeInterface(inter)
+{}
+
+bool ctkExchangeSoapMessageProcessor::process(
+	const QtSoapMessage& message,
+	QtSoapMessage* reply ) const
+{
+  // TODO check for NULL exchangeInterface?
+  
+  const QtSoapType& method = message.method();
+  QString methodName = method.name().name();
+
+  qDebug() << "ExchangeMessageProcessor: Received soap method request: " << methodName;
+
+  bool foundMethod = false;
+  
+  if (methodName == "notifyDataAvailable")
+  {
+    processNotifyDataAvailable(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "getData")
+  {
+    processGetData(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "releaseData")
+  {
+    processReleaseData(message, reply);
+    foundMethod = true;
+  }
+  
+  return foundMethod;
+}
+		
+void ctkExchangeSoapMessageProcessor::processNotifyDataAvailable(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["data"];
+  const ctkDicomWG23::AvailableData data = ctkDicomSoapAvailableData::getAvailableData(inputType);
+  const QtSoapType& inputType2 = message.method()["lastData"];
+  const bool lastData = ctkDicomSoapBool::getBool(inputType2);
+  // query interface
+  bool result = exchangeInterface->notifyDataAvailable(data, lastData);
+  // set reply message
+  reply->setMethod("notifyDataAvailable");
+  QtSoapType* resultType = new ctkDicomSoapBool("stateLegal",result);
+  reply->addMethodArgument(resultType);
+}
+
+void ctkExchangeSoapMessageProcessor::processGetData(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["objectUUIDs"];
+  const QList<QUuid>* objectUUIDs = ctkDicomSoapArrayOfUUIDS::getArray(
+    dynamic_cast<const QtSoapArray&>(inputType));
+  const QtSoapType& inputType2 = message.method()["acceptableTransferSyntaxUIDs"];
+  const QStringList* acceptableTransferSyntaxUIDs = ctkDicomSoapArrayOfStringType::getArray(
+    dynamic_cast<const QtSoapArray&>(inputType2));
+  const QtSoapType& inputType3 = message.method()["includeBulkData"];
+  const bool includeBulkData = ctkDicomSoapBool::getBool(inputType3);
+  // query interface
+  const QList<ctkDicomWG23::ObjectLocator> result = exchangeInterface->getData(
+    *objectUUIDs, *acceptableTransferSyntaxUIDs, includeBulkData);
+  // set reply message
+  reply->setMethod("getData");
+  QtSoapType* resultType;
+  reply->addMethodArgument(resultType);
+}
+
+void ctkExchangeSoapMessageProcessor::processReleaseData(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["objectUUIDs"];
+  const QList<QUuid> objectUUIDs;
+  // query interface
+  exchangeInterface->releaseData(objectUUIDs);
+  // set reply message: nothing to be done
+}

+ 52 - 0
Plugins/org.commontk.dicom.wg23.core/ctkExchangeSoapMessageProcessor.h

@@ -0,0 +1,52 @@
+/*=============================================================================
+
+  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.
+
+=============================================================================*/
+
+#ifndef CTKEXCHANGESOAPMESSAGEPROCESSOR_H
+#define CTKEXCHANGESOAPMESSAGEPROCESSOR_H
+
+#include "ctkSoapMessageProcessor.h"
+#include "ctkDicomExchangeInterface.h"
+
+class ctkExchangeSoapMessageProcessor : public ctkSoapMessageProcessor
+{
+
+public:
+
+  ctkExchangeSoapMessageProcessor( ctkDicomExchangeInterface* inter );
+
+  bool process(
+    const QtSoapMessage& message,
+    QtSoapMessage* reply) const;
+    
+private:
+
+  void processNotifyDataAvailable(const QtSoapMessage& message,
+                       QtSoapMessage* reply) const;
+  void processGetData(const QtSoapMessage& message,
+                       QtSoapMessage* reply) const;
+  void processReleaseData(const QtSoapMessage& message,
+                           QtSoapMessage* reply) const;
+               
+  ctkDicomExchangeInterface* exchangeInterface;
+
+};
+
+#endif // CTKEXCHANGESOAPMESSAGEPROCESSOR_H

+ 59 - 0
Plugins/org.commontk.dicom.wg23.core/ctkSoapMessageProcessor.h

@@ -0,0 +1,59 @@
+/*=============================================================================
+
+  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.
+
+=============================================================================*/
+
+#ifndef CTKSOAPMESSAGEPROCESSOR_H
+#define CTKSOAPMESSAGEPROCESSOR_H
+
+#include <qtsoap.h>
+
+#include <org_commontk_dicom_wg23_core_Export.h>
+
+class org_commontk_dicom_wg23_core_EXPORT ctkSoapMessageProcessor
+{
+
+public:
+
+	/**
+	* Process a Soap Message and set the input reply.
+	* @input message The message to process.
+	* @input reply The reply to the input message.
+	* @return True if the message could be processed.
+	*/
+	virtual bool process( 
+		const QtSoapMessage& message,
+    QtSoapMessage* reply) const
+  {
+    // to implement
+    return false;
+  }
+		
+	bool operator==( const ctkSoapMessageProcessor& rhs )
+	{
+		if( this == &rhs )
+		{
+			return true;
+		}
+		return false;
+	}
+
+};
+
+#endif // CTKSOAPMESSAGEPROCESSOR_H

+ 51 - 0
Plugins/org.commontk.dicom.wg23.core/ctkSoapMessageProcessorList.cpp

@@ -0,0 +1,51 @@
+/*=============================================================================
+
+  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 "ctkSoapMessageProcessorList.h"
+
+void ctkSoapMessageProcessorList::push_back( const ctkSoapMessageProcessor& processor )
+{
+	processors.push_back( processor );
+}
+
+void ctkSoapMessageProcessorList::remove( const ctkSoapMessageProcessor& processor )
+{
+	processors.remove( processor );
+}
+
+bool ctkSoapMessageProcessorList::process(
+	const QtSoapMessage& message,
+	QtSoapMessage* reply ) const
+{
+  for( std::list<ctkSoapMessageProcessor>::const_iterator it = processors.begin(); 
+    it != processors.end(); it++)
+	{
+		if( it->process( message, reply ) )
+		{
+			return true;
+		}
+	}
+	// if still here, no processor could process the message
+	reply->setFaultCode( QtSoapMessage::Server );
+    reply->setFaultString( "No processor found to process message." );
+	return false;
+}
+		

+ 49 - 0
Plugins/org.commontk.dicom.wg23.core/ctkSoapMessageProcessorList.h

@@ -0,0 +1,49 @@
+/*=============================================================================
+
+  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.
+
+=============================================================================*/
+
+#ifndef CTKSOAPMESSAGEPROCESSORLIST_H
+#define CTKSOAPMESSAGEPROCESSORLIST_H
+
+#include <list>
+#include "ctkSoapMessageProcessor.h"
+
+#include <org_commontk_dicom_wg23_core_Export.h>
+
+class org_commontk_dicom_wg23_core_EXPORT ctkSoapMessageProcessorList : public ctkSoapMessageProcessor
+{
+
+public:
+
+	void push_back( const ctkSoapMessageProcessor& processor );
+
+	void remove( const ctkSoapMessageProcessor& processor );
+	
+	bool process(
+		const QtSoapMessage& message,
+		QtSoapMessage* reply) const;
+		
+private:
+
+	std::list<ctkSoapMessageProcessor> processors;
+
+};
+
+#endif // CTKSOAPMESSAGEPROCESSORLIST_H

+ 1 - 0
Plugins/org.commontk.dicom.wg23.host/CMakeLists.txt

@@ -8,6 +8,7 @@ SET(PLUGIN_SRCS
   ctkDicomWG23HostPlugin.cpp
   ctkDicomAbstractHost.cpp
   ctkDicomAppService.cpp
+  ctkHostSoapMessageProcessor.cpp
 )
 
 # Files which should be processed by Qts moc

+ 10 - 81
Plugins/org.commontk.dicom.wg23.host/ctkDicomHostServerPrivate.cpp

@@ -28,6 +28,10 @@
 #include <stdexcept>
 #include <ctkDicomWG23TypesHelper.h>
 
+#include <ctkExchangeSoapMessageProcessor.h>
+#include "ctkHostSoapMessageProcessor.h"
+
+
 ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port) :
     hostInterface(hostInterface), port(port)
 {
@@ -38,91 +42,16 @@ ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* host
   {
     qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
   }
+
+  ctkHostSoapMessageProcessor hostProcessor( hostInterface );
+  processors.push_back(hostProcessor);
+  //ctkExchangeSoapMessageProcessor exchangeProcessor( hostInterface );
+  //processors.push_back(exchangeProcessor);
 }
 
 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);
+  processors.process(message, reply);
 }
 
-void ctkDicomHostServerPrivate::processGetOutputLocation(
-  const QtSoapMessage& message, QtSoapMessage* reply) const
-{
-  const QtSoapType& inputType = message.method()["preferredProtocols"];
-  const QStringList* preferredProtocols = ctkDicomSoapArrayOfStringType::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);
-}

+ 3 - 12
Plugins/org.commontk.dicom.wg23.host/ctkDicomHostServerPrivate.h

@@ -19,7 +19,6 @@
 
 =============================================================================*/
 
-
 #ifndef CTKDICOMHOSTSERVERPRIVATE_H
 #define CTKDICOMHOSTSERVERPRIVATE_H
 
@@ -27,6 +26,7 @@
 #include <QtSoapMessage>
 
 #include <ctkSimpleSoapServer.h>
+#include <ctkSoapMessageProcessorList.h>
 
 class ctkDicomHostInterface;
 
@@ -38,7 +38,6 @@ public:
   ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port);
 
   ctkSimpleSoapServer server;
-  ctkDicomHostInterface* hostInterface;
   int port;
 
 public slots:
@@ -48,16 +47,8 @@ public slots:
 
 private:
 
-  void processGetAvailableScreen(const QtSoapMessage& message,
-                                 QtSoapMessage* reply) const;
-  void processNotifyStateChanged(const QtSoapMessage& message,
-                                 QtSoapMessage* reply) const;
-  void processNotifyStatus(const QtSoapMessage& message,
-                                 QtSoapMessage* reply) const;
-  void processGenerateUID(const QtSoapMessage& message,
-                                 QtSoapMessage* reply) const;
-  void processGetOutputLocation(const QtSoapMessage& message,
-                                 QtSoapMessage* reply) const;
+  ctkSoapMessageProcessorList processors;
+  ctkDicomHostInterface* hostInterface;
 
 };
 

+ 133 - 0
Plugins/org.commontk.dicom.wg23.host/ctkHostSoapMessageProcessor.cpp

@@ -0,0 +1,133 @@
+/*=============================================================================
+
+  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 "ctkHostSoapMessageProcessor.h"
+
+#include <ctkDicomWG23TypesHelper.h>
+#include "ctkPluginContext.h"
+#include "ctkDicomWG23HostPlugin_p.h"
+
+ctkHostSoapMessageProcessor::ctkHostSoapMessageProcessor( ctkDicomHostInterface* inter )
+: hostInterface(inter)
+{}
+
+bool ctkHostSoapMessageProcessor::process(
+	const QtSoapMessage& message,
+	QtSoapMessage* reply ) const
+{
+  // TODO check for NULL hostInterface?
+  
+  const QtSoapType& method = message.method();
+  QString methodName = method.name().name();
+
+  qDebug() << "HostMessageProcessor: Received soap method request: " << methodName;
+
+  bool foundMethod = false;
+  
+  if (methodName == "getAvailableScreen")
+  {
+    processGetAvailableScreen(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "notifyStateChanged")
+  {
+    processNotifyStateChanged(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "notifyStatus")
+  {
+    processNotifyStatus(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "generateUID")
+  {
+    processGenerateUID(message, reply);
+    foundMethod = true;
+  }
+  else if (methodName == "getOutputLocation")
+  {
+    processGetOutputLocation(message, reply);
+    foundMethod = true;
+  }
+  
+  return foundMethod;
+}
+		
+void ctkHostSoapMessageProcessor::processGetAvailableScreen(
+    const QtSoapMessage &message, QtSoapMessage *reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["preferredScreen"];
+  const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(inputType);
+  // query interface
+  const QRect result = hostInterface->getAvailableScreen(preferredScreen);
+  // set reply message
+  reply->setMethod("getAvailableScreenResponse");
+  QtSoapStruct* returnType = new ctkDicomSoapRectangle("availableScreen",result);
+  reply->addMethodArgument(returnType);
+}
+
+void ctkHostSoapMessageProcessor::processNotifyStateChanged(
+    const QtSoapMessage &message, QtSoapMessage * /* reply */) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["state"];
+  // query interface
+  hostInterface->notifyStateChanged(ctkDicomSoapState::getState(inputType));
+  // set reply message: nothing to be done
+}
+
+void ctkHostSoapMessageProcessor::processNotifyStatus(
+    const QtSoapMessage &message, QtSoapMessage * /* reply */) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["status"];
+  // query interface
+  hostInterface->notifyStatus(ctkDicomSoapStatus::getStatus(inputType));
+  // set reply message: nothing to be done
+}
+
+void ctkHostSoapMessageProcessor::processGenerateUID(
+  const QtSoapMessage& message, QtSoapMessage* reply) const
+{
+  // extract arguments from input message: nothing to be done
+  // query interface
+  const QString uid = hostInterface->generateUID();
+  // set reply message
+  reply->setMethod("generateUID");
+  QtSoapType* resultType = new ctkDicomSoapUID("uid",uid);
+  reply->addMethodArgument(resultType);
+}
+
+void ctkHostSoapMessageProcessor::processGetOutputLocation(
+  const QtSoapMessage& message, QtSoapMessage* reply) const
+{
+  // extract arguments from input message
+  const QtSoapType& inputType = message.method()["preferredProtocols"];
+  const QStringList* preferredProtocols = ctkDicomSoapArrayOfStringType::getArray(
+    dynamic_cast<const QtSoapArray&>(inputType));
+  // query interface
+  const QString result = hostInterface->getOutputLocation(*preferredProtocols);
+  // set reply message
+  reply->setMethod("getOutputLocation");
+  QtSoapType* resultType = new QtSoapSimpleType( QtSoapQName("preferredProtocols"), result );
+  reply->addMethodArgument(resultType);
+}

+ 56 - 0
Plugins/org.commontk.dicom.wg23.host/ctkHostSoapMessageProcessor.h

@@ -0,0 +1,56 @@
+/*=============================================================================
+
+  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.
+
+=============================================================================*/
+
+#ifndef ctkHostSoapMessageProcessor_H
+#define ctkHostSoapMessageProcessor_H
+
+#include "ctkSoapMessageProcessor.h"
+#include "ctkDicomHostInterface.h"
+
+class ctkHostSoapMessageProcessor : public ctkSoapMessageProcessor
+{
+
+public:
+
+  ctkHostSoapMessageProcessor( ctkDicomHostInterface* inter );
+
+  bool process(
+    const QtSoapMessage& message,
+    QtSoapMessage* reply) const;
+    
+private:
+
+  void processGetAvailableScreen(const QtSoapMessage& message,
+                                 QtSoapMessage* reply) const;
+  void processNotifyStateChanged(const QtSoapMessage& message,
+                                 QtSoapMessage* reply) const;
+  void processNotifyStatus(const QtSoapMessage& message,
+                                 QtSoapMessage* reply) const;
+  void processGenerateUID(const QtSoapMessage& message,
+                                 QtSoapMessage* reply) const;
+  void processGetOutputLocation(const QtSoapMessage& message,
+                                 QtSoapMessage* reply) const;
+               
+  ctkDicomHostInterface* hostInterface;
+
+};
+
+#endif // CTKSOAPMESSAGEPROCESSORLIST_H