Mercurial > hg > orthanc-stone
annotate Applications/Sdl/BasicSdlApplication.cpp @ 266:c9cf95b49a86 am-2
removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
author | am@osimis.io |
---|---|
date | Tue, 21 Aug 2018 18:14:22 +0200 |
parents | c887eddd48f1 |
children | 46c5296d867e |
rev | line source |
---|---|
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
1 /** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
2 * Stone of Orthanc |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
6 * |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
11 * |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
16 * |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
19 **/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
20 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
21 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
22 #if ORTHANC_ENABLE_SDL != 1 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
23 #error this file shall be included only with the ORTHANC_ENABLE_SDL set to 1 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
24 #endif |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
25 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
26 #include "BasicSdlApplication.h" |
243 | 27 #include <boost/program_options.hpp> |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
28 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
29 #include "../../Framework/Toolbox/MessagingToolbox.h" |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
30 #include "SdlEngine.h" |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
31 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
32 #include <Core/Logging.h> |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
33 #include <Core/HttpClient.h> |
260 | 34 #include <Core/Toolbox.h> |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
35 #include <Plugins/Samples/Common/OrthancHttpConnection.h> |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
36 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
37 namespace OrthancStone |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
38 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
39 // Anonymous namespace to avoid clashes against other compilation modules |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
40 namespace |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
41 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
42 class LogStatusBar : public IStatusBar |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
43 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
44 public: |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
45 virtual void ClearMessage() |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
46 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
47 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
48 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
49 virtual void SetMessage(const std::string& message) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
50 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
51 LOG(WARNING) << message; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
52 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
53 }; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
54 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
55 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
56 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
57 static void DeclareSdlCommandLineOptions(boost::program_options::options_description& options) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
58 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
59 // Declare the supported parameters |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
60 boost::program_options::options_description generic("Generic options"); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
61 generic.add_options() |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
62 ("help", "Display this help and exit") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
63 ("verbose", "Be verbose in logs") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
64 ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"), |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
65 "URL to the Orthanc server") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
66 ("username", "Username for the Orthanc server") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
67 ("password", "Password for the Orthanc server") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
68 ("https-verify", boost::program_options::value<bool>()->default_value(true), "Check HTTPS certificates") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
69 ; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
70 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
71 options.add(generic); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
72 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
73 boost::program_options::options_description sdl("SDL options"); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
74 sdl.add_options() |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
75 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
76 ("height", boost::program_options::value<int>()->default_value(768), "Initial height of the SDL window") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
77 ("opengl", boost::program_options::value<bool>()->default_value(true), "Enable OpenGL in SDL") |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
78 ; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
79 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
80 options.add(sdl); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
81 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
82 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
83 |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
243
diff
changeset
|
84 int BasicSdlApplication::ExecuteWithSdl(MessageBroker& broker, |
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
243
diff
changeset
|
85 IBasicApplication& application, |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
86 int argc, |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
87 char* argv[]) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
88 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
89 /****************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
90 * Initialize all the subcomponents of Orthanc Stone |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
91 ******************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
92 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
93 Orthanc::Logging::Initialize(); |
260 | 94 Orthanc::Toolbox::InitializeOpenSsl(); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
95 Orthanc::HttpClient::GlobalInitialize(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
96 SdlWindow::GlobalInitialize(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
97 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
98 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
99 /****************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
100 * Declare and parse the command-line options of the application |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
101 ******************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
102 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
103 boost::program_options::options_description options; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
104 DeclareSdlCommandLineOptions(options); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
105 application.DeclareStartupOptions(options); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
106 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
107 boost::program_options::variables_map parameters; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
108 bool error = false; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
109 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
110 try |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
111 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
112 boost::program_options::store(boost::program_options::command_line_parser(argc, argv). |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
113 options(options).run(), parameters); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
114 boost::program_options::notify(parameters); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
115 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
116 catch (boost::program_options::error& e) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
117 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
118 LOG(ERROR) << "Error while parsing the command-line arguments: " << e.what(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
119 error = true; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
120 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
121 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
122 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
123 /****************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
124 * Configure the application with the command-line parameters |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
125 ******************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
126 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
127 if (error || parameters.count("help")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
128 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
129 std::cout << std::endl |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
130 << "Usage: " << argv[0] << " [OPTION]..." |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
131 << std::endl |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
132 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
133 << std::endl << std::endl |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
134 << "Demonstration application of Orthanc Stone using SDL." |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
135 << std::endl; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
136 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
137 std::cout << options << "\n"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
138 return error ? -1 : 0; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
139 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
140 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
141 if (parameters.count("https-verify") && |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
142 !parameters["https-verify"].as<bool>()) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
143 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
144 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
145 Orthanc::HttpClient::ConfigureSsl(false, ""); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
146 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
147 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
148 if (parameters.count("verbose")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
149 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
150 Orthanc::Logging::EnableInfoLevel(true); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
151 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
152 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
153 if (!parameters.count("width") || |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
154 !parameters.count("height") || |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
155 !parameters.count("opengl")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
156 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
157 LOG(ERROR) << "Parameter \"width\", \"height\" or \"opengl\" is missing"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
158 return -1; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
159 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
160 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
161 int w = parameters["width"].as<int>(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
162 int h = parameters["height"].as<int>(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
163 if (w <= 0 || h <= 0) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
164 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
165 LOG(ERROR) << "Parameters \"width\" and \"height\" must be positive"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
166 return -1; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
167 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
168 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
169 unsigned int width = static_cast<unsigned int>(w); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
170 unsigned int height = static_cast<unsigned int>(h); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
171 LOG(WARNING) << "Initial display size: " << width << "x" << height; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
172 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
173 bool opengl = parameters["opengl"].as<bool>(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
174 if (opengl) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
175 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
176 LOG(WARNING) << "OpenGL is enabled, disable it with option \"--opengl=off\" if the application crashes"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
177 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
178 else |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
179 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
180 LOG(WARNING) << "OpenGL is disabled, enable it with option \"--opengl=on\" for best performance"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
181 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
182 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
183 bool success = true; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
184 try |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
185 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
186 /**************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
187 * Initialize the connection to the Orthanc server |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
188 ****************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
189 |
242 | 190 Orthanc::WebServiceParameters webServiceParameters; |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
191 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
192 if (parameters.count("orthanc")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
193 { |
242 | 194 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>()); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
195 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
196 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
197 if (parameters.count("username")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
198 { |
242 | 199 webServiceParameters.SetUsername(parameters["username"].as<std::string>()); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
200 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
201 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
202 if (parameters.count("password")) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
203 { |
242 | 204 webServiceParameters.SetPassword(parameters["password"].as<std::string>()); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
205 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
206 |
242 | 207 LOG(WARNING) << "URL to the Orthanc REST API: " << webServiceParameters.GetUrl(); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
208 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
209 { |
242 | 210 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
211 if (!MessagingToolbox::CheckOrthancVersion(orthanc)) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
212 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
213 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of Orthanc, please upgrade"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
214 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
215 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
216 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
217 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
218 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
219 /**************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
220 * Initialize the application |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
221 ****************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
222 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
223 LOG(WARNING) << "Creating the widgets of the application"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
224 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
225 LogStatusBar statusBar; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
226 |
242 | 227 boost::mutex stoneGlobalMutex; |
228 Oracle oracle(stoneGlobalMutex, 4); // use 4 threads to download content | |
251
192e6e349e69
first usage of new message system (in SDL only)
am@osimis.io
parents:
243
diff
changeset
|
229 OracleWebService webService(broker, oracle, webServiceParameters); |
242 | 230 BasicSdlApplicationContext context(webService); |
231 | |
232 application.Initialize(&context, statusBar, parameters); | |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
233 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
234 { |
222 | 235 BasicSdlApplicationContext::ViewportLocker locker(context); |
242 | 236 context.SetCentralWidget(application.GetCentralWidget()); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
237 locker.GetViewport().SetStatusBar(statusBar); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
238 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
239 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
240 std::string title = application.GetTitle(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
241 if (title.empty()) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
242 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
243 title = "Stone of Orthanc"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
244 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
245 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
246 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
247 /************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
248 * Run the application inside a SDL window |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
249 **************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
250 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
251 LOG(WARNING) << "Starting the application"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
252 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
253 SdlWindow window(title.c_str(), width, height, opengl); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
254 SdlEngine sdl(window, context); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
255 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
256 { |
222 | 257 BasicSdlApplicationContext::ViewportLocker locker(context); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
258 locker.GetViewport().Register(sdl); // (*) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
259 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
260 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
261 context.Start(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
262 sdl.Run(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
263 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
264 LOG(WARNING) << "Stopping the application"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
265 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
266 // Don't move the "Stop()" command below out of the block, |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
267 // otherwise the application might crash, because the |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
268 // "SdlEngine" is an observer of the viewport (*) and the |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
269 // update thread started by "context.Start()" would call a |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
270 // destructed object (the "SdlEngine" is deleted with the |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
271 // lexical scope). |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
272 context.Stop(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
273 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
274 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
275 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
276 /**************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
277 * Finalize the application |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
278 ****************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
279 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
280 LOG(WARNING) << "The application has stopped"; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
281 application.Finalize(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
282 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
283 catch (Orthanc::OrthancException& e) |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
284 { |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
285 LOG(ERROR) << "EXCEPTION: " << e.What(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
286 success = false; |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
287 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
288 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
289 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
290 /****************************************************************** |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
291 * Finalize all the subcomponents of Orthanc Stone |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
292 ******************************************************************/ |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
293 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
294 SdlWindow::GlobalFinalize(); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
295 Orthanc::HttpClient::GlobalFinalize(); |
260 | 296 Orthanc::Toolbox::FinalizeOpenSsl(); |
221
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
297 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
298 return (success ? 0 : -1); |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
299 } |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
300 |
d7b2590744f8
wip: building applications reusable in SDL and WASM
am@osimis.io
parents:
diff
changeset
|
301 } |