Browse Source

ENH: dah Added app server classes

ivmartel 14 years ago
parent
commit
c974005bed

+ 3 - 4
Plugins/org.commontk.dicom.wg23.app/CMakeLists.txt

@@ -8,16 +8,15 @@ ENDIF()
 SET(PLUGIN_export_directive "org_commontk_dicom_wg23_app_EXPORT")
 
 SET(PLUGIN_SRCS
-  ctkDicomHostServicePrivate.cpp
-  ctkDicomWG23AppPlugin.cpp
   ctkDicomAppServer.cpp
+  ctkDicomAppServerPrivate.cpp
+  ctkDicomWG23AppPlugin.cpp
 )
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS
-  ctkDicomHostServicePrivate.h
+  ctkDicomAppServerPrivate.h
   ctkDicomWG23AppPlugin_p.h
-  ctkDicomAppServer.h
 )
 
 # Qt Designer files which should be processed by Qts uic

+ 3 - 5
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServer.cpp

@@ -22,12 +22,10 @@
 
 #include "ctkDicomAppServer.h"
 
+#include "ctkDicomAppServerPrivate.h"
+
 ctkDicomAppServer::ctkDicomAppServer()
+  : d_ptr(new ctkDicomAppServerPrivate)
 {
 
 }
-
-ctkDicomAppServer::~ctkDicomAppServer()
-{
-  
-}

+ 11 - 7
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServer.h

@@ -19,20 +19,24 @@
 
 =============================================================================*/
 
-#include <QObject>
-
 #ifndef CTKDICOMAPPPSERVER_H
 #define CTKDICOMAPPPSERVER_H
 
-class ctkDicomAppServer : public QObject
+#include <QScopedPointer>
+
+class ctkDicomAppServerPrivate;
+
+class ctkDicomAppServer
 {
-  Q_OBJECT
 
 public:
-
   ctkDicomAppServer();
-  ~ctkDicomAppServer();
 
-}; // ctkDicomAppServer
+private:
+
+  Q_DECLARE_PRIVATE(ctkDicomAppServer)
+
+  const QScopedPointer<ctkDicomAppServerPrivate> d_ptr;
+};
 
 #endif // CTKDICOMAPPPSERVER_H

+ 101 - 0
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.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 "ctkDicomAppServerPrivate.h"
+
+#include "ctkDicomWG23AppPlugin_p.h"
+#include <ctkDicomAppInterface.h>
+
+#include <QHostAddress>
+
+#include <stdexcept>
+#include <ctkDicomWG23TypesHelper.h>
+
+ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(QObject *parent) :
+    QObject(parent)
+{
+  ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
+  ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomAppInterface");
+  if (!serviceRef)
+  {
+    // this will change after mergin changes from branch plugin_framework
+    throw std::runtime_error("No Dicom App Service found");
+  }
+
+  serviceBinding = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
+
+  connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
+          this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
+
+  if (!server.listen(QHostAddress::LocalHost, 8080))
+  {
+    qCritical() << "Listening to 127.0.0.1:8080 failed.";
+  }
+}
+
+void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
+                                              QtSoapMessage* reply)
+{
+  const QtSoapType& method = message.method();
+  QString methodName = method.name().name();
+
+  qDebug() << "Received soap method request: " << methodName;
+
+  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 = serviceBinding->getState();
+
+    reply->setMethod("GetState");
+    QtSoapStruct* stateType = new ctkDicomSoapState("state",result);
+    reply->addMethodArgument(stateType);
+}
+
+void ctkDicomAppServerPrivate::processSetState(
+    const QtSoapMessage &message, QtSoapMessage *reply)
+{
+    const QtSoapType& stateType = message.method()["state"];
+    serviceBinding->setState(ctkDicomSoapState::getState(stateType));
+}
+
+void ctkDicomAppServerPrivate::processBringToFront(
+    const QtSoapMessage &message, QtSoapMessage *reply)
+{
+   const QtSoapType& requestedScreenAreaType = message.method()["requestedScreenArea"];
+   const QRect requestedScreenArea = ctkDicomSoapRectangle::getQRect(requestedScreenAreaType);
+
+   serviceBinding->bringToFront(requestedScreenArea);
+}

+ 58 - 0
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.h

@@ -0,0 +1,58 @@
+/*=============================================================================
+
+  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 DICOMAPPINTERFACEIMPL_P_H
+#define DICOMAPPINTERFACEIMPL_P_H
+
+#include <ctkDicomAppInterface.h>
+
+#include <QEventLoop>
+#include <QtSoapHttpTransport>
+
+class ctkDicomAppServerPrivate : public ctkDicomAppInterface
+{
+  Q_OBJECT
+
+public:
+  ctkDicomAppServerPrivate(QObject *parent = 0);
+
+  ctkSimpleSoapServer server;
+
+public slots:
+
+  void incomingSoapMessage(const QtSoapMessage& message,
+                           QtSoapMessage* reply);
+
+private:
+
+  void processGetState(const QtSoapMessage& message,
+                       QtSoapMessage* reply);
+  void processSetState(const QtSoapMessage& message,
+                       QtSoapMessage* reply);
+  void processBringToFront(const QtSoapMessage& message,
+                           QtSoapMessage* reply);
+
+  ctkDicomAppInterface* serviceBinding;
+
+};
+
+#endif // DICOMAPPINTERFACEIMPL_P_H

+ 4 - 4
Plugins/org.commontk.dicom.wg23.app/ctkDicomWG23AppPlugin.cpp

@@ -22,7 +22,7 @@
 
 #include "ctkDicomWG23AppPlugin_p.h"
 
-#include <ctkDicomHostServicePrivate.h>
+#include <ctkDicomAppServerPrivate.h>
 
 #include <QtPlugin>
 
@@ -44,15 +44,15 @@ void ctkDicomWG23AppPlugin::start(ctkPluginContext* context)
   instance = this;
   this->context = context;
 
-  hostInterface = new ctkDicomHostService();
-  context->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
+  appInterface = new ctkDicomAppService();
+  context->registerService(QStringList("ctkDicomAppInterface"), appInterface);
 }
 
 void ctkDicomWG23AppPlugin::stop(ctkPluginContext* context)
 {
   Q_UNUSED(context)
 
-  delete hostInterface;
+  delete appInterface;
 }
 
 ctkDicomWG23AppPlugin* ctkDicomWG23AppPlugin::getInstance()

+ 2 - 2
Plugins/org.commontk.dicom.wg23.app/ctkDicomWG23AppPlugin_p.h

@@ -25,7 +25,7 @@
 
 #include <ctkPluginActivator.h>
 
-class ctkDicomHostInterface;
+class ctkDicomAppInterface;
 
 class ctkDicomWG23AppPlugin :
   public QObject, public ctkPluginActivator
@@ -51,7 +51,7 @@ private:
   static ctkDicomWG23AppPlugin* instance;
   ctkPluginContext* context;
 
-  ctkDicomHostInterface* hostInterface;
+  ctkDicomAppInterface* appInterface;
 
 }; // ctkDicomWG23AppPlugin