comparison Applications/BasicApplicationContext.cpp @ 53:c2dc924f1a63 wasm

removing threading out of the framework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Apr 2017 16:57:49 +0200
parents b340879da9bd
children d20e25cfcf3a
comparison
equal deleted inserted replaced
52:37e504582af6 53:c2dc924f1a63
25 #include "../../Framework/Volumes/VolumeImageSimplePolicy.h" 25 #include "../../Framework/Volumes/VolumeImageSimplePolicy.h"
26 #include "../../Framework/Volumes/VolumeImageProgressivePolicy.h" 26 #include "../../Framework/Volumes/VolumeImageProgressivePolicy.h"
27 27
28 namespace OrthancStone 28 namespace OrthancStone
29 { 29 {
30 void BasicApplicationContext::UpdateThread(BasicApplicationContext* that)
31 {
32 while (!that->stopped_)
33 {
34 {
35 ViewportLocker locker(*that);
36 locker.GetViewport().UpdateContent();
37 }
38
39 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelay_));
40 }
41 }
42
43
30 BasicApplicationContext::BasicApplicationContext(OrthancPlugins::IOrthancConnection& orthanc) : 44 BasicApplicationContext::BasicApplicationContext(OrthancPlugins::IOrthancConnection& orthanc) :
31 orthanc_(orthanc) 45 orthanc_(orthanc),
46 stopped_(true),
47 updateDelay_(100) // By default, 100ms between each refresh of the content
32 { 48 {
33 } 49 }
34 50
35 51
36 BasicApplicationContext::~BasicApplicationContext() 52 BasicApplicationContext::~BasicApplicationContext()
117 assert(*it != NULL); 133 assert(*it != NULL);
118 (*it)->Start(); 134 (*it)->Start();
119 } 135 }
120 136
121 viewport_.Start(); 137 viewport_.Start();
138
139 if (viewport_.HasUpdateContent())
140 {
141 stopped_ = false;
142 updateThread_ = boost::thread(UpdateThread, this);
143 }
122 } 144 }
123 145
124 146
125 void BasicApplicationContext::Stop() 147 void BasicApplicationContext::Stop()
126 { 148 {
149 stopped_ = true;
150
151 if (updateThread_.joinable())
152 {
153 updateThread_.join();
154 }
155
127 viewport_.Stop(); 156 viewport_.Stop();
128 157
129 for (Volumes::iterator it = volumes_.begin(); it != volumes_.end(); ++it) 158 for (Volumes::iterator it = volumes_.begin(); it != volumes_.end(); ++it)
130 { 159 {
131 assert(*it != NULL); 160 assert(*it != NULL);