Kaynağa Gözat

ENH: on the way to use ctkDicomAppServer for the example app

ivowolf 14 yıl önce
ebeveyn
işleme
83785f9c0d

+ 3 - 3
Applications/ctkExampleHostedApp/ctkExampleHostedAppMain.cpp

@@ -27,7 +27,7 @@
 // --hostURL http://localhost:8081/host --applicationURL http://localhost:8082/app dicomapp
 
 // replace "//$" with nothing as soon as ctkDicomAppServer/ctkDicomHostService exist
-//$#include <ctkDicomAppServer.h>
+#include <ctkDicomAppServer.h>
 //$#include <ctkDicomHostService.h>
 
 #include <QApplication>
@@ -159,8 +159,8 @@ int main(int argv, char** argc)
   }
 
   // setup the communication infrastructure: DicomAppServer and DicomHostService
-//$  ctkDicomAppServer * appServer = new ctkDicomAppServer(appURL); // accesses the app-plugin via getService("ctkDicomAppInterface");
-//$  ctkDicomHostInterface * hostInterface = new ctkDicomHostService(hostURL);
+  ctkDicomAppServer * appServer = new ctkDicomAppServer(QUrl(appURL).port()); // accesses the app-plugin via getService("ctkDicomAppInterface");
+//$  ctkDicomHostInterface * hostInterface = new ctkDicomHostService(QUrl(hostURL).port());
 //$  framework->getPluginContext()->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
 
   framework->start();

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

@@ -11,7 +11,7 @@ class ctkDicomAbstractAppPrivate
     {
       port = 8080;
     }
-    server = new ctkDicomAppServer(appInterface,port);
+    server = new ctkDicomAppServer(port);
   }
   ~ctkDicomAbstractAppPrivate()
   {

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

@@ -23,8 +23,8 @@
 
 #include "ctkDicomAppServerPrivate.h"
 
-ctkDicomAppServer::ctkDicomAppServer(ctkDicomAppInterface* appInterface, int port)
-  : d_ptr(new ctkDicomAppServerPrivate(appInterface, port))
+ctkDicomAppServer::ctkDicomAppServer(int port)
+  : d_ptr(new ctkDicomAppServerPrivate(port))
 {
 
 }

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

@@ -26,14 +26,15 @@
 class ctkDicomAppInterface;
 
 #include <QScopedPointer>
+#include <org_commontk_dicom_wg23_app_Export.h>
 
 class ctkDicomAppServerPrivate;
 
-class ctkDicomAppServer
+class org_commontk_dicom_wg23_app_EXPORT ctkDicomAppServer
 {
 
 public:
-  ctkDicomAppServer(ctkDicomAppInterface* appInterface, int port);
+  ctkDicomAppServer(int port);
   ~ctkDicomAppServer();
 
 private:

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

@@ -23,16 +23,17 @@
 #include "ctkDicomAppServerPrivate.h"
 
 #include <ctkDicomAppInterface.h>
+#include <ctkServiceReference.h>
 
 #include <QHostAddress>
 
 #include <stdexcept>
 #include <ctkDicomWG23TypesHelper.h>
+#include <ctkDicomWG23AppPlugin_p.h>
 
-ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(ctkDicomAppInterface* appInterface, int port) :
-    appInterface(appInterface), port(port)
+ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(int port) :
+    appInterface(0), port(port)
 {
-
   connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
           this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
 
@@ -40,6 +41,15 @@ ctkDicomAppServerPrivate::ctkDicomAppServerPrivate(ctkDicomAppInterface* appInte
   {
     qCritical() << "Listening to 127.0.0.1:" << port << " failed.";
   }
+
+  ctkPluginContext* context = ctkDicomWG23AppPlugin::getInstance()->getPluginContext();
+  ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomAppInterface");
+  if (!serviceRef)
+  {
+    // this will change after merging changes from branch plugin_framework
+    throw std::runtime_error("No Dicom App Service found");
+  }
+  appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
 }
 
 void ctkDicomAppServerPrivate::incomingSoapMessage(const QtSoapMessage& message,

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

@@ -35,7 +35,7 @@ class ctkDicomAppServerPrivate : public QObject
   Q_OBJECT
 
 public:
-  ctkDicomAppServerPrivate(ctkDicomAppInterface* appInterface, int port);
+  ctkDicomAppServerPrivate(int port);
 
   ctkSimpleSoapServer server;
   ctkDicomAppInterface* appInterface;

+ 9 - 3
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic.cpp

@@ -23,15 +23,16 @@
 #include "ctkExampleDicomAppLogic_p.h"
 #include <QtPlugin>
 #include <QRect>
+#include <QDebug>
+#include <QPushButton>
 
-ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>* host)
+ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host)
   : host(host)
 {
 }
 
 ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
 {
-  delete host;
 }
 
 ctkDicomWG23::State ctkExampleDicomAppLogic::getState()
@@ -42,6 +43,11 @@ ctkDicomWG23::State ctkExampleDicomAppLogic::getState()
 bool ctkExampleDicomAppLogic::setState(ctkDicomWG23::State newState)
 {
   qDebug() << "setState called";
+  if (newState == ctkDicomWG23::INPROGRESS)
+  {
+    QPushButton *button = new QPushButton("Button from App");
+    button->show();
+  }
   return false;
 }
 
@@ -53,5 +59,5 @@ bool ctkExampleDicomAppLogic::bringToFront(const QRect& requestedScreenArea)
 void ctkExampleDicomAppLogic::do_something()
 {
   QRect preferred;
-  QRect rect = host->call()->getAvailableScreen(preferred);
+  QRect rect = host->getAvailableScreen(preferred);
 }

+ 8 - 4
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppLogic_p.h

@@ -33,7 +33,7 @@ public:
   ServiceAccessor(ctkPluginContext* context, const QString& clazz) : context(context), clazz(clazz)
   {
   }
-  TServiceType* call()
+  TServiceType* operator->()
   {
     ctkServiceReference* serviceRef = context->getServiceReference(clazz);
     if (!serviceRef)
@@ -43,9 +43,13 @@ public:
     }
     return qobject_cast<TServiceType*>(context->getService(serviceRef));
   }
+  TServiceType* operator*()
+  {
+    return operator->();
+  }
 private:
   ctkPluginContext* context;
-  const QString& clazz;
+  const QString clazz;
 };
 
 
