Mercurial > hg > orthanc-stone
comparison 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 |
comparison
equal
deleted
inserted
replaced
45:ecd96e563929 | 46:766d31dc5716 |
---|---|
90 statusBar_->SetMessage(message); | 90 statusBar_->SetMessage(message); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 void WidgetBase::WorkerThread(WidgetBase* that) | |
96 { | |
97 while (that->started_) | |
98 { | |
99 that->UpdateStep(); | |
100 } | |
101 } | |
102 | |
103 | |
104 WidgetBase::WidgetBase() : | 95 WidgetBase::WidgetBase() : |
105 statusBar_(NULL), | 96 statusBar_(NULL), |
106 started_(false), | 97 started_(false), |
107 backgroundCleared_(false) | 98 backgroundCleared_(false) |
108 { | 99 { |
131 } | 122 } |
132 | 123 |
133 | 124 |
134 void WidgetBase::Register(IChangeObserver& observer) | 125 void WidgetBase::Register(IChangeObserver& observer) |
135 { | 126 { |
127 if (started_) | |
128 { | |
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
130 } | |
131 | |
136 observers_.Register(observer); | 132 observers_.Register(observer); |
137 } | 133 } |
138 | 134 |
139 | 135 |
140 void WidgetBase::Unregister(IChangeObserver& observer) | 136 void WidgetBase::Unregister(IChangeObserver& observer) |
141 { | 137 { |
138 if (started_) | |
139 { | |
140 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
141 } | |
142 | |
142 observers_.Unregister(observer); | 143 observers_.Unregister(observer); |
143 } | 144 } |
144 | 145 |
145 | 146 |
146 void WidgetBase::Start() | 147 void WidgetBase::Start() |
147 { | 148 { |
148 if (started_) | 149 if (started_) |
149 { | 150 { |
150 LOG(ERROR) << "Cannot Start() twice"; | |
151 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 151 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
152 } | 152 } |
153 | 153 else |
154 started_ = true; | |
155 | |
156 if (HasUpdateThread()) | |
157 { | 154 { |
158 thread_ = boost::thread(WorkerThread, this); | 155 started_ = true; |
159 } | 156 } |
160 } | 157 } |
161 | 158 |
159 | |
160 void WidgetBase::Stop() | |
161 { | |
162 if (started_) | |
163 { | |
164 started_ = false; | |
165 } | |
166 else | |
167 { | |
168 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
169 } | |
170 } | |
162 | 171 |
163 void WidgetBase::Stop() | 172 |
173 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) | |
164 { | 174 { |
165 if (!started_) | 175 if (!started_) |
166 { | 176 { |
167 LOG(ERROR) << "Cannot Stop() if Start() has not been invoked"; | |
168 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 177 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
169 } | 178 } |
170 | 179 |
171 started_ = false; | |
172 | |
173 if (HasUpdateThread() && | |
174 thread_.joinable()) | |
175 { | |
176 thread_.join(); | |
177 } | |
178 } | |
179 | |
180 | |
181 bool WidgetBase::Render(Orthanc::ImageAccessor& surface) | |
182 { | |
183 #if 0 | 180 #if 0 |
184 ClearBackgroundOrthanc(surface); | 181 ClearBackgroundOrthanc(surface); |
185 #else | 182 #else |
186 ClearBackgroundCairo(surface); // Faster than Orthanc | 183 ClearBackgroundCairo(surface); // Faster than Orthanc |
187 #endif | 184 #endif |
188 | 185 |
189 return true; | 186 return true; |
190 } | 187 } |
188 | |
189 | |
190 void WidgetBase::UpdateContent() | |
191 { | |
192 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
193 } | |
191 } | 194 } |