Просмотр исходного кода

Lots of DAH related cleanup and proper service usage.

Sascha Zelzer лет назад: 15
Родитель
Сommit
8f0467451b
25 измененных файлов с 168 добавлено и 138 удалено
  1. 4 0
      Plugins/org.commontk.dah.app/CMakeLists.txt
  2. 6 7
      Plugins/org.commontk.dah.app/ctkAppSoapMessageProcessor.cpp
  3. 5 10
      Plugins/org.commontk.dah.app/ctkDicomAppPlugin.cpp
  4. 3 7
      Plugins/org.commontk.dah.app/ctkDicomAppPlugin_p.h
  5. 38 12
      Plugins/org.commontk.dah.app/ctkDicomAppServer.cpp
  6. 20 4
      Plugins/org.commontk.dah.app/ctkDicomAppServer_p.h
  7. 3 1
      Plugins/org.commontk.dah.app/ctkDicomHostService_p.h
  8. 4 3
      Plugins/org.commontk.dah.core/CMakeLists.txt
  9. 3 3
      Plugins/org.commontk.dah.core/ctkDicomAppHostingTypesHelper.h
  10. 3 10
      Plugins/org.commontk.dah.core/ctkDicomAppInterface.h
  11. 4 6
      Plugins/org.commontk.dah.core/ctkDicomExchangeInterface.h
  12. 2 2
      Plugins/org.commontk.dah.core/ctkDicomExchangeService.h
  13. 3 11
      Plugins/org.commontk.dah.core/ctkDicomHostInterface.h
  14. 2 2
      Plugins/org.commontk.dah.core/ctkDicomServicePrivate.h
  15. 3 4
      Plugins/org.commontk.dah.core/ctkExchangeSoapMessageProcessor.cpp
  16. 6 0
      Plugins/org.commontk.dah.core/ctkSoapMessageProcessorList.cpp
  17. 2 0
      Plugins/org.commontk.dah.core/ctkSoapMessageProcessorList.h
  18. 2 0
      Plugins/org.commontk.dah.exampleapp/CMakeLists.txt
  19. 22 4
      Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp
  20. 16 27
      Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic_p.h
  21. 8 15
      Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppPlugin.cpp
  22. 3 7
      Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppPlugin_p.h
  23. 1 0
      Plugins/org.commontk.dah.examplehost/CMakeLists.txt
  24. 1 1
      Plugins/org.commontk.dah.examplehost/ctkExampleDicomHost.h
  25. 4 2
      Plugins/org.commontk.dah.host/CMakeLists.txt

+ 4 - 0
Plugins/org.commontk.dah.app/CMakeLists.txt

@@ -6,14 +6,18 @@ SET(PLUGIN_SRCS
   ctkAppSoapMessageProcessor.cpp
   ctkDicomAbstractApp.cpp
   ctkDicomAppPlugin.cpp
+  ctkDicomAppPlugin_p.h
   ctkDicomAppServer.cpp
+  ctkDicomAppServer_p.h
   ctkDicomHostService.cpp
+  ctkDicomHostService_p.h
 )
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS
   ctkDicomAppPlugin_p.h
   ctkDicomAppServer_p.h
+  ctkDicomHostService_p.h
 )
 
 # Qt Designer files which should be processed by Qts uic

+ 6 - 7
Plugins/org.commontk.dah.app/ctkAppSoapMessageProcessor.cpp

@@ -25,12 +25,11 @@
 
 
 ctkAppSoapMessageProcessor::ctkAppSoapMessageProcessor(ctkDicomAppInterface* inter)
