diff Framework/Widgets/WidgetBase.cpp @ 46:766d31dc5716 wasm

removing threads for wasm
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Apr 2017 14:33:06 +0200
parents 7207a407bcd8
children 25befef48c35
line wrap: on
line diff
--- a/Framework/Widgets/WidgetBase.cpp	Wed Apr 19 10:28:08 2017 +0200
+++ b/Framework/Widgets/WidgetBase.cpp	Wed Apr 19 14:33:06 2017 +0200
@@ -92,15 +92,6 @@
   }
 
 
-  void WidgetBase::WorkerThread(WidgetBase* that)
-  {
-    while (that->started_)
-    {
-      that->UpdateStep();
-    }
-  }
-
-
   WidgetBase::WidgetBase() :
     statusBar_(NULL),
     started_(false),
@@ -133,12 +124,22 @@
 
   void WidgetBase::Register(IChangeObserver& observer)
   {
+    if (started_)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+
     observers_.Register(observer);
   }
 
 
   void WidgetBase::Unregister(IChangeObserver& observer)
   {
+    if (started_)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+
     observers_.Unregister(observer);
   }
 
@@ -147,39 +148,35 @@
   {
     if (started_)
     {
-      LOG(ERROR) << "Cannot Start() twice";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
-
-    started_ = true;
-
-    if (HasUpdateThread())
+    else
     {
-      thread_ = boost::thread(WorkerThread, this);
+      started_ = true;
     }
   }
 
+  
+  void WidgetBase::Stop()
+  {
+    if (started_)
+    {
+      started_ = false;
+    }
+    else
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
+    }
+  }
 
-  void WidgetBase::Stop()
+  
+  bool WidgetBase::Render(Orthanc::ImageAccessor& surface)
   {
     if (!started_)
     {
-      LOG(ERROR) << "Cannot Stop() if Start() has not been invoked";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
-
-    started_ = false;
-
-    if (HasUpdateThread() &&
-        thread_.joinable())
-    {
-      thread_.join();
-    }
-  }
-
-
-  bool WidgetBase::Render(Orthanc::ImageAccessor& surface)
-  {
+    
 #if 0
     ClearBackgroundOrthanc(surface);
 #else
@@ -188,4 +185,10 @@
 
     return true;
   }
+
+  
+  void WidgetBase::UpdateContent()
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+  }
 }