Mercurial > hg > orthanc-stone
comparison Applications/Generic/NativeStoneApplicationRunner.cpp @ 603:70992b38aa8a
new routable logging system in STDIO mode + flag support (with no value) in StartupParametersBuilder + 80 col indent
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 29 Apr 2019 15:09:48 +0200 |
parents | b336dfa71f12 |
children | 86dfde451f4c |
comparison
equal
deleted
inserted
replaced
602:03c4b998fcd0 | 603:70992b38aa8a |
---|---|
79 { // generic options | 79 { // generic options |
80 boost::program_options::options_description generic("Generic options"); | 80 boost::program_options::options_description generic("Generic options"); |
81 generic.add_options() | 81 generic.add_options() |
82 ("help", "Display this help and exit") | 82 ("help", "Display this help and exit") |
83 ("verbose", "Be verbose in logs") | 83 ("verbose", "Be verbose in logs") |
84 ("orthanc", boost::program_options::value<std::string>()->default_value("http://localhost:8042/"), | 84 ("orthanc", boost::program_options::value<std::string>()-> |
85 default_value("http://localhost:8042/"), | |
85 "URL to the Orthanc server") | 86 "URL to the Orthanc server") |
86 ("username", "Username for the Orthanc server") | 87 ("username", "Username for the Orthanc server") |
87 ("password", "Password for the Orthanc server") | 88 ("password", "Password for the Orthanc server") |
88 ("https-verify", boost::program_options::value<bool>()->default_value(true), "Check HTTPS certificates") | 89 ("https-verify", boost::program_options::value<bool>()-> |
90 default_value(true), "Check HTTPS certificates") | |
89 ; | 91 ; |
90 | 92 |
91 options.add(generic); | 93 options.add(generic); |
92 } | 94 } |
93 | 95 |
100 boost::program_options::variables_map parameters; | 102 boost::program_options::variables_map parameters; |
101 bool error = false; | 103 bool error = false; |
102 | 104 |
103 try | 105 try |
104 { | 106 { |
105 boost::program_options::store(boost::program_options::command_line_parser(argc, argv). | 107 boost::program_options::store( |
106 options(options).run(), parameters); | 108 boost::program_options::command_line_parser(argc, argv). |
109 options(options).run(), parameters); | |
107 boost::program_options::notify(parameters); | 110 boost::program_options::notify(parameters); |
108 } | 111 } |
109 catch (boost::program_options::error& e) | 112 catch (boost::program_options::error& e) |
110 { | 113 { |
111 LOG(ERROR) << "Error while parsing the command-line arguments: " << e.what(); | 114 LOG(ERROR) << |
115 "Error while parsing the command-line arguments: " << e.what(); | |
112 error = true; | 116 error = true; |
113 } | 117 } |
114 | 118 |
115 | 119 |
116 /****************************************************************** | 120 /****************************************************************** |
118 ******************************************************************/ | 122 ******************************************************************/ |
119 | 123 |
120 if (error || parameters.count("help")) | 124 if (error || parameters.count("help")) |
121 { | 125 { |
122 std::cout << std::endl | 126 std::cout << std::endl |
123 << "Usage: " << argv[0] << " [OPTION]..." | 127 << "Usage: " << argv[0] << " [OPTION]..." << std::endl |
124 << std::endl | 128 << "Orthanc, lightweight, RESTful DICOM server for healthcare " |
125 << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." | 129 << "and medical research." << std::endl << std::endl |
126 << std::endl << std::endl | 130 << "Demonstration application of Orthanc Stone in native " |
127 << "Demonstration application of Orthanc Stone in native environment." | 131 << "environment." << std::endl; |
128 << std::endl; | |
129 | 132 |
130 std::cout << options << "\n"; | 133 std::cout << options << "\n"; |
131 return error ? -1 : 0; | 134 return error ? -1 : 0; |
132 } | 135 } |
133 | 136 |
136 { | 139 { |
137 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)"; | 140 LOG(WARNING) << "Turning off verification of HTTPS certificates (unsafe)"; |
138 Orthanc::HttpClient::ConfigureSsl(false, ""); | 141 Orthanc::HttpClient::ConfigureSsl(false, ""); |
139 } | 142 } |
140 | 143 |
144 LOG(ERROR) << "???????? if (parameters.count(\"verbose\"))"; | |
141 if (parameters.count("verbose")) | 145 if (parameters.count("verbose")) |
142 { | 146 { |
147 LOG(ERROR) << "parameters.count(\"verbose\") != 0"; | |
143 Orthanc::Logging::EnableInfoLevel(true); | 148 Orthanc::Logging::EnableInfoLevel(true); |
144 LOG(INFO) << "Verbose logs are enabled"; | 149 LOG(INFO) << "Verbose logs are enabled"; |
145 } | 150 } |
146 | 151 |
152 ` LOG(ERROR) << "???????? if (parameters.count(\"trace\"))"; | |
147 if (parameters.count("trace")) | 153 if (parameters.count("trace")) |
148 { | 154 { |
155 LOG(ERROR) << "parameters.count(\"trace\") != 0"; | |
149 Orthanc::Logging::EnableTraceLevel(true); | 156 Orthanc::Logging::EnableTraceLevel(true); |
150 VLOG(1) << "Trace logs are enabled"; | 157 VLOG(1) << "Trace logs are enabled"; |
151 } | 158 } |
152 | 159 |
153 ParseCommandLineOptions(parameters); | 160 ParseCommandLineOptions(parameters); |
154 | |
155 | 161 |
156 bool success = true; | 162 bool success = true; |
157 try | 163 try |
158 { | 164 { |
159 /**************************************************************** | 165 /**************************************************************** |
167 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>()); | 173 webServiceParameters.SetUrl(parameters["orthanc"].as<std::string>()); |
168 } | 174 } |
169 | 175 |
170 if (parameters.count("username") && parameters.count("password")) | 176 if (parameters.count("username") && parameters.count("password")) |
171 { | 177 { |
172 webServiceParameters.SetCredentials(parameters["username"].as<std::string>(), | 178 webServiceParameters.SetCredentials(parameters["username"]. |
173 parameters["password"].as<std::string>()); | 179 as<std::string>(), |
174 } | 180 parameters["password"].as<std::string>()); |
175 | 181 } |
176 LOG(WARNING) << "URL to the Orthanc REST API: " << webServiceParameters.GetUrl(); | 182 |
183 LOG(WARNING) << "URL to the Orthanc REST API: " << | |
184 webServiceParameters.GetUrl(); | |
177 | 185 |
178 { | 186 { |
179 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters); | 187 OrthancPlugins::OrthancHttpConnection orthanc(webServiceParameters); |
180 if (!MessagingToolbox::CheckOrthancVersion(orthanc)) | 188 if (!MessagingToolbox::CheckOrthancVersion(orthanc)) |
181 { | 189 { |
182 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of Orthanc, please upgrade"; | 190 LOG(ERROR) << "Your version of Orthanc is incompatible with Stone of " |
191 << "Orthanc, please upgrade"; | |
183 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); | 192 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
184 } | 193 } |
185 } | 194 } |
186 | 195 |
187 | 196 |
194 LogStatusBar statusBar; | 203 LogStatusBar statusBar; |
195 | 204 |
196 NativeStoneApplicationContext context(broker_); | 205 NativeStoneApplicationContext context(broker_); |
197 | 206 |
198 { | 207 { |
199 Oracle oracle(6); // use multiple threads to execute asynchronous tasks like download content | 208 // use multiple threads to execute asynchronous tasks like |
209 // download content | |
210 Oracle oracle(6); | |
200 oracle.Start(); | 211 oracle.Start(); |
201 | 212 |
202 { | 213 { |
203 OracleWebService webService(broker_, oracle, webServiceParameters, context); | 214 OracleWebService webService( |
215 broker_, oracle, webServiceParameters, context); | |
216 | |
204 context.SetWebService(webService); | 217 context.SetWebService(webService); |
205 context.SetOrthancBaseUrl(webServiceParameters.GetUrl()); | 218 context.SetOrthancBaseUrl(webServiceParameters.GetUrl()); |
206 | 219 |
207 OracleDelayedCallExecutor delayedExecutor(broker_, oracle, context); | 220 OracleDelayedCallExecutor delayedExecutor(broker_, oracle, context); |
208 context.SetDelayedCallExecutor(delayedExecutor); | 221 context.SetDelayedCallExecutor(delayedExecutor); |
253 Orthanc::HttpClient::GlobalFinalize(); | 266 Orthanc::HttpClient::GlobalFinalize(); |
254 Orthanc::Toolbox::FinalizeOpenSsl(); | 267 Orthanc::Toolbox::FinalizeOpenSsl(); |
255 | 268 |
256 return (success ? 0 : -1); | 269 return (success ? 0 : -1); |
257 } | 270 } |
258 | |
259 } | 271 } |