Browse Source

Merge branch 'dah' into dah_master_merge

Ivo Wolf 14 years ago
parent
commit
f549e15989

+ 3 - 1
Applications/ctkExampleHost/ctkHostAppExampleWidget.cpp

@@ -117,7 +117,9 @@ ctkHostAppExampleWidget::ctkHostAppExampleWidget(QWidget *parent) :
 ctkHostAppExampleWidget::~ctkHostAppExampleWidget()
 {
   delete this->Host;
-  delete ui;
+  this->Host = 0;
+  delete this->ui;
+  this->ui = 0;
 }
 
 //----------------------------------------------------------------------------

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

@@ -18,6 +18,7 @@ SET(PLUGIN_MOC_SRCS
   ctkDicomAppPlugin_p.h
   ctkDicomAppServer_p.h
   ctkDicomHostService_p.h
+  ctkDicomAbstractApp.h
 )
 
 # Qt Designer files which should be processed by Qts uic

+ 103 - 3
Plugins/org.commontk.dah.app/ctkDicomAbstractApp.cpp

@@ -21,20 +21,27 @@
 
 // CTK includes
 #include "ctkDicomAbstractApp.h"
+#include <ctkDicomHostInterface.h>
+#include <ctkPluginContext.h>
+#include <ctkServiceTracker.h>
 
 class ctkDicomAbstractAppPrivate
 {
 public:
-  ctkDicomAbstractAppPrivate();
+  ctkDicomAbstractAppPrivate(ctkPluginContext* context);
   ~ctkDicomAbstractAppPrivate();
+
+  ctkServiceTracker<ctkDicomHostInterface*> HostTracker;
+  ctkDicomAppHosting::State currentState;
 };
 
 //----------------------------------------------------------------------------
 // ctkDicomAbstractAppPrivate methods
 
 //----------------------------------------------------------------------------
-ctkDicomAbstractAppPrivate::ctkDicomAbstractAppPrivate()
+ctkDicomAbstractAppPrivate::ctkDicomAbstractAppPrivate(ctkPluginContext * context):HostTracker(context),currentState(ctkDicomAppHosting::IDLE)
 {
+  //perhaps notStarted or some dummy state instead of IDLE?
 }
 
 //----------------------------------------------------------------------------
@@ -46,11 +53,104 @@ ctkDicomAbstractAppPrivate::~ctkDicomAbstractAppPrivate()
 // ctkDicomAbstractApp methods
 
 //----------------------------------------------------------------------------
-ctkDicomAbstractApp::ctkDicomAbstractApp() : d_ptr(new ctkDicomAbstractAppPrivate())
+ctkDicomAbstractApp::ctkDicomAbstractApp(ctkPluginContext* context) : d_ptr(new ctkDicomAbstractAppPrivate(context))
 {
+  d_ptr->HostTracker.open();
 }
 
 //----------------------------------------------------------------------------
 ctkDicomAbstractApp::~ctkDicomAbstractApp()
 {
 }