-: appInterface(inter)
+  : appInterface(inter)
 {}
 
 bool ctkAppSoapMessageProcessor::process(
-	const QtSoapMessage& message,
-	QtSoapMessage* reply ) const
+  const QtSoapMessage& message, QtSoapMessage* reply ) const
 {
   // TODO check for NULL appInterface?
   
@@ -59,9 +58,9 @@ bool ctkAppSoapMessageProcessor::process(
   
   return foundMethod;
 }
-		
+
 void ctkAppSoapMessageProcessor::processGetState(
-    const QtSoapMessage &message, QtSoapMessage *reply) const
+  const QtSoapMessage &message, QtSoapMessage *reply) const
 {
   Q_UNUSED(message)
 
@@ -75,7 +74,7 @@ void ctkAppSoapMessageProcessor::processGetState(
 }
 
 void ctkAppSoapMessageProcessor::processSetState(
-    const QtSoapMessage &message, QtSoapMessage *reply) const
+  const QtSoapMessage &message, QtSoapMessage *reply) const
 {
   // extract arguments from input message
   const QtSoapType& inputType = message.method()["newState"];
@@ -88,7 +87,7 @@ void ctkAppSoapMessageProcessor::processSetState(
 }
 
 void ctkAppSoapMessageProcessor::processBringToFront(
-    const QtSoapMessage &message, QtSoapMessage *reply) const
+  const QtSoapMessage &message, QtSoapMessage *reply) const
 {
   // extract arguments from input message
   const QtSoapType& inputType = message.method()["requestedScreenArea"];

+ 5 - 10
Plugins/org.commontk.dah.app/ctkDicomAppPlugin.cpp

@@ -29,10 +29,10 @@
 
 #include <stdexcept>
 
-ctkDicomAppPlugin* ctkDicomAppPlugin::instance = 0;
+ctkPluginContext* ctkDicomAppPlugin::context = 0;
 
 ctkDicomAppPlugin::ctkDicomAppPlugin()
-  : context(0), appServer(0), hostInterface(0)
+  : appServer(0), hostInterface(0)
 {
 
 }
@@ -44,7 +44,6 @@ ctkDicomAppPlugin::~ctkDicomAppPlugin()
 
 void ctkDicomAppPlugin::start(ctkPluginContext* context)
 {
-  instance = this;
   this->context = context;
 
 
@@ -65,7 +64,7 @@ void ctkDicomAppPlugin::start(ctkPluginContext* context)
 
   // register the host service, providing callbacks to the hosting application
   hostInterface = new ctkDicomHostService(QUrl(hostURL).port(), "/HostInterface");
-  context->registerService(QStringList("ctkDicomHostInterface"), hostInterface);
+  context->registerService<ctkDicomHostInterface>(hostInterface);
 
 }
 
@@ -75,14 +74,10 @@ void ctkDicomAppPlugin::stop(ctkPluginContext* context)
 
   delete appServer;
   delete hostInterface;
+  this->context = 0;
 }
 
-ctkDicomAppPlugin* ctkDicomAppPlugin::getInstance()
-{
-  return instance;
-}
-
-ctkPluginContext* ctkDicomAppPlugin::getPluginContext() const
+ctkPluginContext* ctkDicomAppPlugin::getPluginContext()
 {
   return context;
 }

+ 3 - 7
Plugins/org.commontk.dah.app/ctkDicomAppPlugin_p.h

@@ -26,7 +26,6 @@
 #include <ctkPluginActivator.h>
 
 class ctkDicomAppServer;
-class ctkDicomHostInterface;
 
 class ctkDicomAppPlugin :
   public QObject, public ctkPluginActivator
@@ -42,18 +41,15 @@ public:
   void start(ctkPluginContext* context);
   void stop(ctkPluginContext* context);
 
-  static ctkDicomAppPlugin* getInstance();
-
-  ctkPluginContext* getPluginContext() const;
+  static ctkPluginContext* getPluginContext();
 
 
 private:
 
-  static ctkDicomAppPlugin* instance;
-  ctkPluginContext* context;
+  static ctkPluginContext* context;
 
   ctkDicomAppServer* appServer;
-  ctkDicomHostInterface* hostInterface;
+  QObject* hostInterface;
 
 }; // ctkDicomAppPlugin
 

