comparison Applications/Generic/BasicNativeApplicationContext.cpp @ 274:dc1beee33134 am-2

split SdlApplication into NativeApplication and SdlApplication
author am@osimis.io
date Fri, 24 Aug 2018 13:52:55 +0200
parents
children a38465cc909f
comparison
equal deleted inserted replaced
273:f21ba2468570 274:dc1beee33134
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 "BasicNativeApplicationContext.h"
23 #include "../../Platforms/Generic/OracleWebService.h"
24
25 namespace OrthancStone
26 {
27 IWidget& BasicNativeApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership
28 {
29 centralViewport_->SetCentralWidget(widget);
30 return *widget;
31 }
32
33
34 void BasicNativeApplicationContext::UpdateThread(BasicNativeApplicationContext* 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->updateDelay_));
44 }
45 }
46
47
48 BasicNativeApplicationContext::BasicNativeApplicationContext() : // Orthanc::WebServiceParameters& orthanc, WidgetViewport* centralViewport) :
49 centralViewport_(new OrthancStone::WidgetViewport()),
50 stopped_(true),
51 updateDelay_(100) // By default, 100ms between each refresh of the content
52 {
53 srand(time(NULL));
54 }
55
56
57 void BasicNativeApplicationContext::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 BasicNativeApplicationContext::Stop()
70 {
71 stopped_ = true;
72
73 if (updateThread_.joinable())
74 {
75 updateThread_.join();
76 }
77
78 dynamic_cast<OracleWebService*>(webService_)->Stop();
79 }
80 }