Mercurial > hg > orthanc-stone
comparison Framework/Oracle/WebAssemblyOracle.cpp @ 933:f75f6cb69c1b
Commented-out traces for debug
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 26 Jul 2019 20:09:42 +0200 |
parents | 67f9c27214c5 |
children | a7351ad54960 |
comparison
equal
deleted
inserted
replaced
932:061a58c0011a | 933:f75f6cb69c1b |
---|---|
151 * Firstly, make a local copy of the fetched information, and | 151 * Firstly, make a local copy of the fetched information, and |
152 * free data associated with the fetch. | 152 * free data associated with the fetch. |
153 **/ | 153 **/ |
154 | 154 |
155 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); | 155 std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData)); |
156 if (fetch->userData == NULL) | |
157 { | |
158 LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback fetch->userData is NULL!!!!!!!"; | |
159 } | |
156 | 160 |
157 std::string answer; | 161 std::string answer; |
158 if (fetch->numBytes > 0) | 162 if (fetch->numBytes > 0) |
159 { | 163 { |
160 answer.assign(fetch->data, fetch->numBytes); | 164 answer.assign(fetch->data, fetch->numBytes); |
168 * query. This should be fixed in future versions of emscripten. | 172 * query. This should be fixed in future versions of emscripten. |
169 * https://github.com/emscripten-core/emscripten/pull/8486 | 173 * https://github.com/emscripten-core/emscripten/pull/8486 |
170 **/ | 174 **/ |
171 | 175 |
172 HttpHeaders headers; | 176 HttpHeaders headers; |
173 if (!context->GetExpectedContentType().empty()) | 177 if (fetch->userData != NULL) |
174 { | 178 { |
175 headers["Content-Type"] = context->GetExpectedContentType(); | 179 if (!context->GetExpectedContentType().empty()) |
176 } | 180 { |
177 | 181 headers["Content-Type"] = context->GetExpectedContentType(); |
182 } | |
183 } | |
178 | 184 |
179 emscripten_fetch_close(fetch); | 185 emscripten_fetch_close(fetch); |
180 | 186 |
181 | 187 |
182 /** | 188 /** |
392 }; | 398 }; |
393 | 399 |
394 void WebAssemblyOracle::Execute(const IObserver& receiver, | 400 void WebAssemblyOracle::Execute(const IObserver& receiver, |
395 OrthancRestApiCommand* command) | 401 OrthancRestApiCommand* command) |
396 { | 402 { |
397 FetchCommand fetch(*this, receiver, command); | 403 try |
398 | 404 { |
399 fetch.SetMethod(command->GetMethod()); | 405 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute."; |
400 fetch.SetUri(command->GetUri()); | 406 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command; |
401 fetch.SetHttpHeaders(command->GetHttpHeaders()); | 407 FetchCommand fetch(*this, receiver, command); |
402 fetch.SetTimeout(command->GetTimeout()); | 408 |
403 | 409 fetch.SetMethod(command->GetMethod()); |
404 if (command->GetMethod() == Orthanc::HttpMethod_Post || | 410 fetch.SetUri(command->GetUri()); |
411 fetch.SetHttpHeaders(command->GetHttpHeaders()); | |
412 fetch.SetTimeout(command->GetTimeout()); | |
413 | |
414 if (command->GetMethod() == Orthanc::HttpMethod_Post || | |
405 command->GetMethod() == Orthanc::HttpMethod_Put) | 415 command->GetMethod() == Orthanc::HttpMethod_Put) |
406 { | 416 { |
407 std::string body; | 417 std::string body; |
408 command->SwapBody(body); | 418 command->SwapBody(body); |
409 fetch.SetBody(body); | 419 fetch.SetBody(body); |
410 } | 420 } |
411 | 421 |
412 fetch.Execute(); | 422 fetch.Execute(); |
423 //LOG(TRACE) << "*********** successful end of WebAssemblyOracle::Execute."; | |
424 } | |
425 catch (const Orthanc::OrthancException& e) | |
426 { | |
427 if (e.HasDetails()) | |
428 { | |
429 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What() << " Details: " << e.GetDetails(); | |
430 } | |
431 else | |
432 { | |
433 LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What(); | |
434 } | |
435 //LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; | |
436 throw; | |
437 } | |
438 catch (const std::exception& e) | |
439 { | |
440 LOG(ERROR) << "std::exception in WebAssemblyOracle::Execute: " << e.what(); | |
441 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; | |
442 throw; | |
443 } | |
444 catch (...) | |
445 { | |
446 LOG(ERROR) << "Unknown exception in WebAssemblyOracle::Execute"; | |
447 // LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute."; | |
448 throw; | |
449 } | |
413 } | 450 } |
414 | 451 |
415 | 452 |
416 void WebAssemblyOracle::Execute(const IObserver& receiver, | 453 void WebAssemblyOracle::Execute(const IObserver& receiver, |
417 GetOrthancImageCommand* command) | 454 GetOrthancImageCommand* command) |
451 } | 488 } |
452 | 489 |
453 switch (command->GetType()) | 490 switch (command->GetType()) |
454 { | 491 { |
455 case IOracleCommand::Type_OrthancRestApi: | 492 case IOracleCommand::Type_OrthancRestApi: |
493 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
494 //{ | |
495 // const IObserver* pReceiver = &receiver; | |
496 // LOG(TRACE) << "WebAssemblyOracle::Schedule | pReceiver is " << pReceiver; | |
497 // LOG(TRACE) << "WebAssemblyOracle::Schedule | command = " << command; | |
498 // OrthancRestApiCommand* rac = dynamic_cast<OrthancRestApiCommand*>(protection.get()); | |
499 // LOG(TRACE) << "WebAssemblyOracle::Schedule | typed command = " << rac; | |
500 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
501 //} | |
502 //// END OF BLOCK TO REMOVE | |
456 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); | 503 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); |
457 break; | 504 break; |
458 | 505 |
459 case IOracleCommand::Type_GetOrthancImage: | 506 case IOracleCommand::Type_GetOrthancImage: |
507 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
508 //{ | |
509 // GetOrthancImageCommand* rac = dynamic_cast<GetOrthancImageCommand*>(protection.get()); | |
510 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
511 //} | |
512 //// END OF BLOCK TO REMOVE | |
460 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); | 513 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); |
461 break; | 514 break; |
462 | 515 |
463 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | 516 case IOracleCommand::Type_GetOrthancWebViewerJpeg: |
517 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
518 //{ | |
519 // GetOrthancWebViewerJpegCommand* rac = dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.get()); | |
520 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
521 //} | |
522 //// END OF BLOCK TO REMOVE | |
464 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release())); | 523 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release())); |
465 break; | 524 break; |
466 | 525 |
467 case IOracleCommand::Type_Sleep: | 526 case IOracleCommand::Type_Sleep: |
468 { | 527 { |