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