+ 38 - 12
Plugins/org.commontk.dah.app/ctkDicomAppServer.cpp

@@ -35,9 +35,12 @@
 #include <stdexcept>
 
 
-ctkDicomAppServer::ctkDicomAppServer(int port) :
-      port(port), appInterface(0)
+ctkDicomAppServer::ctkDicomAppServer(int port)
+  : appInterfaceRegistered(false), port(port),
+    appInterfaceTracker(ctkDicomAppPlugin::getPluginContext(), this)
 {
+  appInterfaceTracker.open();
+
   connect(&server, SIGNAL(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)),
           this, SLOT(incomingSoapMessage(QtSoapMessage,QtSoapMessage*)));
   connect(&server, SIGNAL(incomingWSDLMessage(QString,QString*)),
@@ -84,18 +87,41 @@ void ctkDicomAppServer::incomingSoapMessage(
   QtSoapMessage* reply)
 
 {
-  if(appInterface == NULL)
+  QMutexLocker lock(&mutex);
+  processors.process(message, reply);
+}
+
+ctkDicomAppInterface* ctkDicomAppServer::addingService(const ctkServiceReference& reference)
+{
+  QMutexLocker lock(&mutex);
+
+  if (appInterfaceRegistered)
   {
-    ctkPluginContext* context = ctkDicomAppPlugin::getInstance()->getPluginContext();
-    ctkServiceReference serviceRef = context->getServiceReference("ctkDicomAppInterface");
-    appInterface = qobject_cast<ctkDicomAppInterface*>(context->getService(serviceRef));
-    
-    ctkAppSoapMessageProcessor* appProcessor = new ctkAppSoapMessageProcessor( appInterface );
-    processors.push_back(appProcessor);
-    ctkExchangeSoapMessageProcessor* exchangeProcessor = new ctkExchangeSoapMessageProcessor( appInterface );
-    processors.push_back(exchangeProcessor);
+    //TODO maybe use ctkLogService
+    qWarning() << "A ctkDicomAppInterface service has already been added";
+    return 0;
   }
+  appInterfaceRegistered = true;
+  ctkDicomAppInterface* appInterface = ctkDicomAppPlugin::getPluginContext()->getService<ctkDicomAppInterface>(reference);
+  processors.push_back(new ctkAppSoapMessageProcessor(appInterface));
+  processors.push_back(new ctkExchangeSoapMessageProcessor(appInterface));
+  return appInterface;
+}
 
-  processors.process(message, reply);
+void ctkDicomAppServer::modifiedService(const ctkServiceReference& reference, ctkDicomAppInterface* service)
+{
+  Q_UNUSED(reference)
+  Q_UNUSED(service)
+  // do nothing
+}
+
+void ctkDicomAppServer::removedService(const ctkServiceReference& reference, ctkDicomAppInterface* service)
+{
+  Q_UNUSED(reference)
+  Q_UNUSED(service)
+
+  QMutexLocker lock(&mutex);
+  appInterfaceRegistered = false;
+  processors.clear();
 }
 

+ 20 - 4
Plugins/org.commontk.dah.app/ctkDicomAppServer_p.h

@@ -26,12 +26,19 @@
 #include <QObject>
 #include <QtSoapMessage>
 
+#include <ctkServiceTracker.h>
+
+#include <ctkDicomAppInterface.h>
 #include <ctkSimpleSoapServer.h>
 #include <ctkSoapMessageProcessorList.h>
 
-class ctkDicomAppInterface;
-
-class ctkDicomAppServer : public QObject
+/**
+ * This class serves as a SOAP server for DICOM Hosted Application
+ * specific requests. It forwards the SOAP requests to a service
+ * object registered under the ctkDicomAppInterface interface from
+ * a specific application plugin.
+ */
+class ctkDicomAppServer : public QObject, ctkServiceTrackerCustomizer<ctkDicomAppInterface*>
 {
   Q_OBJECT
 
@@ -44,13 +51,22 @@ public slots:
                            QtSoapMessage* reply);
   void incomingWSDLMessage(const QString& message, QString* reply);
 
+protected:
+
+  ctkDicomAppInterface* addingService(const ctkServiceReference& reference);
+  void modifiedService(const ctkServiceReference& reference, ctkDicomAppInterface* service);
+  void removedService(const ctkServiceReference& reference, ctkDicomAppInterface* service);
+
 private:
 
+  QMutex mutex;
+  bool appInterfaceRegistered;
+
   ctkSoapMessageProcessorList processors;
   ctkSimpleSoapServer server;
   int port;
 
-  ctkDicomAppInterface* appInterface;
+  ctkServiceTracker<ctkDicomAppInterface*> appInterfaceTracker;
 };
 
 #endif // CTKDICOMAPPPSERVER_P_H

+ 3 - 1
Plugins/org.commontk.dah.app/ctkDicomHostService_p.h

@@ -26,8 +26,10 @@
 #include <ctkDicomHostInterface.h>
 #include <ctkDicomExchangeService.h>
 
-class ctkDicomHostService : public ctkDicomHostInterface
+class ctkDicomHostService : public QObject, public ctkDicomHostInterface
 {
+  Q_OBJECT
+  Q_INTERFACES(ctkDicomHostInterface)
 
 public:
   ctkDicomHostService(ushort port, QString path);

+ 4 - 3
Plugins/org.commontk.dah.core/CMakeLists.txt

@@ -4,24 +4,25 @@ SET(PLUGIN_export_directive "org_commontk_dah_core_EXPORT")
 
 SET(PLUGIN_SRCS
   ctkDicomAppHostingCorePlugin.cpp
+  ctkDicomAppHostingCorePlugin_p.h
   ctkDicomAppHostingTypes.h
   ctkDicomAppHostingTypesHelper.h
   ctkDicomAppInterface.h
+  ctkDicomExchangeInterface.h
   ctkDicomExchangeService.cpp
   ctkDicomHostInterface.h
   ctkDicomServicePrivate.cpp
   ctkExchangeSoapMessageProcessor.cpp
   ctkSimpleSoapServer.cpp
   ctkSoapConnectionRunnable.cpp
+  ctkSoapConnectionRunnable_p.h
+  ctkSoapMessageProcessor.h
   ctkSoapMessageProcessorList.cpp
 )
 
 # Files which should be processed by Qts moc
 SET(PLUGIN_MOC_SRCS
   ctkDicomAppHostingCorePlugin_p.h
-  ctkDicomAppInterface.h
-  ctkDicomExchangeInterface.h
-  ctkDicomHostInterface.h
   ctkDicomServicePrivate.h
   ctkSimpleSoapServer.h
   ctkSoapConnectionRunnable_p.h

+ 3 - 3
Plugins/org.commontk.dah.core/ctkDicomAppHostingTypesHelper.h

@@ -20,8 +20,8 @@
 =============================================================================*/
 
 
-#ifndef CTKDICOM23TYPESHELPER_H
-#define CTKDICOM23TYPESHELPER_H
+#ifndef CTKDICOMAPPHOSTINGTYPESHELPER_H
+#define CTKDICOMAPPHOSTINGTYPESHELPER_H
 
 #include <QtSoapStruct>
 #include <QtSoapQName>
@@ -576,4 +576,4 @@ public:
 
 };
 
-#endif
+#endif // CTKDICOMAPPHOSTINGTYPESHELPER_H

+ 3 - 10
Plugins/org.commontk.dah.core/ctkDicomAppInterface.h

@@ -23,19 +23,10 @@
 #ifndef CTKDICOMAPPINTERFACE_H
 #define CTKDICOMAPPINTERFACE_H
 
-#include <QObject>
-#include <QRect>
-
-#include "ctkDicomAppHostingTypes.h"
 #include "ctkDicomExchangeInterface.h"
 
-#include <org_commontk_dah_core_Export.h>
-
-class org_commontk_dah_core_EXPORT ctkDicomAppInterface : public ctkDicomExchangeInterface
+struct ctkDicomAppInterface : public ctkDicomExchangeInterface
 {
-  Q_OBJECT
-
-public:
 
   // Application interface methods
   virtual ctkDicomAppHosting::State getState() = 0;
@@ -47,4 +38,6 @@ public:
 
 };
 
+Q_DECLARE_INTERFACE(ctkDicomAppInterface, "org.commontk.dah.core.AppInterface")
+
 #endif // CTKDICOMAPPINTERFACE_H

+ 4 - 6
Plugins/org.commontk.dah.core/ctkDicomExchangeInterface.h

@@ -23,17 +23,13 @@
 #ifndef ctkDicomExchangeInterface_H
 #define ctkDicomExchangeInterface_H
 
-#include <QObject>
 #include <QRect>
+#include <QObject>
 
 #include "ctkDicomAppHostingTypes.h"
-#include <org_commontk_dah_core_Export.h>
 
-class org_commontk_dah_core_EXPORT ctkDicomExchangeInterface : public QObject
+struct ctkDicomExchangeInterface
 {
-  Q_OBJECT
-
-public:
 
   // Data exchange interface methods
 
@@ -53,4 +49,6 @@ public:
 
 };
 
+Q_DECLARE_INTERFACE(ctkDicomExchangeInterface, "org.commontk.dah.core.ExchangeInterface")
+
 #endif // ctkDicomExchangeInterface_H

+ 2 - 2
Plugins/org.commontk.dah.core/ctkDicomExchangeService.h

@@ -23,8 +23,8 @@
 #ifndef CTKDICOMEXCHANGESERVICE_H
 #define CTKDICOMEXCHANGESERVICE_H
 
-#include <ctkDicomExchangeInterface.h>
-#include <QScopedPointer>
+#include "ctkDicomExchangeInterface.h"
+
 #include <org_commontk_dah_core_Export.h>
 
 class ctkDicomServicePrivate;

+ 3 - 11
Plugins/org.commontk.dah.core/ctkDicomHostInterface.h

@@ -23,20 +23,10 @@
 #ifndef CTKDICOMHOSTINTERFACE_H
 #define CTKDICOMHOSTINTERFACE_H
 
-#include <QObject>
-#include <QRect>
-
-#include "ctkDicomAppHostingTypes.h"
 #include "ctkDicomExchangeInterface.h"
 
-#include <org_commontk_dah_core_Export.h>
-
-class org_commontk_dah_core_EXPORT ctkDicomHostInterface: public ctkDicomExchangeInterface
+struct ctkDicomHostInterface: public ctkDicomExchangeInterface
 {
-  Q_OBJECT
-
-public:
-
   // Host interface methods
   virtual QString generateUID() = 0;
   virtual QRect getAvailableScreen(const QRect& preferredScreen) = 0;
@@ -49,4 +39,6 @@ public:
 
 };
 
+Q_DECLARE_INTERFACE(ctkDicomHostInterface, "org.commontk.dah.core.HostInterface")
+
 #endif // CTKDICOMHOSTINTERFACE_H

+ 2 - 2
Plugins/org.commontk.dah.core/ctkDicomServicePrivate.h

@@ -22,12 +22,12 @@
 #ifndef CTKDICOMSERVICEPRIVATE_H
 #define CTKDICOMSERVICEPRIVATE_H
 
-#include <ctkDicomAppHostingTypes.h>
+#include "ctkDicomAppHostingTypes.h"
 
 #include <QEventLoop>
 #include <QtSoapHttpTransport>
+
 #include <org_commontk_dah_core_Export.h>
-#include <ctkDicomExchangeInterface.h>
 
 class org_commontk_dah_core_EXPORT ctkDicomServicePrivate : public QObject
 {

+ 3 - 4
Plugins/org.commontk.dah.core/ctkExchangeSoapMessageProcessor.cpp

@@ -28,8 +28,7 @@ ctkExchangeSoapMessageProcessor::ctkExchangeSoapMessageProcessor(ctkDicomExchang
 {}
 
 bool ctkExchangeSoapMessageProcessor::process(
-	const QtSoapMessage& message,
-	QtSoapMessage* reply ) const
+  const QtSoapMessage& message, QtSoapMessage* reply ) const
 {
   // TODO check for NULL exchangeInterface?
   
@@ -58,9 +57,9 @@ bool ctkExchangeSoapMessageProcessor::process(
   
   return foundMethod;
 }
-		
+
 void ctkExchangeSoapMessageProcessor::processNotifyDataAvailable(
-    const QtSoapMessage &message, QtSoapMessage *reply) const
+  const QtSoapMessage &message, QtSoapMessage *reply) const
 {
   // extract arguments from input message
   const QtSoapType& inputType = message.method()["data"];

+ 6 - 0
Plugins/org.commontk.dah.core/ctkSoapMessageProcessorList.cpp

@@ -31,6 +31,12 @@ void ctkSoapMessageProcessorList::push_back( ctkSoapMessageProcessor* processor
   processors.push_back( processor );
 }
 
+void ctkSoapMessageProcessorList::clear()
+{
+  qDeleteAll(processors);
+  processors.clear();
+}
+
 bool ctkSoapMessageProcessorList::process(
     const QtSoapMessage& message,
     QtSoapMessage* reply ) const

+ 2 - 0
Plugins/org.commontk.dah.core/ctkSoapMessageProcessorList.h

@@ -37,6 +37,8 @@ public:
 
   void push_back( ctkSoapMessageProcessor* processor );
 
+  void clear();
+
   bool process(const QtSoapMessage& message,
                QtSoapMessage* reply) const;
 

+ 2 - 0
Plugins/org.commontk.dah.exampleapp/CMakeLists.txt

@@ -3,6 +3,8 @@ PROJECT(org_commontk_dah_exampleapp)
 SET(PLUGIN_export_directive "org_commontk_example_dicomapp_EXPORT")
 
 SET(PLUGIN_SRCS
+  ctkExampleDicomAppLogic_p.h
+  ctkExampleDicomAppPlugin_p.h
   ctkExampleDicomAppLogic.cpp
   ctkExampleDicomAppPlugin.cpp
 )

+ 22 - 4
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

@@ -21,14 +21,20 @@
 
 
 #include "ctkExampleDicomAppLogic_p.h"
+#include "ctkExampleDicomAppPlugin_p.h"
+
+#include <ctkDicomHostInterface.h>
+
 #include <QtPlugin>
 #include <QRect>
 #include <QDebug>
 #include <QPushButton>
 
-ctkExampleDicomAppLogic::ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host)
-  : host(host)
+ctkExampleDicomAppLogic::ctkExampleDicomAppLogic()
+  : hostTracker(ctkExampleDicomAppPlugin::getPluginContext())
 {
+  hostTracker.open();
+
   connect(this, SIGNAL(stateChanged(int)), this, SLOT(changeState(int)), Qt::QueuedConnection);
   emit stateChanged(ctkDicomAppHosting::IDLE);
 }
@@ -59,9 +65,10 @@ void ctkExampleDicomAppLogic::do_something()
   QPushButton *button = new QPushButton("Button from App");
   try
   {
+
     QRect preferred(50,50,100,100);
     qDebug() << "  Asking:getAvailableScreen";
-    QRect rect = host->getAvailableScreen(preferred);
+    QRect rect = getHostInterface()->getAvailableScreen(preferred);
     qDebug() << "  got sth:" << rect.top();
     button->move(rect.topLeft());
     button->resize(rect.size());
@@ -69,6 +76,7 @@ void ctkExampleDicomAppLogic::do_something()
   catch (const std::runtime_error& e)
   {
     qCritical() << e.what();
+    return;
   }
   button->show();
 }
@@ -76,13 +84,15 @@ void ctkExampleDicomAppLogic::do_something()
 void ctkExampleDicomAppLogic::changeState(int anewstate)
 {
   ctkDicomAppHosting::State newstate = static_cast<ctkDicomAppHosting::State>(anewstate);
+
   try
   {
-    host->notifyStateChanged(newstate);
+    getHostInterface()->notifyStateChanged(newstate);
   }
   catch (const std::runtime_error& e)
   {
     qCritical() << e.what();
+    return;
   }
 
   if (newstate == ctkDicomAppHosting::INPROGRESS)
@@ -108,7 +118,15 @@ QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
   Q_UNUSED(includeBulkData)
   return QList<ctkDicomAppHosting::ObjectLocator>();
 }
+
 void ctkExampleDicomAppLogic::releaseData(QList<QUuid> objectUUIDs)
 {
   Q_UNUSED(objectUUIDs)
 }
+
+ctkDicomHostInterface* ctkExampleDicomAppLogic::getHostInterface() const
+{
+  ctkDicomHostInterface* host = hostTracker.getService();
+  if (!host) throw std::runtime_error("DICOM Host Interface not available");
+  return host;
+}

+ 16 - 27
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic_p.h

@@ -23,41 +23,20 @@
 #ifndef CTKEXAMPLEDICOMAPPLOGIC_P_H
 #define CTKEXAMPLEDICOMAPPLOGIC_P_H
 
-#include <ctkPluginActivator.h>
-#include <ctkServiceReference.h>
 #include <ctkDicomAppInterface.h>
-#include <ctkDicomHostInterface.h>
-#include <stdexcept>
 
-template <class TServiceType>
-class ServiceAccessor {
-public:
-  ServiceAccessor(ctkPluginContext* context, const QString& clazz) : context(context), clazz(clazz)
-  {
-  }
-  TServiceType* operator->()
-  {
-    ctkServiceReference serviceRef = context->getServiceReference(clazz);
-    return qobject_cast<TServiceType*>(context->getService(serviceRef));
-  }
-  TServiceType* operator*()
-  {
-    return operator->();
-  }
-private:
-  ctkPluginContext* context;
-  const QString clazz;
-};
+#include <ctkServiceTracker.h>
 
+class ctkDicomHostInterface;
 
-class ctkExampleDicomAppLogic :
-  public ctkDicomAppInterface
+class ctkExampleDicomAppLogic : public QObject, public ctkDicomAppInterface
 {
   Q_OBJECT
+  Q_INTERFACES(ctkDicomAppInterface)
 
 public:
 
-  ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface> host);
+  ctkExampleDicomAppLogic();
   ~ctkExampleDicomAppLogic();
 
   // ctkDicomAppInterface
@@ -67,20 +46,30 @@ public:
 
   // ctkDicomExchangeInterface
   bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
+
   QList<ctkDicomAppHosting::ObjectLocator> getData(
     QList<QUuid> objectUUIDs, 
     QList<QString> acceptableTransferSyntaxUIDs, 
     bool includeBulkData);
+
   void releaseData(QList<QUuid> objectUUIDs);
 
   // some logic
   void do_something();
+
 signals:
+
   void stateChanged(int);
+
 protected slots:
+
   void changeState(int);
+
 private:
-  ServiceAccessor<ctkDicomHostInterface> host;
+
+  ctkDicomHostInterface* getHostInterface() const;
+
+  ctkServiceTracker<ctkDicomHostInterface*> hostTracker;
 
 }; // ctkExampleDicomAppLogic
 

+ 8 - 15
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppPlugin.cpp

@@ -26,41 +26,34 @@
 #include <QStringList>
 #include <QString>
 
-ctkExampleDicomAppPlugin* ctkExampleDicomAppPlugin::instance = 0;
+ctkPluginContext* ctkExampleDicomAppPlugin::context = 0;
 
 ctkExampleDicomAppPlugin::ctkExampleDicomAppPlugin()
-  : appLogic(0), context(0)
+  : appLogic(0)
 {
 }
 
 ctkExampleDicomAppPlugin::~ctkExampleDicomAppPlugin()
 {
-  
+  delete appLogic;
 }
 
 void ctkExampleDicomAppPlugin::start(ctkPluginContext* context)
 {
-  instance = this;
   this->context = context;
-  context->registerService(QStringList("ctkDicomAppInterface"), 
-    appLogic = new ctkExampleDicomAppLogic(ServiceAccessor<ctkDicomHostInterface>(context,"ctkDicomHostInterface")));
 
-  //ctkServiceReference serviceRef = context->getServiceReference("ctkDicomHostInterface");
-  //ctkDicomHostInterface*
-  //  serviceBinding = qobject_cast<ctkDicomHostInterface*>(context->getService(serviceRef));
+  delete appLogic;
+  appLogic = new ctkExampleDicomAppLogic();
+  context->registerService<ctkDicomAppInterface>(appLogic);
 }
 
 void ctkExampleDicomAppPlugin::stop(ctkPluginContext* context)
 {
   Q_UNUSED(context)
+  this->context = 0;
 }
 
-ctkExampleDicomAppPlugin* ctkExampleDicomAppPlugin::getInstance()
-{
-  return instance;
-}
-
-ctkPluginContext* ctkExampleDicomAppPlugin::getPluginContext() const
+ctkPluginContext* ctkExampleDicomAppPlugin::getPluginContext()
 {
   return context;
 }

+ 3 - 7
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppPlugin_p.h

@@ -41,17 +41,13 @@ public:
   void start(ctkPluginContext* context);
   void stop(ctkPluginContext* context);
 
-  static ctkExampleDicomAppPlugin* getInstance();
-
-  ctkPluginContext* getPluginContext() const;
-
-  ctkExampleDicomAppLogic* appLogic;
+  static ctkPluginContext* getPluginContext();
 
 private:
 
-  static ctkExampleDicomAppPlugin* instance;
-  ctkPluginContext* context;
+  static ctkPluginContext* context;
 
+  QObject* appLogic;
 
 }; // ctkExampleDicomAppPlugin
 

