annotate Applications/Generic/NativeStoneApplicationRunner.cpp @ 967:e3234630df9c toa2019082801

Removed pragma-no-cache header that seems to be useless (and even nefarious)
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 28 Aug 2019 10:54:15 +0200
parents 4fe4b221a31f
children b537002f83a9 2d8ab34c8c91
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
748
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
22 #if ORTHANC_ENABLE_THREADS != 1
ab236bb5dbc7 ThreadedOracle
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 726
diff changeset
23 #error this file shall be included only with the ORTHANC_ENABLE_THREADS set to 1
285
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
792
4fe4b221a31f deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
28 #include "../../Framework/Deprecated/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 {
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 659
diff changeset
46 class LogStatusBar : public Deprecated::IStatusBar
285
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")
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
84 ("orthanc", boost::program_options::value<std::string>()->
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
85 default_value("http://localhost:8042/"),
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
86 "URL to the Orthanc server")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
87 ("username", "Username for the Orthanc server")
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
88 ("password", "Password for the Orthanc server")
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
89 ("https-verify", boost::program_options::value<bool>()->
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
90 default_value(true), "Check HTTPS certificates")
285
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 options.add(generic);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
94 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
95
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
96 // platform specific options
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
97 DeclareCommandLineOptions(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 // application specific options
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
100 application_.DeclareStartupOptions(options);
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::variables_map parameters;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
103 bool error = false;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
104
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
105 try
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
106 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
107 boost::program_options::store(
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
108 boost::program_options::command_line_parser(argc, argv).
658
63982c8c294a merge am-dev -> default
Alain Mazy <alain@mazy.be>
parents: 604 657
diff changeset
109 options(options).allow_unregistered().run(), parameters);
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
110 boost::program_options::notify(parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
111 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
112 catch (boost::program_options::error& e)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
113 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
114 LOG(ERROR) <<
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
115 "Error while parsing the command-line arguments: " << e.what();
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
116 error = true;
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
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
120 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
121 * Configure the application with the command-line parameters
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
122 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
123
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
124 if (error || parameters.count("help"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
125 {
659
68b5688241d5 Fixed broken previous merge
Benjamin Golinvaux <bgo@osimis.io>
parents: 658
diff changeset
126 std::cout << std::endl;
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
127
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
128 std::cout << options << "\n";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
129 return error ? -1 : 0;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
130 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
131
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
132 if (parameters.count("https-verify") &&
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
133 !parameters["https-verify"].as<bool>())
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
134 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
135 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
136 Orthanc::HttpClient::ConfigureSsl(false, "");
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
137 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
138
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
139 LOG(ERROR) << "???????? if (parameters.count(\"verbose\"))";
285
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 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
142 LOG(ERROR) << "parameters.count(\"verbose\") != 0";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
143 Orthanc::Logging::EnableInfoLevel(true);
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
144 LOG(INFO) << "Verbose logs are enabled";
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
145 }
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
146
604
86dfde451f4c Fixed typo + added flags for MSVC in Stone Sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 603
diff changeset
147 LOG(ERROR) << "???????? if (parameters.count(\"trace\"))";
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
148 if (parameters.count("trace"))
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
149 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
150 LOG(ERROR) << "parameters.count(\"trace\") != 0";
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
151 Orthanc::Logging::EnableTraceLevel(true);
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
152 VLOG(1) << "Trace logs are enabled";
285
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 ParseCommandLineOptions(parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
156
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
157 bool success = true;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
158 try
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
159 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
160 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
161 * Initialize the connection to the Orthanc server
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
162 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
163
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
164 Orthanc::WebServiceParameters webServiceParameters;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
165
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
166 if (parameters.count("orthanc"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
167 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
168 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>());
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
169 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
170
296
am@osimis.io
parents: 291
diff changeset
171 if (parameters.count("username") && parameters.count("password"))
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
172 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
173 webServiceParameters.SetCredentials(parameters["username"].
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
174 as<std::string>(),
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
175 parameters["password"].as<std::string>());
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
176 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
177
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
178 LOG(WARNING) << "URL to the Orthanc REST API: " <<
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
179 webServiceParameters.GetUrl();
285
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 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters);
792
4fe4b221a31f deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 748
diff changeset
183 if (!Deprecated::MessagingToolbox::CheckOrthancVersion(orthanc))
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
184 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
185 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of "
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
186 << "Orthanc, please upgrade";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
187 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
188 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
189 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
190
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
191
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
192 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
193 * Initialize the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
194 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
195
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
196 LOG(WARNING) << "Creating the widgets of the application";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
197
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
198 LogStatusBar statusBar;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
199
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
200 NativeStoneApplicationContext context(broker_);
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
201
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
202 {
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
203 // use multiple threads to execute asynchronous tasks like
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
204 // download content
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 659
diff changeset
205 Deprecated::Oracle oracle(6);
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
206 oracle.Start();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
207
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
208 {
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 659
diff changeset
209 Deprecated::OracleWebService webService(
603
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
210 broker_, oracle, webServiceParameters, context);
70992b38aa8a new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
Benjamin Golinvaux <bgo@osimis.io>
parents: 541
diff changeset
211
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
212 context.SetWebService(webService);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
213 context.SetOrthancBaseUrl(webServiceParameters.GetUrl());
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
214
726
4f2416d519b4 moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 659
diff changeset
215 Deprecated::OracleDelayedCallExecutor delayedExecutor(broker_, oracle, context);
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
216 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
217
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
218 application_.Initialize(&context, statusBar, parameters);
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 NativeStoneApplicationContext::GlobalMutexLocker locker(context);
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
222 locker.SetCentralWidget(application_.GetCentralWidget());
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
223 locker.GetCentralViewport().SetStatusBar(statusBar);
377
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
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
226 std::string title = application_.GetTitle();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
227 if (title.empty())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
228 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
229 title = "Stone of Orthanc";
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
230 }
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
231
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
232 /****************************************************************
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
233 * Run the application
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
234 ****************************************************************/
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
235
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
236 Run(context, title, argc, argv);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
237
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
238 /****************************************************************
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
239 * Finalize the application
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
240 ****************************************************************/
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
241
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
242 oracle.Stop();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
243 }
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
244 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
245
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
246 LOG(WARNING) << "The application is stopping";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
247 application_.Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
248 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
249 catch (Orthanc::OrthancException& e)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
250 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
251 LOG(ERROR) << "EXCEPTION: " << e.What();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
252 success = false;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
253 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
254
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
255
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
256 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
257 * Finalize all the subcomponents of Orthanc Stone
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
258 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
259
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
260 Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
261 Orthanc::HttpClient::GlobalFinalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
262 Orthanc::Toolbox::FinalizeOpenSsl();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
263
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
264 return (success ? 0 : -1);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
265 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
266 }