소스 검색

Started state machine in app + moved up getHostInterface

Benoit Bleuze 14 년 전
부모
커밋
f7516c2e0c

+ 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)

+ 4 - 9
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);
@@ -189,12 +189,7 @@ void ctkExampleDicomAppLogic::releaseData(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()
 {

+ 3 - 9
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)
@@ -51,8 +51,8 @@ public:
   virtual bool notifyDataAvailable(ctkDicomAppHosting::AvailableData data, bool lastData);
 
   virtual QList<ctkDicomAppHosting::ObjectLocator> getData(
-    QList<QUuid> objectUUIDs, 
-    QList<QString> acceptableTransferSyntaxUIDs, 
+    QList<QUuid> objectUUIDs,
+    QList<QString> acceptableTransferSyntaxUIDs,
     bool includeBulkData);
 
   virtual void releaseData(QList<QUuid> objectUUIDs);
@@ -69,13 +69,7 @@ protected slots:
   void changeState(int);
 
   void buttonClicked();
-
 private:
-
-  ctkDicomHostInterface* getHostInterface() const;
-
-  ctkServiceTracker<ctkDicomHostInterface*> HostTracker;
-
   QPushButton * Button;
 
   QUuid uuid;