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