Mercurial > hg > orthanc-stone
annotate Applications/Generic/NativeStoneApplicationRunner.cpp @ 420:8bf717c4e497
canvas size is now defined by the parent div size
author | am@osimis.io |
---|---|
date | Mon, 19 Nov 2018 12:45:37 +0100 |
parents | c23df8b3433b |
children | 26b90b110719 b70e9be013e4 |
rev | line source |
---|---|
285 | 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 #if ORTHANC_ENABLE_NATIVE != 1 | |
23 #error this file shall be included only with the ORTHANC_ENABLE_NATIVE set to 1 | |
24 #endif | |
25 | |
291 | 26 #include "NativeStoneApplicationRunner.h" |
285 | 27 |
28 #include "../../Framework/Toolbox/MessagingToolbox.h" | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
29 #include "../../Platforms/Generic/OracleWebService.h" |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
30 #include "NativeStoneApplicationContext.h" |
285 | 31 |
32 #include <Core/Logging.h> | |
33 #include <Core/HttpClient.h> | |
34 #include <Core/Toolbox.h> | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
35 #include <Core/OrthancException.h> |
285 | 36 #include <Plugins/Samples/Common/OrthancHttpConnection.h> |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
37 |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
38 #include <boost/program_options.hpp> |
285 | 39 |
40 namespace OrthancStone | |
41 { | |
42 // Anonymous namespace to avoid clashes against other compilation modules | |
43 namespace | |
44 { | |
45 class LogStatusBar : public IStatusBar | |
46 { | |
47 public: | |
48 virtual void ClearMessage() | |
49 { | |
50 } | |
51 | |
52 virtual void SetMessage(const std::string& message) | |
53 { | |
54 LOG(WARNING) << message; | |
55 } | |
56 }; | |
57 } | |
58 | |
291 | 59 int NativeStoneApplicationRunner::Execute(int argc, |
285 | 60 char* argv[]) |
61 { | |
62 /****************************************************************** | |
63 * Initialize all the subcomponents of Orthanc Stone | |
64 ******************************************************************/ | |
65 | |
66 Orthanc::Logging::Initialize(); | |
67 Orthanc::Toolbox::InitializeOpenSsl(); | |
68 Orthanc::HttpClient::GlobalInitialize(); | |
69 | |
70 Initialize(); | |
71 | |
72 /****************************************************************** | |
73 * Declare and parse the command-line options of the application | |
74 ******************************************************************/ | |
75 | |
76 boost::program_options::options_description options; | |
77 | |
78 { // generic options | |
79 boost::program_options::options_description generic("Generic options"); | |
80 generic.add_options() | |
81 ("help", "Display this help and exit") | |
82 ("verbose", "Be verbose in logs") | |
83 ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"), | |
84 "URL to the Orthanc server") | |
85 ("username", "Username for the Orthanc server") | |
86 ("password", "Password for the Orthanc server") | |
87 ("https-verify", boost::program_options::value<bool>()->default_value(true), "Check HTTPS certificates") | |
88 ; | |
89 | |
90 options.add(generic); | |
91 } | |
92 | |
93 // platform specific options | |
94 DeclareCommandLineOptions(options); | |
95 | |
96 // application specific options | |
97 application_.DeclareStartupOptions(options); | |
98 | |
99 boost::program_options::variables_map parameters; | |
100 bool error = false; | |
101 | |
102 try | |
103 { | |
104 boost::program_options::store(boost::program_options::command_line_parser(argc, argv). | |
105 options(options).run(), parameters); | |
106 boost::program_options::notify(parameters); | |
107 } | |
108 catch (boost::program_options::error& e) | |
109 { | |
110 LOG(ERROR) << "Error while parsing the command-line arguments: " << e.what(); | |
111 error = true; | |
112 } | |
113 | |
114 | |
115 /****************************************************************** | |
116 * Configure the application with the command-line parameters | |
117 ******************************************************************/ | |
118 | |
119 if (error || parameters.count("help")) | |
120 { | |
121 std::cout << std::endl | |
122 << "Usage: " << argv[0] << " [OPTION]..." | |
123 << std::endl | |
124 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." | |
125 << std::endl << std::endl | |
296 | 126 << "Demonstration application of Orthanc Stone in native environment." |
285 | 127 << std::endl; |
128 | |
129 std::cout << options << "\n"; | |
130 return error ? -1 : 0; | |
131 } | |
132 | |
133 if (parameters.count("https-verify") && | |
134 !parameters["https-verify"].as<bool>()) | |
135 { | |
136 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)"; | |
137 Orthanc::HttpClient::ConfigureSsl(false, ""); | |
138 } | |
139 | |
140 if (parameters.count("verbose")) | |
141 { | |
142 Orthanc::Logging::EnableInfoLevel(true); | |
143 } | |
144 | |
145 ParseCommandLineOptions(parameters); | |
146 | |
147 | |
148 bool success = true; | |
149 try | |
150 { | |
151 /**************************************************************** | |
152 * Initialize the connection to the Orthanc server | |
153 ****************************************************************/ | |
154 | |
155 Orthanc::WebServiceParameters webServiceParameters; | |
156 | |
157 if (parameters.count("orthanc")) | |
158 { | |
159 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>()); | |
160 } | |
161 | |
296 | 162 if (parameters.count("username") && parameters.count("password")) |
285 | 163 { |
296 | 164 webServiceParameters.SetCredentials(parameters["username"].as<std::string>(), |
165 parameters["password"].as<std::string>()); | |
285 | 166 } |
167 | |
168 LOG(WARNING) << "URL to the Orthanc REST API: " << webServiceParameters.GetUrl(); | |
169 | |
170 { | |
171 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters); | |
172 if (!MessagingToolbox::CheckOrthancVersion(orthanc)) | |
173 { | |
174 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of Orthanc, please upgrade"; | |
175 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); | |
176 } | |
177 } | |
178 | |
179 | |
180 /**************************************************************** | |
181 * Initialize the application | |
182 ****************************************************************/ | |
183 | |
184 LOG(WARNING) << "Creating the widgets of the application"; | |
185 | |
186 LogStatusBar statusBar; | |
187 | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
188 NativeStoneApplicationContext context(broker_); |
285 | 189 |
190 { | |
377 | 191 Oracle oracle(4); // use 4 threads to download content |
192 oracle.Start(); | |
193 | |
194 { | |
195 OracleWebService webService(broker_, oracle, webServiceParameters, context); | |
418 | 196 context.SetWebService(webService); |
197 context.SetOrthancBaseUrl(webServiceParameters.GetUrl()); | |
377 | 198 |
199 application_.Initialize(&context, statusBar, parameters); | |
200 | |
201 { | |
202 NativeStoneApplicationContext::GlobalMutexLocker locker(context); | |
385
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
203 locker.SetCentralWidget(application_.GetCentralWidget()); |
6cc3ce74dc05
using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
204 locker.GetCentralViewport().SetStatusBar(statusBar); |
377 | 205 } |
285 | 206 |
377 | 207 std::string title = application_.GetTitle(); |
208 if (title.empty()) | |
209 { | |
210 title = "Stone of Orthanc"; | |
211 } | |
212 | |
213 /**************************************************************** | |
214 * Run the application | |
215 ****************************************************************/ | |
216 | |
217 Run(context, title, argc, argv); | |
218 | |
219 /**************************************************************** | |
220 * Finalize the application | |
221 ****************************************************************/ | |
222 | |
223 oracle.Stop(); | |
224 } | |
285 | 225 } |
226 | |
227 LOG(WARNING) << "The application is stopping"; | |
228 application_.Finalize(); | |
229 } | |
230 catch (Orthanc::OrthancException& e) | |
231 { | |
232 LOG(ERROR) << "EXCEPTION: " << e.What(); | |
233 success = false; | |
234 } | |
235 | |
236 | |
237 /****************************************************************** | |
238 * Finalize all the subcomponents of Orthanc Stone | |
239 ******************************************************************/ | |
240 | |
241 Finalize(); | |
242 Orthanc::HttpClient::GlobalFinalize(); | |
243 Orthanc::Toolbox::FinalizeOpenSsl(); | |
244 | |
245 return (success ? 0 : -1); | |
246 } | |
247 | |
248 } |