annotate Applications/Generic/NativeStoneApplicationRunner.cpp @ 339:5a7915b23138 am-2

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 19 Oct 2018 14:44:12 +0200
parents ac9fd144feae
children 8eb4fe74000f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
1 /**
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
6 *
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
11 *
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
16 *
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
19 **/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
20
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
21
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
22 #if ORTHANC_ENABLE_NATIVE != 1
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
23 #error this file shall be included only with the ORTHANC_ENABLE_NATIVE set to 1
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
24 #endif
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
25
291
87376a645ee1 renaming
am@osimis.io
parents: 285
diff changeset
26 #include "NativeStoneApplicationRunner.h"
87376a645ee1 renaming
am@osimis.io
parents: 285
diff changeset
27 #include "NativeStoneApplicationContext.h"
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
28 #include <boost/program_options.hpp>
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
29
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
30 #include "../../Framework/Toolbox/MessagingToolbox.h"
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
31
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
32 #include <Core/Logging.h>
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
33 #include <Core/HttpClient.h>
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
34 #include <Core/Toolbox.h>
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
35 #include <Plugins/Samples/Common/OrthancHttpConnection.h>
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
36 #include "../../Platforms/Generic/OracleWebService.h"
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
37
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
38 namespace OrthancStone
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
39 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
40 // Anonymous namespace to avoid clashes against other compilation modules
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
41 namespace
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
42 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
43 class LogStatusBar : public IStatusBar
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
44 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
45 public:
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
46 virtual void ClearMessage()
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
47 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
48 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
49
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
50 virtual void SetMessage(const std::string& message)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
51 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
52 LOG(WARNING) << message;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
53 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
54 };
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
55 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
56
291
87376a645ee1 renaming
am@osimis.io
parents: 285
diff changeset
57 int NativeStoneApplicationRunner::Execute(int argc,
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
58 char* argv[])
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
59 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
60 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
61 * Initialize all the subcomponents of Orthanc Stone
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
62 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
63
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
64 Orthanc::Logging::Initialize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
65 Orthanc::Toolbox::InitializeOpenSsl();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
66 Orthanc::HttpClient::GlobalInitialize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
67
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
68 Initialize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
69
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
70 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
71 * Declare and parse the command-line options of the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
72 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
73
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
74 boost::program_options::options_description options;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
75
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
76 { // generic options
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
77 boost::program_options::options_description generic("Generic options");
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
78 generic.add_options()
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
79 ("help", "Display this help and exit")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
80 ("verbose", "Be verbose in logs")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
81 ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"),
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
82 "URL to the Orthanc server")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
83 ("username", "Username for the Orthanc server")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
84 ("password", "Password for the Orthanc server")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
85 ("https-verify", boost::program_options::value<bool>()->default_value(true), "Check HTTPS certificates")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
86 ;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
87
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
88 options.add(generic);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
89 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
90
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
91 // platform specific options
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
92 DeclareCommandLineOptions(options);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
93
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
94 // application specific options
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
95 application_.DeclareStartupOptions(options);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
96
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
97 boost::program_options::variables_map parameters;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
98 bool error = false;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
99
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
100 try
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
101 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
102 boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
103 options(options).run(), parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
104 boost::program_options::notify(parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
105 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
106 catch (boost::program_options::error& e)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
107 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
108 LOG(ERROR) << "Error while parsing the command-line arguments: " << e.what();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
109 error = true;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
110 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
111
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
112
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
113 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
114 * Configure the application with the command-line parameters
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
115 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
116
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
117 if (error || parameters.count("help"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
118 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
119 std::cout << std::endl
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
120 << "Usage: " << argv[0] << " [OPTION]..."
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
121 << std::endl
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
122 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research."
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
123 << std::endl << std::endl
296
am@osimis.io
parents: 291
diff changeset
124 << "Demonstration application of Orthanc Stone in native environment."
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
125 << std::endl;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
126
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
127 std::cout << options << "\n";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
128 return error ? -1 : 0;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
129 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
130
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
131 if (parameters.count("https-verify") &&
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
132 !parameters["https-verify"].as<bool>())
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
133 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
134 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
135 Orthanc::HttpClient::ConfigureSsl(false, "");
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
136 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
137
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
138 if (parameters.count("verbose"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
139 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
140 Orthanc::Logging::EnableInfoLevel(true);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
141 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
142
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
143 ParseCommandLineOptions(parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
144
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
145
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
146 bool success = true;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
147 try
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
148 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
149 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
150 * Initialize the connection to the Orthanc server
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
151 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
152
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
153 Orthanc::WebServiceParameters webServiceParameters;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
154
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
155 if (parameters.count("orthanc"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
156 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
157 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>());
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
158 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
159
296
am@osimis.io
parents: 291
diff changeset
160 if (parameters.count("username") && parameters.count("password"))
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
161 {
296
am@osimis.io
parents: 291
diff changeset
162 webServiceParameters.SetCredentials(parameters["username"].as<std::string>(),
am@osimis.io
parents: 291
diff changeset
163 parameters["password"].as<std::string>());
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
164 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
165
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
166 LOG(WARNING) << "URL to the Orthanc REST API: " << webServiceParameters.GetUrl();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
167
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
168 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
169 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
170 if (!MessagingToolbox::CheckOrthancVersion(orthanc))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
171 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
172 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of Orthanc, please upgrade";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
173 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
174 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
175 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
176
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
177
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
178 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
179 * Initialize the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
180 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
181
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
182 LOG(WARNING) << "Creating the widgets of the application";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
183
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
184 LogStatusBar statusBar;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
185
291
87376a645ee1 renaming
am@osimis.io
parents: 285
diff changeset
186 NativeStoneApplicationContext context;
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
187 Oracle oracle(4); // use 4 threads to download content
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
188 OracleWebService webService(broker_, oracle, webServiceParameters, context);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
189 context.SetWebService(webService);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
190
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
191 application_.Initialize(&context, statusBar, parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
192
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
193 {
291
87376a645ee1 renaming
am@osimis.io
parents: 285
diff changeset
194 NativeStoneApplicationContext::GlobalMutexLocker locker(context);
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
195 context.SetCentralWidget(application_.GetCentralWidget());
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
196 context.GetCentralViewport().SetStatusBar(statusBar);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
197 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
198
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
199 std::string title = application_.GetTitle();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
200 if (title.empty())
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
201 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
202 title = "Stone of Orthanc";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
203 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
204
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
205 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
206 * Run the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
207 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
208
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
209 Run(context, title, argc, argv);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
210
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
211 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
212 * Finalize the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
213 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
214
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
215 LOG(WARNING) << "The application is stopping";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
216 application_.Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
217 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
218 catch (Orthanc::OrthancException& e)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
219 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
220 LOG(ERROR) << "EXCEPTION: " << e.What();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
221 success = false;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
222 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
223
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
224
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
225 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
226 * Finalize all the subcomponents of Orthanc Stone
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
227 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
228
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
229 Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
230 Orthanc::HttpClient::GlobalFinalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
231 Orthanc::Toolbox::FinalizeOpenSsl();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
232
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
233 return (success ? 0 : -1);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
234 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
235
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
236 }