comparison Framework/Oracle/GenericOracleRunner.cpp @ 1135:a0a33e5ea5bb broker

IOracleCommand::Clone()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 06 Nov 2019 17:34:58 +0100
parents 87fbeb823375
children 42581a6182c8
comparison
equal deleted inserted replaced
1134:87fbeb823375 1135:a0a33e5ea5bb
100 } 100 }
101 101
102 102
103 static void RunInternal(boost::weak_ptr<IObserver> receiver, 103 static void RunInternal(boost::weak_ptr<IObserver> receiver,
104 IMessageEmitter& emitter, 104 IMessageEmitter& emitter,
105 HttpCommand& command) 105 const HttpCommand& command)
106 { 106 {
107 Orthanc::HttpClient client; 107 Orthanc::HttpClient client;
108 client.SetUrl(command.GetUrl()); 108 client.SetUrl(command.GetUrl());
109 client.SetMethod(command.GetMethod()); 109 client.SetMethod(command.GetMethod());
110 client.SetTimeout(command.GetTimeout()); 110 client.SetTimeout(command.GetTimeout());
134 134
135 135
136 static void RunInternal(boost::weak_ptr<IObserver> receiver, 136 static void RunInternal(boost::weak_ptr<IObserver> receiver,
137 IMessageEmitter& emitter, 137 IMessageEmitter& emitter,
138 const Orthanc::WebServiceParameters& orthanc, 138 const Orthanc::WebServiceParameters& orthanc,
139 OrthancRestApiCommand& command) 139 const OrthancRestApiCommand& command)
140 { 140 {
141 Orthanc::HttpClient client(orthanc, command.GetUri()); 141 Orthanc::HttpClient client(orthanc, command.GetUri());
142 client.SetMethod(command.GetMethod()); 142 client.SetMethod(command.GetMethod());
143 client.SetTimeout(command.GetTimeout()); 143 client.SetTimeout(command.GetTimeout());
144 144
162 162
163 163
164 static void RunInternal(boost::weak_ptr<IObserver> receiver, 164 static void RunInternal(boost::weak_ptr<IObserver> receiver,
165 IMessageEmitter& emitter, 165 IMessageEmitter& emitter,
166 const Orthanc::WebServiceParameters& orthanc, 166 const Orthanc::WebServiceParameters& orthanc,
167 GetOrthancImageCommand& command) 167 const GetOrthancImageCommand& command)
168 { 168 {
169 Orthanc::HttpClient client(orthanc, command.GetUri()); 169 Orthanc::HttpClient client(orthanc, command.GetUri());
170 client.SetTimeout(command.GetTimeout()); 170 client.SetTimeout(command.GetTimeout());
171 171
172 CopyHttpHeaders(client, command.GetHttpHeaders()); 172 CopyHttpHeaders(client, command.GetHttpHeaders());
182 182
183 183
184 static void RunInternal(boost::weak_ptr<IObserver> receiver, 184 static void RunInternal(boost::weak_ptr<IObserver> receiver,
185 IMessageEmitter& emitter, 185 IMessageEmitter& emitter,
186 const Orthanc::WebServiceParameters& orthanc, 186 const Orthanc::WebServiceParameters& orthanc,
187 GetOrthancWebViewerJpegCommand& command) 187 const GetOrthancWebViewerJpegCommand& command)
188 { 188 {
189 Orthanc::HttpClient client(orthanc, command.GetUri()); 189 Orthanc::HttpClient client(orthanc, command.GetUri());
190 client.SetTimeout(command.GetTimeout()); 190 client.SetTimeout(command.GetTimeout());
191 191
192 CopyHttpHeaders(client, command.GetHttpHeaders()); 192 CopyHttpHeaders(client, command.GetHttpHeaders());
223 223
224 224
225 static void RunInternal(boost::weak_ptr<IObserver> receiver, 225 static void RunInternal(boost::weak_ptr<IObserver> receiver,
226 IMessageEmitter& emitter, 226 IMessageEmitter& emitter,
227 const std::string& root, 227 const std::string& root,
228 ReadFileCommand& command) 228 const ReadFileCommand& command)
229 { 229 {
230 std::string path = GetPath(root, command.GetPath()); 230 std::string path = GetPath(root, command.GetPath());
231 231
232 std::string content; 232 std::string content;
233 Orthanc::SystemToolbox::ReadFile(content, path, true /* log */); 233 Orthanc::SystemToolbox::ReadFile(content, path, true /* log */);
239 239
240 #if ORTHANC_ENABLE_DCMTK == 1 240 #if ORTHANC_ENABLE_DCMTK == 1
241 static void RunInternal(boost::weak_ptr<IObserver> receiver, 241 static void RunInternal(boost::weak_ptr<IObserver> receiver,
242 IMessageEmitter& emitter, 242 IMessageEmitter& emitter,
243 const std::string& root, 243 const std::string& root,
244 ParseDicomFileCommand& command) 244 const ParseDicomFileCommand& command)
245 { 245 {
246 std::string path = GetPath(root, command.GetPath()); 246 std::string path = GetPath(root, command.GetPath());
247 247
248 if (!Orthanc::SystemToolbox::IsRegularFile(path)) 248 if (!Orthanc::SystemToolbox::IsRegularFile(path))
249 { 249 {
301 301
302 static void RunInternal(boost::weak_ptr<IObserver> receiver, 302 static void RunInternal(boost::weak_ptr<IObserver> receiver,
303 IMessageEmitter& emitter, 303 IMessageEmitter& emitter,
304 boost::shared_ptr<ParsedDicomFileCache> cache, 304 boost::shared_ptr<ParsedDicomFileCache> cache,
305 const std::string& root, 305 const std::string& root,
306 ParseDicomFileCommand& command) 306 const ParseDicomFileCommand& command)
307 { 307 {
308 #if 0 308 #if 0
309 // The code to use the cache is buggy in multithreaded environments => TODO FIX 309 // The code to use the cache is buggy in multithreaded environments => TODO FIX
310 if (cache.get()) 310 if (cache.get())
311 { 311 {
346 #endif 346 #endif
347 347
348 348
349 void GenericOracleRunner::Run(boost::weak_ptr<IObserver> receiver, 349 void GenericOracleRunner::Run(boost::weak_ptr<IObserver> receiver,
350 IMessageEmitter& emitter, 350 IMessageEmitter& emitter,
351 IOracleCommand& command) 351 const IOracleCommand& command)
352 { 352 {
353 Orthanc::ErrorCode error = Orthanc::ErrorCode_Success; 353 Orthanc::ErrorCode error = Orthanc::ErrorCode_Success;
354 354
355 try 355 try
356 { 356 {
359 case IOracleCommand::Type_Sleep: 359 case IOracleCommand::Type_Sleep:
360 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType, 360 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType,
361 "Sleep command cannot be executed by the runner"); 361 "Sleep command cannot be executed by the runner");
362 362
363 case IOracleCommand::Type_Http: 363 case IOracleCommand::Type_Http:
364 RunInternal(receiver, emitter, dynamic_cast<HttpCommand&>(command)); 364 RunInternal(receiver, emitter, dynamic_cast<const HttpCommand&>(command));
365 break; 365 break;
366 366
367 case IOracleCommand::Type_OrthancRestApi: 367 case IOracleCommand::Type_OrthancRestApi:
368 RunInternal(receiver, emitter, orthanc_, 368 RunInternal(receiver, emitter, orthanc_,
369 dynamic_cast<OrthancRestApiCommand&>(command)); 369 dynamic_cast<const OrthancRestApiCommand&>(command));
370 break; 370 break;
371 371
372 case IOracleCommand::Type_GetOrthancImage: 372 case IOracleCommand::Type_GetOrthancImage:
373 RunInternal(receiver, emitter, orthanc_, 373 RunInternal(receiver, emitter, orthanc_,
374 dynamic_cast<GetOrthancImageCommand&>(command)); 374 dynamic_cast<const GetOrthancImageCommand&>(command));
375 break; 375 break;
376 376
377 case IOracleCommand::Type_GetOrthancWebViewerJpeg: 377 case IOracleCommand::Type_GetOrthancWebViewerJpeg:
378 RunInternal(receiver, emitter, orthanc_, 378 RunInternal(receiver, emitter, orthanc_,
379 dynamic_cast<GetOrthancWebViewerJpegCommand&>(command)); 379 dynamic_cast<const GetOrthancWebViewerJpegCommand&>(command));
380 break; 380 break;
381 381
382 case IOracleCommand::Type_ReadFile: 382 case IOracleCommand::Type_ReadFile:
383 RunInternal(receiver, emitter, rootDirectory_, 383 RunInternal(receiver, emitter, rootDirectory_,
384 dynamic_cast<ReadFileCommand&>(command)); 384 dynamic_cast<const ReadFileCommand&>(command));
385 break; 385 break;
386 386
387 case IOracleCommand::Type_ParseDicomFile: 387 case IOracleCommand::Type_ParseDicomFile:
388 #if ORTHANC_ENABLE_DCMTK == 1 388 #if ORTHANC_ENABLE_DCMTK == 1
389 RunInternal(receiver, emitter, dicomCache_, rootDirectory_, 389 RunInternal(receiver, emitter, dicomCache_, rootDirectory_,
390 dynamic_cast<ParseDicomFileCommand&>(command)); 390 dynamic_cast<const ParseDicomFileCommand&>(command));
391 break; 391 break;
392 #else 392 #else
393 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, 393 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
394 "DCMTK must be enabled to parse DICOM files"); 394 "DCMTK must be enabled to parse DICOM files");
395 #endif 395 #endif
407 { 407 {
408 LOG(ERROR) << "Threaded exception within the oracle"; 408 LOG(ERROR) << "Threaded exception within the oracle";
409 error = Orthanc::ErrorCode_InternalError; 409 error = Orthanc::ErrorCode_InternalError;
410 } 410 }
411 411
412 OracleCommandExceptionMessage message(command, error); 412 if (error != Orthanc::ErrorCode_Success)
413 emitter.EmitMessage(receiver, message); 413 {
414 OracleCommandExceptionMessage message(command, error);
415 emitter.EmitMessage(receiver, message);
416 }
414 } 417 }
415 } 418 }