@@ -56,7 +60,7 @@ class ctkExampleDicomAppLogic :
 
 public:
 
-  ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>* host);
+  ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host);
   ~ctkExampleDicomAppLogic();
 
   // ctkDicomAppInterface
@@ -69,7 +73,7 @@ public:
   // some logic
   void do_something();
 private:
-  ServiceAccessor<ctkDicomHostInterface>* host;
+  ServiceAccessor<ctkDicomHostInterface> host;
 
 }; // ctkExampleDicomAppLogic
 

+ 2 - 2
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppPlugin.cpp

@@ -29,7 +29,7 @@
 ctkExampleDicomAppPlugin* ctkExampleDicomAppPlugin::instance = 0;
 
 ctkExampleDicomAppPlugin::ctkExampleDicomAppPlugin()
-  : context(0)
+  : context(0), appLogic(0)
 {
 }
 
@@ -43,7 +43,7 @@ void ctkExampleDicomAppPlugin::start(ctkPluginContext* context)
   instance = this;
   this->context = context;
   context->registerService(QStringList("ctkDicomAppInterface"), 
-    new ctkExampleDicomAppLogic(new ServiceAccessor<ctkDicomHostInterface>(context,"ctkDicomHostInterface")));
+    appLogic = new ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>(context,"ctkDicomHostInterface")));
 
   //ctkServiceReference* serviceRef = context->getServiceReference("ctkDicomHostInterface");
   //if (!serviceRef)

+ 3 - 0
Plugins/org.commontk.example.dicomapp/ctkExampleDicomAppPlugin_p.h

@@ -25,6 +25,8 @@
 
 #include <ctkPluginActivator.h>
 
+class ctkExampleDicomAppLogic;
+
 class ctkExampleDicomAppPlugin :
   public QObject, public ctkPluginActivator
 {
@@ -43,6 +45,7 @@ public:
 
   ctkPluginContext* getPluginContext() const;
 
+  ctkExampleDicomAppLogic* appLogic;
 
 private: