comparison Framework/Viewport/WebGLViewportsRegistry.cpp @ 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 a28861abf888
children b9b5d4378874
comparison
equal deleted inserted replaced
1234:e99e09143c64 1235:e71ee3e88448
25 25
26 namespace OrthancStone 26 namespace OrthancStone
27 { 27 {
28 void WebGLViewportsRegistry::LaunchTimer() 28 void WebGLViewportsRegistry::LaunchTimer()
29 { 29 {
30 emscripten_set_timeout(OnTimeoutCallback, 1000.0 * static_cast<double>(timeoutSeconds_), this); 30 emscripten_set_timeout(OnTimeoutCallback, timeoutMS_, this);
31 } 31 }
32 32
33 33
34 void WebGLViewportsRegistry::OnTimeout() 34 void WebGLViewportsRegistry::OnTimeout()
35 { 35 {
86 WebGLViewportsRegistry& that = *reinterpret_cast<WebGLViewportsRegistry*>(userData); 86 WebGLViewportsRegistry& that = *reinterpret_cast<WebGLViewportsRegistry*>(userData);
87 that.OnTimeout(); 87 that.OnTimeout();
88 } 88 }
89 89
90 90
91 WebGLViewportsRegistry::WebGLViewportsRegistry(unsigned int timeoutSeconds) : 91 WebGLViewportsRegistry::WebGLViewportsRegistry(double timeoutMS) :
92 timeoutSeconds_(timeoutSeconds) 92 timeoutMS_(timeoutMS)
93 { 93 {
94 if (timeoutSeconds <= 0) 94 if (timeoutMS <= 0)
95 { 95 {
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 96 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
97 } 97 }
98 98
99 LaunchTimer(); 99 LaunchTimer();
100 } 100 }
101 101
102
103 WebGLViewportsRegistry::~WebGLViewportsRegistry()
104 {
105 for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it)
106 {
107 if (it->second != NULL)
108 {
109 delete it->second;
110 }
111 }
112 }
113 102
114
115 void WebGLViewportsRegistry::Add(const std::string& canvasId) 103 void WebGLViewportsRegistry::Add(const std::string& canvasId)
116 { 104 {
117 if (viewports_.find(canvasId) != viewports_.end()) 105 if (viewports_.find(canvasId) != viewports_.end())
118 { 106 {
119 LOG(ERROR) << "Canvas was already registered: " << canvasId; 107 LOG(ERROR) << "Canvas was already registered: " << canvasId;
144 viewports_.erase(found); 132 viewports_.erase(found);
145 } 133 }
146 } 134 }
147 135
148 136
137 void WebGLViewportsRegistry::Clear()
138 {
139 for (Viewports::iterator it = viewports_.begin(); it != viewports_.end(); ++it)
140 {
141 if (it->second != NULL)
142 {
143 delete it->second;
144 }
145 }
146
147 viewports_.clear();
148 }
149
150
149 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that, 151 WebGLViewportsRegistry::Accessor::Accessor(WebGLViewportsRegistry& that,
150 const std::string& canvasId) : 152 const std::string& canvasId) :
151 that_(that) 153 that_(that)
152 { 154 {
153 Viewports::iterator viewport = that.viewports_.find(canvasId); 155 Viewports::iterator viewport = that.viewports_.find(canvasId);