+
+/**
+  * Method triggered by the host. Changes the state of the hosted application.
+  *@return true if state received and not illegal in the transition diagram from the reference, false if illegal or not recognized.
+  */
+bool ctkDicomAbstractApp::setState(ctkDicomAppHosting::State newState)
+{
+  bool result = true;
+  //received a new state,
+  switch (newState){
+  case ctkDicomAppHosting::IDLE:
+    if (d_ptr->currentState == ctkDicomAppHosting::COMPLETED)
+    {
+
+    }
+    else
+    {
+      result = false;
+    }
+    break;
+  case ctkDicomAppHosting::INPROGRESS:
+    if (d_ptr->currentState == ctkDicomAppHosting::IDLE)
+    {
+      emit startProgress();
+    }
+    else if(d_ptr->currentState == ctkDicomAppHosting::SUSPENDED)
+    {
+      emit resumeProgress();
+    }
+    else
+    {
+      result = false;
+    }
+    break;
+  case ctkDicomAppHosting::COMPLETED:
+    qDebug() << "Hosting system shouldn't send completed";
+    result = false;
+    break;
+  case ctkDicomAppHosting::SUSPENDED:
+    //suspend computation, release as much resource as possible with possible resuming of computation
+    emit suspendProgress();
+    break;
+  case ctkDicomAppHosting::CANCELED:
+    //stop and release everything.
+    if (d_ptr->currentState != ctkDicomAppHosting::INPROGRESS
+        || d_ptr->currentState != ctkDicomAppHosting::SUSPENDED)
+    {
+      result = false;
+    }
+    else
+    {
+      //releasing resources
+      emit cancelProgress();
+      //special state, a transitional state, so we notify straight away the new state.
+      getHostInterface()->notifyStateChanged(ctkDicomAppHosting::CANCELED);
+      d_ptr->currentState = ctkDicomAppHosting::CANCELED;
+    }
+    break;
+  case ctkDicomAppHosting::EXIT:
+    //check if current state is IDLE
+    if (d_ptr->currentState != ctkDicomAppHosting::IDLE)
+    {
+      qDebug()<<"illegal transition to EXIT." <<
+                 "Current state is:" << d_ptr->currentState;
+      result = false;
+    }
+    //maybe not useful:
+    getHostInterface()->notifyStateChanged(ctkDicomAppHosting::EXIT);
+    emit exitHostedApp();
+    break;
+  default:
+    //should never happen
+    qDebug() << "unexisting state Code, do nothing";
+    result = false;
+  }
+  if (!result)
+  {
+    qDebug()<<"illegal transition to: "<< newState <<
+               "Current state is:" << d_ptr->currentState;
+  }
+  return result;
+}
+
+
+ctkDicomHostInterface* ctkDicomAbstractApp::getHostInterface() const
+{
+  ctkDicomHostInterface* host = d_ptr->HostTracker.getService();
+  if (!host) throw std::runtime_error("DICOM Host Interface not available");
+  return host;
+}
+
+

+ 16 - 3
Plugins/org.commontk.dah.app/ctkDicomAbstractApp.h

@@ -27,7 +27,8 @@
 #include <org_commontk_dah_app_Export.h>
 
 class ctkDicomAbstractAppPrivate;
-
+class ctkDicomHostInterface;
+class ctkPluginContext;
 /**
   * Provides a basic implementation for an application app.
   *
@@ -36,13 +37,25 @@ class ctkDicomAbstractAppPrivate;
   * The methods of the ctkDicomAppInterface have to be implemented for the business logic,
   *
   */
-class org_commontk_dah_app_EXPORT ctkDicomAbstractApp : public ctkDicomAppInterface
+class org_commontk_dah_app_EXPORT ctkDicomAbstractApp : public QObject, public ctkDicomAppInterface
 {
+  Q_OBJECT
 
 public:
 
-  ctkDicomAbstractApp();
+  ctkDicomAbstractApp(ctkPluginContext* context);
   virtual ~ctkDicomAbstractApp();
+  virtual bool setState(ctkDicomAppHosting::State newState);
+
+protected:
+  virtual ctkDicomHostInterface* getHostInterface() const;
+
+signals:
+  void startProgress();
+  void resumeProgress();
+  void suspendProgress();
+  void cancelProgress();
+  void exitHostedApp();
 
 private:
   Q_DECLARE_PRIVATE(ctkDicomAbstractApp)

+ 2 - 1
Plugins/org.commontk.dah.app/ctkDicomAppPlugin.cpp

@@ -44,7 +44,6 @@ ctkDicomAppPlugin::ctkDicomAppPlugin()
 //----------------------------------------------------------------------------
 ctkDicomAppPlugin::~ctkDicomAppPlugin()
 {
-  std::cout<<"in the destructor of the plugin"<<std::endl;
   delete this->AppServer;
   delete this->HostInterface;
   ctkDicomAppPlugin::Context = 0;
@@ -83,6 +82,8 @@ void ctkDicomAppPlugin::stop(ctkPluginContext* context)
 
   delete this->AppServer;
   delete this->HostInterface;
+  this->AppServer = 0;
+  this->HostInterface = 0;
   this->Context = 0;
 }
 

+ 4 - 4
Plugins/org.commontk.dah.app/ctkDicomHostService.cpp

@@ -81,22 +81,22 @@ void ctkDicomHostService::notifyStatus(const ctkDicomAppHosting::Status& status)
 // Exchange methods
 
 //----------------------------------------------------------------------------
-bool ctkDicomHostService::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
+bool ctkDicomHostService::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
 {
   return ctkDicomExchangeService::notifyDataAvailable(data, lastData);
 }
 
 //----------------------------------------------------------------------------
 QList<ctkDicomAppHosting::ObjectLocator> ctkDicomHostService::getData(
-  QList<QUuid> objectUUIDs, 
-  QList<QString> acceptableTransferSyntaxUIDs, 
+  const QList<QUuid>& objectUUIDs,
+  const QList<QString>& acceptableTransferSyntaxUIDs,
   bool includeBulkData)
 {
   return ctkDicomExchangeService::getData(objectUUIDs, acceptableTransferSyntaxUIDs, includeBulkData);
 }
 
 //----------------------------------------------------------------------------
-void ctkDicomHostService::releaseData(QList<QUuid> objectUUIDs)
+void ctkDicomHostService::releaseData(const QList<QUuid>& objectUUIDs)
 {
   ctkDicomExchangeService::releaseData(objectUUIDs);
 }

+ 4 - 4
Plugins/org.commontk.dah.app/ctkDicomHostService_p.h

@@ -43,14 +43,14 @@ public:
   virtual void notifyStatus(const ctkDicomAppHosting::Status& status);
 
   // Exchange methods implemented in ctkDicomExchangeService
-  virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
+  virtual bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData);
 
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-    QList<QUuid> objectUUIDs, 
-    QList<QString> acceptableTransferSyntaxUIDs, 
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
     bool includeBulkData);
 
-  virtual void releaseData(QList<QUuid> objectUUIDs);
+  virtual void releaseData(const QList<QUuid>& objectUUIDs);
 
 };
 

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

@@ -34,14 +34,14 @@ struct ctkDicomExchangeInterface
 
   // Data exchange interface methods
 
-  virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData) = 0;
+  virtual bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData) = 0;
 
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-    QList<QUuid> objectUUIDs, 
-    QList<QString> acceptableTransferSyntaxUIDs, 
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
     bool includeBulkData) = 0;
 
-  virtual void releaseData(QList<QUuid> objectUUIDs) = 0;
+  virtual void releaseData(const QList<QUuid>& objectUUIDs) = 0;
 
 //    8.3.3 getAsModels(objectUUIDs : ArrayOfUUID, classUID : UID, supportedInfosetTypes : ArrayOfMimeType) : ModelSetDescriptor	33
 //    8.3.4 queryModel(models : ArrayOfUUID, xpaths : ArrayOfString) : ArrayOfQueryResult	34

+ 4 - 4
Plugins/org.commontk.dah.core/ctkDicomExchangeService.cpp

@@ -40,7 +40,7 @@ ctkDicomExchangeService::~ctkDicomExchangeService()
 
 //----------------------------------------------------------------------------
 bool ctkDicomExchangeService::notifyDataAvailable(
-    ctkDicomAppHosting::AvailableData data, bool lastData)
+    const ctkDicomAppHosting::AvailableData& data, bool lastData)
 {
   QList<QtSoapType*> list;
   list << new ctkDicomSoapAvailableData("data", data);
@@ -51,8 +51,8 @@ bool ctkDicomExchangeService::notifyDataAvailable(
 
 //----------------------------------------------------------------------------
 QList<ctkDicomAppHosting::ObjectLocator> ctkDicomExchangeService::getData(
-    QList<QUuid> objectUUIDs,
-    QList<QString> acceptableTransferSyntaxUIDs, bool includeBulkData)
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs, bool includeBulkData)
 {
   //Q_D(ctkDicomService);
   QList<QtSoapType*> list;
@@ -75,7 +75,7 @@ DumpAll(result); //xxx
 }
 
 //----------------------------------------------------------------------------
-void ctkDicomExchangeService::releaseData(QList<QUuid> objectUUIDs)
+void ctkDicomExchangeService::releaseData(const QList<QUuid>& objectUUIDs)
 {
   QList<QtSoapType*> list;
 

+ 8 - 4
Plugins/org.commontk.dah.core/ctkDicomExchangeService.h

@@ -37,10 +37,14 @@ public:
   ctkDicomExchangeService(ushort port, QString path);
   virtual ~ctkDicomExchangeService();
 
-  bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
-  QList<ctkDicomAppHosting::ObjectLocator> getData(QList<QUuid> objectUUIDs,
-                                             QList<QString> acceptableTransferSyntaxUIDs, bool includeBulkData);
-  void releaseData(QList<QUuid> objectUUIDs);
+  bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData);
+
+  QList<ctkDicomAppHosting::ObjectLocator> getData(
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
+    bool includeBulkData);
+
+  void releaseData(const QList<QUuid>& objectUUIDs);
 
 };
 

