|
@@ -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;
|
|
|
+}
|
|
|
+
|
|
|
+
|