+ 1 - 0
Plugins/org.commontk.dah.examplehost/CMakeLists.txt

@@ -5,6 +5,7 @@ SET(PLUGIN_export_directive "org_commontk_dah_examplehost_EXPORT")
 SET(PLUGIN_SRCS
   ctkExampleDicomHost.cpp
   ctkExampleDicomHostPlugin.cpp
+  ctkExampleDicomHostPlugin_p.h
   ctkHostedAppPlaceholderWidget.cpp
 )
 

+ 1 - 1
Plugins/org.commontk.dah.examplehost/ctkExampleDicomHost.h

@@ -30,7 +30,7 @@
 #include <QUrl>
 #include <QProcess>
 
-class org_commontk_dah_examplehost_EXPORT ctkExampleDicomHost : public ctkDicomAbstractHost
+class org_commontk_dah_examplehost_EXPORT ctkExampleDicomHost : public QObject, public ctkDicomAbstractHost
 {
   Q_OBJECT
 

+ 4 - 2
Plugins/org.commontk.dah.host/CMakeLists.txt

@@ -4,11 +4,13 @@ SET(PLUGIN_export_directive "org_commontk_dah_host_EXPORT")
 
 SET(PLUGIN_SRCS
   ctkDicomAbstractHost.cpp
-  ctkDicomAppService.cpp  
-  ctkDicomHostPlugin.cpp  
+  ctkDicomAppService.cpp
+  ctkDicomHostPlugin.cpp
+  ctkDicomHostPlugin_p.h
   ctkDicomHostServer.cpp
   ctkDicomHostServerPrivate.cpp
   ctkHostSoapMessageProcessor.cpp
+  ctkHostSoapMessageProcessor_p.h
 )
 
 # Files which should be processed by Qts moc