Browse Source

CHG: hosting server port and business logic initialization

Marco Nolden 15 years ago
parent
commit
f8785029af

+ 2 - 3
Plugins/org.commontk.dicom.wg23.host/ctkDicomHostServer.cpp

@@ -19,13 +19,12 @@
 
 =============================================================================*/
 
-
 #include "ctkDicomHostServer.h"
 
 #include "ctkDicomHostServerPrivate.h"
 
-ctkDicomHostServer::ctkDicomHostServer()
-  : d_ptr(new ctkDicomHostServerPrivate)
+ctkDicomHostServer::ctkDicomHostServer(ctkDicomHostInterface* hostInterface, int port)
+  : d_ptr(new ctkDicomHostServerPrivate(hostInterface, port))
 {
 
 }

+ 3 - 1
Plugins/org.commontk.dicom.wg23.host/ctkDicomHostServer.h

@@ -23,6 +23,8 @@
 #ifndef CTKDICOMHOSTSERVER_H
 #define CTKDICOMHOSTSERVER_H
 
+class ctkDicomHostInterface;
+
 #include <QScopedPointer>
 
 class ctkDicomHostServerPrivate;
@@ -31,7 +33,7 @@ class ctkDicomHostServer
 {
 
 public:
-  ctkDicomHostServer();
+  ctkDicomHostServer(ctkDicomHostInterface* hostInterface, int port);
 
   Q_DECLARE_PRIVATE(ctkDicomHostServer)
 

+ 7 - 18
Plugins/org.commontk.dicom.wg23.host/ctkDicomHostServerPrivate.cpp

@@ -22,8 +22,6 @@
 
 #include "ctkDicomHostServerPrivate.h"
 
-#include "ctkDicomWG23HostPlugin_p.h"
-
 #include <ctkDicomHostInterface.h>
 
 #include <QHostAddress>
@@ -31,25 +29,16 @@
 #include <stdexcept>
 #include <ctkDicomWG23TypesHelper.h>
 
-ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(QObject *parent) :
-    QObject(parent)
+ctkDicomHostServerPrivate::ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port) :
+    hostInterface(hostInterface), port(port)
 {
-  ctkPluginContext* context = ctkDicomWG23HostPlugin::getInstance()->getPluginContext();
-  ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomHostInterface");
-  if (!serviceRef)
-  {
-    // this will change after mergin changes from branch plugin_framework
-    throw std::runtime_error("No Dicom Host Service found");
-  }
-
-  serviceBinding = qobject_cast<ctkDicomHostInterface*>(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.";
   }
 }
 
@@ -81,7 +70,7 @@ void ctkDicomHostServerPrivate::processGetAvailableScreen(
   const QtSoapType& preferredScreenType = message.method()["preferredScreen"];
   const QRect preferredScreen = ctkDicomSoapRectangle::getQRect(preferredScreenType);
 
-  const QRect result = serviceBinding->getAvailableScreen(preferredScreen);
+  const QRect result = hostInterface->getAvailableScreen(preferredScreen);
 
   reply->setMethod("GetAvailableScreenResponse");
   QtSoapStruct* availableScreenType = new ctkDicomSoapRectangle("availableScreen",result);
@@ -92,13 +81,13 @@ void ctkDicomHostServerPrivate::processNotifyStateChanged(
     const QtSoapMessage &message, QtSoapMessage *reply)
 {
     const QtSoapType& stateType = message.method()["state"];
-    serviceBinding->notifyStateChanged(ctkDicomSoapState::getState(stateType));
+    hostInterface->notifyStateChanged(ctkDicomSoapState::getState(stateType));
 }
 
 void ctkDicomHostServerPrivate::processNotifyStatus(
     const QtSoapMessage &message, QtSoapMessage *reply)
 {
     const QtSoapType& status = message.method()["status"];
-    serviceBinding->notifyStatus(ctkDicomSoapStatus::getStatus(status));
+    hostInterface->notifyStatus(ctkDicomSoapStatus::getStatus(status));
 
 }

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

@@ -35,9 +35,11 @@ class ctkDicomHostServerPrivate : public QObject
   Q_OBJECT
 
 public:
-  ctkDicomHostServerPrivate(QObject *parent = 0);
+  ctkDicomHostServerPrivate(ctkDicomHostInterface* hostInterface, int port);
 
   ctkSimpleSoapServer server;
+  ctkDicomHostInterface* hostInterface;
+  int port;
 
 public slots: