Mercurial > hg > orthanc-stone
comparison Applications/BasicApplicationContext.cpp @ 222:84844649a8fd am
continued: reusable applications
author | am@osimis.io |
---|---|
date | Tue, 12 Jun 2018 17:21:15 +0200 |
parents | d7b2590744f8 |
children |
comparison
equal
deleted
inserted
replaced
221:d7b2590744f8 | 222:84844649a8fd |
---|---|
21 | 21 |
22 #include "BasicApplicationContext.h" | 22 #include "BasicApplicationContext.h" |
23 | 23 |
24 namespace OrthancStone | 24 namespace OrthancStone |
25 { | 25 { |
26 void BasicApplicationContext::UpdateThread(BasicApplicationContext* that) | |
27 { | |
28 while (!that->stopped_) | |
29 { | |
30 { | |
31 ViewportLocker locker(*that); | |
32 locker.GetViewport().UpdateContent(); | |
33 } | |
34 | |
35 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelay_)); | |
36 } | |
37 } | |
38 | |
39 | |
40 BasicApplicationContext::BasicApplicationContext(Orthanc::WebServiceParameters& orthanc) : | |
41 oracle_(viewportMutex_, 4), // Use 4 threads to download | |
42 //oracle_(viewportMutex_, 1), // Disable threading to be reproducible | |
43 webService_(oracle_, orthanc), | |
44 stopped_(true), | |
45 updateDelay_(100) // By default, 100ms between each refresh of the content | |
46 { | |
47 srand(time(NULL)); | |
48 } | |
49 | |
50 | |
51 IWidget& BasicApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership | |
52 { | |
53 centralViewport_.SetCentralWidget(widget); | |
54 return *widget; | |
55 } | |
56 | |
57 | |
58 void BasicApplicationContext::Start() | |
59 { | |
60 oracle_.Start(); | |
61 | |
62 if (centralViewport_.HasUpdateContent()) | |
63 { | |
64 stopped_ = false; | |
65 updateThread_ = boost::thread(UpdateThread, this); | |
66 } | |
67 } | |
68 | |
69 | |
70 void BasicApplicationContext::Stop() | |
71 { | |
72 stopped_ = true; | |
73 | |
74 if (updateThread_.joinable()) | |
75 { | |
76 updateThread_.join(); | |
77 } | |
78 | |
79 oracle_.Stop(); | |
80 } | |
81 } | 26 } |