222
|
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 "BasicSdlApplicationContext.h"
|
|
23
|
|
24 namespace OrthancStone
|
|
25 {
|
|
26 IWidget& BasicSdlApplicationContext::SetCentralWidget(IWidget* widget) // Takes ownership
|
|
27 {
|
233
|
28 centralViewport_->SetCentralWidget(widget);
|
222
|
29 return *widget;
|
|
30 }
|
|
31
|
|
32
|
|
33 void BasicSdlApplicationContext::UpdateThread(BasicSdlApplicationContext* that)
|
|
34 {
|
|
35 while (!that->stopped_)
|
|
36 {
|
|
37 {
|
|
38 ViewportLocker locker(*that);
|
|
39 locker.GetViewport().UpdateContent();
|
|
40 }
|
|
41
|
|
42 boost::this_thread::sleep(boost::posix_time::milliseconds(that->updateDelay_));
|
|
43 }
|
|
44 }
|
|
45
|
|
46
|
242
|
47 BasicSdlApplicationContext::BasicSdlApplicationContext(OracleWebService& webService) : // Orthanc::WebServiceParameters& orthanc, WidgetViewport* centralViewport) :
|
|
48 BasicApplicationContext(webService),
|
|
49 oracleWebService_(&webService),
|
|
50 // oracle_(viewportMutex_, 4), // Use 4 threads to download
|
|
51 // webService_(oracle_, orthanc),
|
|
52 // centralViewport_(centralViewport),
|
|
53 centralViewport_(new OrthancStone::WidgetViewport()),
|
222
|
54 stopped_(true),
|
|
55 updateDelay_(100) // By default, 100ms between each refresh of the content
|
|
56 {
|
|
57 srand(time(NULL));
|
|
58 }
|
|
59
|
|
60
|
|
61 void BasicSdlApplicationContext::Start()
|
|
62 {
|
242
|
63 oracleWebService_->Start();
|
222
|
64
|
233
|
65 if (centralViewport_->HasUpdateContent())
|
222
|
66 {
|
|
67 stopped_ = false;
|
|
68 updateThread_ = boost::thread(UpdateThread, this);
|
|
69 }
|
|
70 }
|
|
71
|
|
72
|
|
73 void BasicSdlApplicationContext::Stop()
|
|
74 {
|
|
75 stopped_ = true;
|
|
76
|
|
77 if (updateThread_.joinable())
|
|
78 {
|
|
79 updateThread_.join();
|
|
80 }
|
|
81
|
242
|
82 oracleWebService_->Stop();
|
222
|
83 }
|
|
84 }
|