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