annotate Applications/Generic/NativeStoneApplicationRunner.cpp @ 622:8a3a25f2d42c

uncoupling oracle from context
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 May 2019 12:32:21 +0200
parents 86dfde451f4c
children 63982c8c294a
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")
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).
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
109 options(options).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 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
126 std::cout << std::endl
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
127 << "Usage: " << argv[0] << " [OPTION]..." << std::endl
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
128 << "Orthanc, lightweight, RESTful DICOM server for healthcare "
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
129 << "and medical research." << std::endl << std::endl
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
130 << "Demonstration application of Orthanc Stone in native "
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
131 << "environment." << std::endl;
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
132
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
133 std::cout << options << "\n";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
134 return error ? -1 : 0;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
135 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
136
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
137 if (parameters.count("https-verify") &&
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
138 !parameters["https-verify"].as<bool>())
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
139 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
140 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
141 Orthanc::HttpClient::ConfigureSsl(false, "");
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
142 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
143
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
144 LOG(ERROR) << "???????? if (parameters.count(\"verbose\"))";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
145 if (parameters.count("verbose"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
146 {
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
147 LOG(ERROR) << "parameters.count(\"verbose\") != 0";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
148 Orthanc::Logging::EnableInfoLevel(true);
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
149 LOG(INFO) << "Verbose logs are enabled";
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
150 }
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
151
604
86dfde451f4c Fixed typo + added flags for MSVC in Stone Sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 603
diff changeset
152 LOG(ERROR) << "???????? if (parameters.count(\"trace\"))";
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
153 if (parameters.count("trace"))
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
154 {
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
155 LOG(ERROR) << "parameters.count(\"trace\") != 0";
541
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
156 Orthanc::Logging::EnableTraceLevel(true);
Alain Mazy <alain@mazy.be>
parents: 440
diff changeset
157 VLOG(1) << "Trace logs are enabled";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
158 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
159
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
160 ParseCommandLineOptions(parameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
161
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
162 bool success = true;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
163 try
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
164 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
165 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
166 * Initialize the connection to the Orthanc server
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 Orthanc::WebServiceParameters webServiceParameters;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
170
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
171 if (parameters.count("orthanc"))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
172 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
173 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>());
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
174 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
175
296
am@osimis.io
parents: 291
diff changeset
176 if (parameters.count("username") && parameters.count("password"))
285
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 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
179 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
180 parameters["password"].as<std::string>());
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
181 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
182
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
183 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
184 webServiceParameters.GetUrl();
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
185
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
186 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
187 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
188 if (!MessagingToolbox::CheckOrthancVersion(orthanc))
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
189 {
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
190 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
191 << "Orthanc, please upgrade";
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
192 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
193 }
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
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
197 /****************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
198 * Initialize the application
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
199 ****************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
200
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
201 LOG(WARNING) << "Creating the widgets of the application";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
202
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
203 LogStatusBar statusBar;
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
204
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
205 NativeStoneApplicationContext context(broker_);
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
206
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
207 {
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
208 // 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
209 // download content
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 Oracle oracle(6);
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
211 oracle.Start();
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 {
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
214 OracleWebService webService(
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
215 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
216
418
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
217 context.SetWebService(webService);
c23df8b3433b refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 417
diff changeset
218 context.SetOrthancBaseUrl(webServiceParameters.GetUrl());
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
219
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
220 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
221 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
222
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
223 application_.Initialize(&context, statusBar, parameters);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
224
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 NativeStoneApplicationContext::GlobalMutexLocker locker(context);
385
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
227 locker.SetCentralWidget(application_.GetCentralWidget());
6cc3ce74dc05 using message broker in widgets
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
228 locker.GetCentralViewport().SetStatusBar(statusBar);
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
229 }
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
230
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
231 std::string title = application_.GetTitle();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
232 if (title.empty())
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
233 {
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
234 title = "Stone of Orthanc";
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
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 * Run the application
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
239 ****************************************************************/
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 Run(context, title, argc, argv);
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
242
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
243 /****************************************************************
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
244 * Finalize the application
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
245 ****************************************************************/
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
246
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
247 oracle.Stop();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 296
diff changeset
248 }
285
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
249 }
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(WARNING) << "The application is stopping";
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
252 application_.Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
253 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
254 catch (Orthanc::OrthancException& e)
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
255 {
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
256 LOG(ERROR) << "EXCEPTION: " << e.What();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
257 success = false;
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
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
261 /******************************************************************
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
262 * Finalize all the subcomponents of Orthanc Stone
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
263 ******************************************************************/
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
264
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
265 Finalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
266 Orthanc::HttpClient::GlobalFinalize();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
267 Orthanc::Toolbox::FinalizeOpenSsl();
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
268
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
269 return (success ? 0 : -1);
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
270 }
3c190e2bb3af refactoring: ApplicationRunner + app hierarchy
am@osimis.io
parents:
diff changeset
271 }