Pārlūkot izejas kodu

ENH: dah Mirrored host classes.

ymartelli 14 gadi atpakaļ
vecāks
revīzija
3a937884c6

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

@@ -11,6 +11,7 @@ SET(PLUGIN_SRCS
   ctkDicomAppServer.cpp
   ctkDicomAppServerPrivate.cpp
   ctkDicomWG23AppPlugin.cpp
+  ctkDicomAbstractApp.cpp
 )
 
 # Files which should be processed by Qts moc

+ 33 - 0
Plugins/org.commontk.dicom.wg23.app/ctkDicomAbstractApp.cpp

@@ -0,0 +1,33 @@
+#include "ctkDicomAbstractApp.h"
+#include "ctkDicomAppServer.h"
+
+class ctkDicomAbstractAppPrivate
+{
+  public:
+  ctkDicomAbstractAppPrivate(ctkDicomAbstractApp* appInterface, int port) : port(port)
+  {
+    // start server
+    if (!port)
+    {
+      port = 8080;
+    }
+    server = new ctkDicomAppServer(appInterface,port);
+  }
+  ~ctkDicomAbstractAppPrivate()
+  {
+    delete server;
+  }
+
+  int port;
+  ctkDicomAppServer* server;
+};
+
+ctkDicomAbstractApp::ctkDicomAbstractApp(int port) : d_ptr(new ctkDicomAbstractAppPrivate(this,port))
+{
+}
+
+int ctkDicomAbstractApp::getPort() const
+{
+  Q_D(const ctkDicomAbstractApp);
+  return d->port;
+}

+ 33 - 0
Plugins/org.commontk.dicom.wg23.app/ctkDicomAbstractApp.h

@@ -0,0 +1,33 @@
+#ifndef CTKDICOMABSTRACTAPP_H
+#define CTKDICOMABSTRACTAPP_H
+
+#include <ctkDicomAppInterface.h>
+#include <QScopedPointer>
+
+class ctkDicomAbstractAppPrivate;
+
+/**
+  * Provide a basic implementation for an application app.
+  *
+  * It starts a http server and serves one hosted application. Multiple instances
+  * can be used for hosting multiple applications.
+  *
+  * The methods of the ctkDicomAppInterface have to be implemented for the business logic,
+  *
+  */
+class ctkDicomAbstractApp : public ctkDicomAppInterface
+{
+public:
+    /**
+      * Start the soap sever on the specified port or choose port automatically.
+      */
+    ctkDicomAbstractApp(int port = 0);
+    int getPort() const;
+
+private:
+    Q_DECLARE_PRIVATE(ctkDicomAbstractApp)
+    const QScopedPointer<ctkDicomAbstractAppPrivate> d_ptr;
+
+};
+
+#endif // CTKDICOMABSTRACTAPP_H

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

@@ -19,13 +19,15 @@
 
 =============================================================================*/
 
-
 #include "ctkDicomAppServer.h"
 
 #include "ctkDicomAppServerPrivate.h"
 
-ctkDicomAppServer::ctkDicomAppServer()
-  : d_ptr(new ctkDicomAppServerPrivate)
+ctkDicomAppServer::ctkDicomAppServer(ctkDicomAppInterface* appInterface, int port)
+  : d_ptr(new ctkDicomAppServerPrivate(appInterface, port))
 {
 
 }
+ctkDicomAppServer::~ctkDicomAppServer()
+{
+}

+ 4 - 1
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServer.h

@@ -22,6 +22,8 @@
 #ifndef CTKDICOMAPPPSERVER_H
 #define CTKDICOMAPPPSERVER_H
 
+class ctkDicomAppInterface;
+
 #include <QScopedPointer>
 
 class ctkDicomAppServerPrivate;
@@ -30,7 +32,8 @@ class ctkDicomAppServer
 {
 
 public:
-  ctkDicomAppServer();
+  ctkDicomAppServer(ctkDicomAppInterface* appInterface, int port);
+  ~ctkDicomAppServer();
 
 private:
 

+ 8 - 18
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.cpp

@@ -22,7 +22,6 @@
 
 #include "ctkDicomAppServerPrivate.h"
 
-#include "ctkDicomWG23AppPlugin_p.h"
 #include <ctkDicomAppInterface.h>
 
 #include <QHostAddress>
@@ -30,25 +29,16 @@
 #include <stdexcept>
 #include <ctkDicomWG23TypesHelper.h>
 
-ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(QObject *parent) :
-    QObject(parent)
+ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(ctkDicomAppInterface* appInterface, int port) :
+    appInterface(appInterface), port(port)
 {
-  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))
+  if (!server.listen(QHostAddress::LocalHost, this->port))
   {
-    qCritical() << "Listening to 127.0.0.1:8080 failed.";
+    qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
   }
 }
 
@@ -77,10 +67,10 @@ void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,
 void ctkDicomAppServerPrivate::processGetState(
     const QtSoapMessage &message, QtSoapMessage *reply)
 {
-    const ctkDicomWG23::State result = serviceBinding->getState();
+    const ctkDicomWG23::State result = appInterface->getState();
 
     reply->setMethod("GetState");
-    QtSoapStruct* stateType = new ctkDicomSoapState("state",result);
+    QtSoapSimpleType* stateType = new ctkDicomSoapState("state",result);
     reply->addMethodArgument(stateType);
 }
 
@@ -88,7 +78,7 @@ void ctkDicomAppServerPrivate::processSetState(
     const QtSoapMessage &message, QtSoapMessage *reply)
 {
     const QtSoapType& stateType = message.method()["state"];
-    serviceBinding->setState(ctkDicomSoapState::getState(stateType));
+    appInterface->setState(ctkDicomSoapState::getState(stateType));
 }
 
 void ctkDicomAppServerPrivate::processBringToFront(
@@ -97,5 +87,5 @@ void ctkDicomAppServerPrivate::processBringToFront(
    const QtSoapType& requestedScreenAreaType = message.method()["requestedScreenArea"];
    const QRect requestedScreenArea = ctkDicomSoapRectangle::getQRect(requestedScreenAreaType);
 
-   serviceBinding->bringToFront(requestedScreenArea);
+   appInterface->bringToFront(requestedScreenArea);
 }

+ 12 - 10
Plugins/org.commontk.dicom.wg23.app/ctkDicomAppServerPrivate.h

@@ -20,22 +20,26 @@
 =============================================================================*/
 
 
-#ifndef DICOMAPPINTERFACEIMPL_P_H
-#define DICOMAPPINTERFACEIMPL_P_H
+#ifndef CTKDICOMAPPSERVERPRIVATE_H
+#define CTKDICOMAPPSERVERPRIVATE_H
 
-#include <ctkDicomAppInterface.h>
+#include <QObject>
+#include <QtSoapMessage>
 
-#include <QEventLoop>
-#include <QtSoapHttpTransport>
+#include <ctkSimpleSoapServer.h>
 
-class ctkDicomAppServerPrivate : public ctkDicomAppInterface
+class ctkDicomAppInterface;
+
+class ctkDicomAppServerPrivate : public QObject
 {
   Q_OBJECT
 
 public:
-  ctkDicomAppServerPrivate(QObject *parent = 0);
+  ctkDicomAppServerPrivate(ctkDicomAppInterface* appInterface, int port);
 
   ctkSimpleSoapServer server;
+  ctkDicomAppInterface* appInterface;
+  int port;
 
 public slots:
 
@@ -51,8 +55,6 @@ private:
   void processBringToFront(const QtSoapMessage& message,
                            QtSoapMessage* reply);
 
-  ctkDicomAppInterface* serviceBinding;
-
 };
 
-#endif // DICOMAPPINTERFACEIMPL_P_H
+#endif // CTKDICOMAPPSERVERPRIVATE_H

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

@@ -22,8 +22,6 @@
 
 #include "ctkDicomWG23AppPlugin_p.h"
 
-#include <ctkDicomAppServerPrivate.h>
-
 #include <QtPlugin>
 
 ctkDicomWG23AppPlugin* ctkDicomWG23AppPlugin::instance = 0;
@@ -43,16 +41,11 @@ void ctkDicomWG23AppPlugin::start(ctkPluginContext* context)
 {
   instance = this;
   this->context = context;
-
-  appInterface = new ctkDicomAppService();
-  context->registerService(QStringList("ctkDicomAppInterface"), appInterface);
 }
 
 void ctkDicomWG23AppPlugin::stop(ctkPluginContext* context)
 {
   Q_UNUSED(context)
-
-  delete appInterface;
 }
 
 ctkDicomWG23AppPlugin* ctkDicomWG23AppPlugin::getInstance()

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

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