+ 8 - 13
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

@@ -36,10 +36,10 @@
 #include <dcmimage.h>
 
 //----------------------------------------------------------------------------
-ctkExampleDicomAppLogic::ctkExampleDicomAppLogic()
-  : HostTracker(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
+ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
+ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
 {
-  this->HostTracker.open();
+
 
   connect(this, SIGNAL(stateChanged(int)), this, SLOT(changeState(int)), Qt::QueuedConnection);
   emit stateChanged(ctkDicomAppHosting::IDLE);
@@ -142,7 +142,7 @@ void ctkExampleDicomAppLogic::changeState(int anewstate)
 }
 
 //----------------------------------------------------------------------------
-bool ctkExampleDicomAppLogic::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
+bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
 {
   Q_UNUSED(lastData)
   QString s;
@@ -173,8 +173,8 @@ bool ctkExampleDicomAppLogic::notifyDataAvailable(ctkDicomAppHosting::AvailableD
 
 //----------------------------------------------------------------------------
 QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
-  QList<QUuid> objectUUIDs,
-  QList<QString> acceptableTransferSyntaxUIDs,
+  const QList<QUuid>& objectUUIDs,
+  const QList<QString>& acceptableTransferSyntaxUIDs,
   bool includeBulkData)
 {
   Q_UNUSED(objectUUIDs)
@@ -184,17 +184,12 @@ QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomAppLogic::getData(
 }
 
 //----------------------------------------------------------------------------
-void ctkExampleDicomAppLogic::releaseData(QList<QUuid> objectUUIDs)
+void ctkExampleDicomAppLogic::releaseData(const QList<QUuid>& objectUUIDs)
 {
   Q_UNUSED(objectUUIDs)
 }
 
-ctkDicomHostInterface* ctkExampleDicomAppLogic::getHostInterface() const
-{
-  ctkDicomHostInterface* host = this->HostTracker.getService();
-  if (!host) throw std::runtime_error("DICOM Host Interface not available");
-  return host;
-}
+
 
 void ctkExampleDicomAppLogic::buttonClicked()
 {

+ 5 - 11
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic_p.h

@@ -32,7 +32,7 @@ struct ctkDicomHostInterface;
 
 class QPushButton;
 
-class ctkExampleDicomAppLogic : public QObject, public ctkDicomAbstractApp
+class ctkExampleDicomAppLogic : public ctkDicomAbstractApp
 {
   Q_OBJECT
   Q_INTERFACES(ctkDicomAppInterface)
@@ -48,14 +48,14 @@ public:
   virtual bool bringToFront(const QRect& requestedScreenArea);
 
   // ctkDicomExchangeInterface
-  virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
+  virtual bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData);
 
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-    QList<QUuid> objectUUIDs, 
-    QList<QString> acceptableTransferSyntaxUIDs, 
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
     bool includeBulkData);
 
-  virtual void releaseData(QList<QUuid> objectUUIDs);
+  virtual void releaseData(const QList<QUuid>& objectUUIDs);
 
   // some logic
   void do_something();
@@ -69,13 +69,7 @@ protected slots:
   void changeState(int);
 
   void buttonClicked();
-
 private:
-
-  ctkDicomHostInterface* getHostInterface() const;
-
-  ctkServiceTracker<ctkDicomHostInterface*> HostTracker;
-
   QPushButton * Button;
 
   QUuid uuid;

+ 1 - 0
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppPlugin.cpp

@@ -41,6 +41,7 @@ ctkExampleDicomAppPlugin::~ctkExampleDicomAppPlugin()
 {
   qDebug()<< "delete applogic";
   delete this->AppLogic;
+  this->AppLogic = 0;
 }
 
 //----------------------------------------------------------------------------

+ 4 - 4
Plugins/org.commontk.dah.examplehost/ctkExampleDicomHost.cpp

@@ -108,7 +108,7 @@ void ctkExampleDicomHost::forwardConsoleOutput()
 }
 
 //----------------------------------------------------------------------------
-bool ctkExampleDicomHost::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
+bool ctkExampleDicomHost::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
 {
   Q_UNUSED(data)
   Q_UNUSED(lastData)
@@ -117,8 +117,8 @@ bool ctkExampleDicomHost::notifyDataAvailable(ctkDicomAppHosting::AvailableData
 
 //----------------------------------------------------------------------------
 QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomHost::getData(
-    QList<QUuid> objectUUIDs,
-    QList<QString> acceptableTransferSyntaxUIDs,
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
     bool includeBulkData)
 {
   Q_UNUSED(includeBulkData)
@@ -150,7 +150,7 @@ QList<ctkDicomAppHosting::ObjectLocator> ctkExampleDicomHost::getData(
 }
 
 //----------------------------------------------------------------------------
-void ctkExampleDicomHost::releaseData(QList<QUuid> objectUUIDs)
+void ctkExampleDicomHost::releaseData(const QList<QUuid>& objectUUIDs)
 {
   Q_UNUSED(objectUUIDs)
 }

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

@@ -48,12 +48,12 @@ public:
   virtual void notifyStateChanged(ctkDicomAppHosting::State state);
   virtual void notifyStatus(const ctkDicomAppHosting::Status& status);
   // exchange methods
-  virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
+  virtual bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData);
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-      QList<QUuid> objectUUIDs,
-      QList<QString> acceptableTransferSyntaxUIDs,
+      const QList<QUuid>& objectUUIDs,
+      const QList<QString>& acceptableTransferSyntaxUIDs,
       bool includeBulkData);
-  virtual void releaseData(QList<QUuid> objectUUIDs);
+  virtual void releaseData(const QList<QUuid>& objectUUIDs);
 
   const QProcess& getAppProcess() const { return this->AppProcess; }
   ctkDicomAppHosting::State getApplicationState()const {return this->ApplicationState;}

+ 4 - 1
Plugins/org.commontk.dah.host/ctkDicomAbstractHost.cpp

@@ -62,7 +62,10 @@ ctkDicomAbstractHostPrivate::ctkDicomAbstractHostPrivate(
 ctkDicomAbstractHostPrivate::~ctkDicomAbstractHostPrivate()
 {
   delete this->Server;
-  delete this->AppService;
+  this->Server = 0;
+  //do not delete AppService, deleted somewhere else before?
+  //delete  this->AppService;
+  //this->AppService = 0;
 }
 
 //----------------------------------------------------------------------------

+ 4 - 4
Plugins/org.commontk.dah.host/ctkDicomAppService.cpp

@@ -63,22 +63,22 @@ bool ctkDicomAppService::bringToFront(const QRect& requestedScreenArea)
 // Exchange methods
 
 //----------------------------------------------------------------------------
-bool ctkDicomAppService::notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData)
+bool ctkDicomAppService::notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData)
 {
   return ctkDicomExchangeService::notifyDataAvailable(data, lastData);
 }
 
 //----------------------------------------------------------------------------
 QList<ctkDicomAppHosting::ObjectLocator> ctkDicomAppService::getData(
-  QList<QUuid> objectUUIDs, 
-  QList<QString> acceptableTransferSyntaxUIDs, 
+  const QList<QUuid>& objectUUIDs,
+  const QList<QString>& acceptableTransferSyntaxUIDs,
   bool includeBulkData)
 {
   return ctkDicomExchangeService::getData(objectUUIDs, acceptableTransferSyntaxUIDs, includeBulkData);
 }
 
 //----------------------------------------------------------------------------
-void ctkDicomAppService::releaseData(QList<QUuid> objectUUIDs)
+void ctkDicomAppService::releaseData(const QList<QUuid>& objectUUIDs)
 {
   ctkDicomExchangeService::releaseData(objectUUIDs);
 }

+ 4 - 4
Plugins/org.commontk.dah.host/ctkDicomAppService.h

@@ -38,14 +38,14 @@ public:
   virtual bool bringToFront(const QRect& requestedScreenArea);
 
   // Exchange methods implemented in ctkDicomExchangeService
-  virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
+  virtual bool notifyDataAvailable(const ctkDicomAppHosting::AvailableData& data, bool lastData);
 
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-    QList<QUuid> objectUUIDs, 
-    QList<QString> acceptableTransferSyntaxUIDs, 
+    const QList<QUuid>& objectUUIDs,
+    const QList<QString>& acceptableTransferSyntaxUIDs,
     bool includeBulkData);
 
-  virtual void releaseData(QList<QUuid> objectUUIDs);
+  virtual void releaseData(const QList<QUuid>& objectUUIDs);
 
 };