comparison Applications/Generic/NativeStoneApplicationContext.cpp @ 291:87376a645ee1 am-2

renaming
author am@osimis.io
date Thu, 30 Aug 2018 17:06:22 +0200
parents Applications/Generic/BasicNativeApplicationContext.cpp@a38465cc909f
children 8eb4fe74000f
comparison
equal deleted inserted replaced
289:36ebe6ec8fe8 291:87376a645ee1
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "NativeStoneApplicationContext.h"
23 #include "../../Platforms/Generic/OracleWebService.h"
24
25 namespace OrthancStone
26 {
27 IWidget& NativeStoneApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership
28 {
29 centralViewport_->SetCentralWidget(widget);
30 return *widget;
31 }
32
33
34 void NativeStoneApplicationContext::UpdateThread(NativeStoneApplicationContext* that)
35 {
36 while (!that->stopped_)
37 {
38 {
39 GlobalMutexLocker locker(*that);
40 that->GetCentralViewport().UpdateContent();
41 }
42
43 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelayInMs_));
44 }
45 }
46
47
48 NativeStoneApplicationContext::NativeStoneApplicationContext() :
49 centralViewport_(new OrthancStone::WidgetViewport()),
50 stopped_(true),
51 updateDelayInMs_(100) // By default, 100ms between each refresh of the content
52 {
53 srand(time(NULL));
54 }
55
56
57 void NativeStoneApplicationContext::Start()
58 {
59 dynamic_cast<OracleWebService*>(webService_)->Start();
60
61 if (centralViewport_->HasUpdateContent())
62 {
63 stopped_ = false;
64 updateThread_ = boost::thread(UpdateThread, this);
65 }
66 }
67
68
69 void NativeStoneApplicationContext::Stop()
70 {
71 stopped_ = true;
72
73 if (updateThread_.joinable())
74 {
75 updateThread_.join();
76 }
77
78 dynamic_cast<OracleWebService*>(webService_)->Stop();
79 }
80 }