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