comparison Applications/Generic/NativeStoneApplicationContext.cpp @ 385:6cc3ce74dc05

using message broker in widgets
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 07 Nov 2018 20:49:41 +0100
parents 8eb4fe74000f
children e33659decec5
comparison
equal deleted inserted replaced
384:d20d75f20c5d 385:6cc3ce74dc05
22 #include "NativeStoneApplicationContext.h" 22 #include "NativeStoneApplicationContext.h"
23 #include "../../Platforms/Generic/OracleWebService.h" 23 #include "../../Platforms/Generic/OracleWebService.h"
24 24
25 namespace OrthancStone 25 namespace OrthancStone
26 { 26 {
27 IWidget& NativeStoneApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership 27 IWidget& NativeStoneApplicationContext::GlobalMutexLocker::SetCentralWidget(IWidget* widget)
28 { 28 {
29 centralViewport_->SetCentralWidget(widget); 29 that_.centralViewport_.SetCentralWidget(widget);
30 return *widget; 30 return *widget;
31 } 31 }
32 32
33 33
34 void NativeStoneApplicationContext::UpdateThread(NativeStoneApplicationContext* that) 34 void NativeStoneApplicationContext::UpdateThread(NativeStoneApplicationContext* that)
35 { 35 {
36 while (!that->stopped_) 36 while (!that->stopped_)
37 { 37 {
38 { 38 {
39 GlobalMutexLocker locker(*that); 39 GlobalMutexLocker locker(*that);
40 that->GetCentralViewport().UpdateContent(); 40 locker.GetCentralViewport().UpdateContent();
41 } 41 }
42 42
43 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelayInMs_)); 43 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelayInMs_));
44 } 44 }
45 } 45 }
46 46
47 47
48 NativeStoneApplicationContext::NativeStoneApplicationContext() : 48 NativeStoneApplicationContext::NativeStoneApplicationContext(MessageBroker& broker) :
49 centralViewport_(new OrthancStone::WidgetViewport()), 49 broker_(broker),
50 centralViewport_(broker),
50 stopped_(true), 51 stopped_(true),
51 updateDelayInMs_(100) // By default, 100ms between each refresh of the content 52 updateDelayInMs_(100) // By default, 100ms between each refresh of the content
52 { 53 {
53 srand(time(NULL)); 54 srand(time(NULL));
54 } 55 }
55 56
56 57
57 void NativeStoneApplicationContext::Start() 58 void NativeStoneApplicationContext::Start()
58 { 59 {
59 if (centralViewport_->HasUpdateContent()) 60 boost::mutex::scoped_lock lock(globalMutex_);
61
62 if (stopped_ &&
63 centralViewport_.HasUpdateContent())
60 { 64 {
61 stopped_ = false; 65 stopped_ = false;
62 updateThread_ = boost::thread(UpdateThread, this); 66 updateThread_ = boost::thread(UpdateThread, this);
63 } 67 }
64 } 68 }