changeset 1235:e71ee3e88448 broker

WebGLViewportsRegistry in milliseconds, and Clear()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Dec 2019 20:25:22 +0100
parents e99e09143c64
children 358461330978
files Framework/Viewport/WebGLViewportsRegistry.cpp Framework/Viewport/WebGLViewportsRegistry.h
diffstat 2 files changed, 28 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Viewport/WebGLViewportsRegistry.cpp	Mon Dec 09 17:48:54 2019 +0100
+++ b/Framework/Viewport/WebGLViewportsRegistry.cpp	Mon Dec 09 20:25:22 2019 +0100
@@ -27,7 +27,7 @@
 {
   void WebGLViewportsRegistry::LaunchTimer()
   {
-    emscripten_set_timeout(OnTimeoutCallback, 1000.0 * static_cast<double>(timeoutSeconds_), this);
+    emscripten_set_timeout(OnTimeoutCallback, timeoutMS_, this);
   }
 
   
@@ -88,30 +88,18 @@
   }
 
     
-  WebGLViewportsRegistry::WebGLViewportsRegistry(unsigned int timeoutSeconds) :
-    timeoutSeconds_(timeoutSeconds)
+  WebGLViewportsRegistry::WebGLViewportsRegistry(double timeoutMS) :
+    timeoutMS_(timeoutMS)
   {
-    if (timeoutSeconds <= 0)
+    if (timeoutMS <= 0)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
     }          
-
+    
     LaunchTimer();
   }
 
-    
-  WebGLViewportsRegistry::~WebGLViewportsRegistry()
-  {
-    for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it)
-    {
-      if (it->second != NULL)
-      {
-        delete it->second;
-      }
-    }
-  }
 
-    
   void WebGLViewportsRegistry::Add(const std::string& canvasId)
   {
     if (viewports_.find(canvasId) != viewports_.end())
@@ -146,6 +134,20 @@
   }
 
     
+  void WebGLViewportsRegistry::Clear()
+  {
+    for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it)
+    {
+      if (it->second != NULL)
+      {
+        delete it->second;
+      }
+    }
+
+    viewports_.clear();
+  }
+
+
   WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that,
                                              const std::string& canvasId) :
     that_(that)
--- a/Framework/Viewport/WebGLViewportsRegistry.h	Mon Dec 09 17:48:54 2019 +0100
+++ b/Framework/Viewport/WebGLViewportsRegistry.h	Mon Dec 09 20:25:22 2019 +0100
@@ -38,8 +38,8 @@
   private:
     typedef std::map<std::string, WebGLViewport*>  Viewports;
 
-    unsigned int  timeoutSeconds_;
-    Viewports     viewports_;
+    double     timeoutMS_;
+    Viewports  viewports_;
 
     void LaunchTimer();
 
@@ -48,14 +48,19 @@
     static void OnTimeoutCallback(void *userData);
     
   public:
-    WebGLViewportsRegistry(unsigned int timeoutSeconds);
+    WebGLViewportsRegistry(double timeoutMS /* in milliseconds */);
     
-    ~WebGLViewportsRegistry();
+    ~WebGLViewportsRegistry()
+    {
+      Clear();
+    }
 
     void Add(const std::string& canvasId);
 
     void Remove(const std::string& canvasId);
 
+    void Clear();
+
     class Accessor : public boost::noncopyable
     {
     private: