Mercurial > hg > orthanc-stone
comparison Framework/Oracle/WebAssemblyOracle.cpp @ 1243:608983cc2512 broker
removing unused logs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jan 2020 20:06:23 +0100 |
parents | b9b5d4378874 |
children | b17959d4da06 |
comparison
equal
deleted
inserted
replaced
1242:b9b5d4378874 | 1243:608983cc2512 |
---|---|
29 | 29 |
30 #include <emscripten.h> | 30 #include <emscripten.h> |
31 #include <emscripten/html5.h> | 31 #include <emscripten/html5.h> |
32 #include <emscripten/fetch.h> | 32 #include <emscripten/fetch.h> |
33 | 33 |
34 #if 0 | |
35 extern bool logbgo233; | |
36 extern bool logbgo115; | |
37 #endif | |
38 | |
39 namespace OrthancStone | 34 namespace OrthancStone |
40 { | 35 { |
41 class WebAssemblyOracle::TimeoutContext | 36 class WebAssemblyOracle::TimeoutContext |
42 { | 37 { |
43 private: | 38 private: |
145 const T& GetTypedCommand() const | 140 const T& GetTypedCommand() const |
146 { | 141 { |
147 return dynamic_cast<T&>(*command_); | 142 return dynamic_cast<T&>(*command_); |
148 } | 143 } |
149 | 144 |
150 #if 0 | |
151 static std::string ToString(Orthanc::HttpMethod method) | |
152 { | |
153 switch (method) { | |
154 case Orthanc::HttpMethod_Get: | |
155 return "GET"; | |
156 break; | |
157 case Orthanc::HttpMethod_Post: | |
158 return "POST"; | |
159 break; | |
160 default: | |
161 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
162 break; | |
163 } | |
164 } | |
165 static void DumpCommand(emscripten_fetch_t* fetch, std::string answer) | |
166 { | |
167 FetchContext* context = reinterpret_cast<FetchContext*>(fetch->userData); | |
168 | |
169 const auto& command = context->GetTypedCommand<OrthancRestApiCommand>(); | |
170 auto commandStr = ToString(command.GetMethod()); | |
171 LOG(TRACE) << "SuccessCallback for REST command. Method is : " << commandStr; | |
172 switch (command.GetMethod()) { | |
173 case Orthanc::HttpMethod_Get: | |
174 LOG(TRACE) << " * SuccessCallback GET URI = " << command.GetUri() << " timeout = " << command.GetTimeout(); | |
175 LOG(TRACE) << " * SuccessCallback GET RESPONSE = " << answer; | |
176 break; | |
177 case Orthanc::HttpMethod_Post: | |
178 LOG(TRACE) << " * SuccessCallback POST URI = " << command.GetUri() << " body = " << command.GetBody() << " timeout = " << command.GetTimeout(); | |
179 LOG(TRACE) << " * SuccessCallback POST RESPONSE = " << answer; | |
180 break; | |
181 default: | |
182 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
183 break; | |
184 } | |
185 } | |
186 #endif | |
187 | |
188 static void SuccessCallback(emscripten_fetch_t *fetch) | 145 static void SuccessCallback(emscripten_fetch_t *fetch) |
189 { | 146 { |
190 /** | 147 /** |
191 * Firstly, make a local copy of the fetched information, and | 148 * Firstly, make a local copy of the fetched information, and |
192 * free data associated with the fetch. | 149 * free data associated with the fetch. |
222 { | 179 { |
223 headers["Content-Type"] = context->GetExpectedContentType(); | 180 headers["Content-Type"] = context->GetExpectedContentType(); |
224 } | 181 } |
225 } | 182 } |
226 | 183 |
227 #if 0 | |
228 if (context->GetCommand().GetType() == IOracleCommand::Type_OrthancRestApi) { | |
229 //if (logbgo115) | |
230 DumpCommand(fetch, answer); | |
231 } | |
232 #endif | |
233 LOG(TRACE) << "About to call emscripten_fetch_close"; | 184 LOG(TRACE) << "About to call emscripten_fetch_close"; |
234 emscripten_fetch_close(fetch); | 185 emscripten_fetch_close(fetch); |
235 LOG(TRACE) << "Successfully called emscripten_fetch_close"; | 186 LOG(TRACE) << "Successfully called emscripten_fetch_close"; |
236 | 187 |
237 /** | 188 /** |
395 password_ = password; | 346 password_ = password; |
396 } | 347 } |
397 | 348 |
398 void Execute() | 349 void Execute() |
399 { | 350 { |
400 #if 0 | |
401 if (logbgo233) { | |
402 if (logbgo115) | |
403 LOG(TRACE) << " WebAssemblyOracle::Execute () command addr " << | |
404 std::hex << command_.get() << std::dec; | |
405 } | |
406 #endif | |
407 if (command_.get() == NULL) | 351 if (command_.get() == NULL) |
408 { | 352 { |
409 // Cannot call Execute() twice | 353 // Cannot call Execute() twice |
410 LOG(ERROR) << "WebAssemblyOracle::Execute(): (command_.get() == NULL)"; | 354 LOG(ERROR) << "WebAssemblyOracle::Execute(): (command_.get() == NULL)"; |
411 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | 355 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
491 attr.requestData = requestData; | 435 attr.requestData = requestData; |
492 } | 436 } |
493 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); | 437 attr.userData = new FetchContext(oracle_, receiver_, command_.release(), expectedContentType); |
494 | 438 |
495 // Must be the last call to prevent memory leak on error | 439 // Must be the last call to prevent memory leak on error |
496 #if 0 | |
497 LOG(TRACE) << "Performing " << method << " request on URI: \"" << url_ << "\""; | |
498 #endif | |
499 emscripten_fetch(&attr, url_.c_str()); | 440 emscripten_fetch(&attr, url_.c_str()); |
500 } | 441 } |
501 catch(...) | 442 catch(...) |
502 { | 443 { |
503 if(requestData != NULL) | 444 if(requestData != NULL) |
505 throw; | 446 throw; |
506 } | 447 } |
507 } | 448 } |
508 }; | 449 }; |
509 | 450 |
510 #if 0 | 451 |
511 static void DumpCommand(OrthancRestApiCommand* pCommand) | |
512 { | |
513 OrthancRestApiCommand& command = *pCommand; | |
514 LOG(TRACE) << "WebAssemblyOracle::Execute for REST command."; | |
515 switch (command.GetMethod()) { | |
516 case Orthanc::HttpMethod_Get: | |
517 LOG(TRACE) << " * WebAssemblyOracle::Execute GET URI = " << command.GetUri() << " timeout = " << command.GetTimeout(); | |
518 break; | |
519 case Orthanc::HttpMethod_Post: | |
520 LOG(TRACE) << " * WebAssemblyOracle::Execute POST URI = " << command.GetUri() << " body = " << command.GetBody() << " timeout = " << command.GetTimeout(); | |
521 break; | |
522 default: | |
523 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
524 break; | |
525 } | |
526 } | |
527 #endif | |
528 | |
529 | |
530 void WebAssemblyOracle::SetOrthancUrl(FetchCommand& command, | 452 void WebAssemblyOracle::SetOrthancUrl(FetchCommand& command, |
531 const std::string& uri) const | 453 const std::string& uri) const |
532 { | 454 { |
533 if (isLocalOrthanc_) | 455 if (isLocalOrthanc_) |
534 { | 456 { |
570 | 492 |
571 | 493 |
572 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, | 494 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
573 OrthancRestApiCommand* command) | 495 OrthancRestApiCommand* command) |
574 { | 496 { |
575 #if 0 | |
576 DumpCommand(command); | |
577 | |
578 if (logbgo233) { | |
579 if (logbgo115) | |
580 LOG(TRACE) << " WebAssemblyOracle::Execute (OrthancRestApiCommand) command addr " << | |
581 std::hex << command << std::dec; | |
582 } | |
583 #endif | |
584 | |
585 try | 497 try |
586 { | 498 { |
587 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute."; | 499 //LOG(TRACE) << "*********** WebAssemblyOracle::Execute."; |
588 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command; | 500 //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command; |
589 FetchCommand fetch(*this, receiver, command); | 501 FetchCommand fetch(*this, receiver, command); |
633 | 545 |
634 | 546 |
635 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, | 547 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
636 GetOrthancImageCommand* command) | 548 GetOrthancImageCommand* command) |
637 { | 549 { |
638 #if 0 | |
639 if (logbgo233) { | |
640 if (logbgo115) | |
641 LOG(TRACE) << " WebAssemblyOracle::Execute (GetOrthancImageCommand) command addr " << | |
642 std::hex << command << std::dec; | |
643 } | |
644 #endif | |
645 | |
646 FetchCommand fetch(*this, receiver, command); | 550 FetchCommand fetch(*this, receiver, command); |
647 | 551 |
648 SetOrthancUrl(fetch, command->GetUri()); | 552 SetOrthancUrl(fetch, command->GetUri()); |
649 fetch.AddHttpHeaders(command->GetHttpHeaders()); | 553 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
650 fetch.SetTimeout(command->GetTimeout()); | 554 fetch.SetTimeout(command->GetTimeout()); |
654 | 558 |
655 | 559 |
656 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, | 560 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
657 GetOrthancWebViewerJpegCommand* command) | 561 GetOrthancWebViewerJpegCommand* command) |
658 { | 562 { |
659 #if 0 | |
660 if (logbgo233) { | |
661 if (logbgo115) | |
662 LOG(TRACE) << " WebAssemblyOracle::Execute (GetOrthancWebViewerJpegCommand) command addr " << std::hex << command << std::dec; | |
663 } | |
664 #endif | |
665 | |
666 FetchCommand fetch(*this, receiver, command); | 563 FetchCommand fetch(*this, receiver, command); |
667 | 564 |
668 SetOrthancUrl(fetch, command->GetUri()); | 565 SetOrthancUrl(fetch, command->GetUri()); |
669 fetch.AddHttpHeaders(command->GetHttpHeaders()); | 566 fetch.AddHttpHeaders(command->GetHttpHeaders()); |
670 fetch.SetTimeout(command->GetTimeout()); | 567 fetch.SetTimeout(command->GetTimeout()); |
671 | 568 |
672 fetch.Execute(); | 569 fetch.Execute(); |
673 } | 570 } |
674 | 571 |
572 | |
573 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, | |
574 ParseDicomFromWadoCommand* command) | |
575 { | |
576 std::auto_ptr<ParseDicomFromWadoCommand> protection(command); | |
577 | |
578 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
579 } | |
675 | 580 |
676 | 581 |
677 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, | 582 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, |
678 IOracleCommand* command) | 583 IOracleCommand* command) |
679 { | 584 { |
692 case IOracleCommand::Type_Http: | 597 case IOracleCommand::Type_Http: |
693 Execute(receiver, dynamic_cast<HttpCommand*>(protection.release())); | 598 Execute(receiver, dynamic_cast<HttpCommand*>(protection.release())); |
694 break; | 599 break; |
695 | 600 |
696 case IOracleCommand::Type_OrthancRestApi: | 601 case IOracleCommand::Type_OrthancRestApi: |
697 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
698 //{ | |
699 // const IObserver* pReceiver = &receiver; | |
700 // LOG(TRACE) << "WebAssemblyOracle::Schedule | pReceiver is " << pReceiver; | |
701 // LOG(TRACE) << "WebAssemblyOracle::Schedule | command = " << command; | |
702 // OrthancRestApiCommand* rac = dynamic_cast<OrthancRestApiCommand*>(protection.get()); | |
703 // LOG(TRACE) << "WebAssemblyOracle::Schedule | typed command = " << rac; | |
704 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
705 //} | |
706 //// END OF BLOCK TO REMOVE | |
707 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); | 602 Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release())); |
708 break; | 603 break; |
709 | 604 |
710 case IOracleCommand::Type_GetOrthancImage: | 605 case IOracleCommand::Type_GetOrthancImage: |
711 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
712 //{ | |
713 // GetOrthancImageCommand* rac = dynamic_cast<GetOrthancImageCommand*>(protection.get()); | |
714 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
715 //} | |
716 //// END OF BLOCK TO REMOVE | |
717 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); | 606 Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release())); |
718 break; | 607 break; |
719 | 608 |
720 case IOracleCommand::Type_GetOrthancWebViewerJpeg: | 609 case IOracleCommand::Type_GetOrthancWebViewerJpeg: |
721 //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE | |
722 //{ | |
723 // GetOrthancWebViewerJpegCommand* rac = dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.get()); | |
724 // LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri(); | |
725 //} | |
726 //// END OF BLOCK TO REMOVE | |
727 Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release())); | |
728 break; | 610 break; |
729 | 611 |
730 case IOracleCommand::Type_Sleep: | 612 case IOracleCommand::Type_Sleep: |
731 { | 613 { |
732 unsigned int timeoutMS = dynamic_cast<SleepOracleCommand*>(command)->GetDelay(); | 614 unsigned int timeoutMS = dynamic_cast<SleepOracleCommand*>(command)->GetDelay(); |
733 emscripten_set_timeout(TimeoutContext::Callback, timeoutMS, | 615 emscripten_set_timeout(TimeoutContext::Callback, timeoutMS, |
734 new TimeoutContext(*this, receiver, protection.release())); | 616 new TimeoutContext(*this, receiver, protection.release())); |
735 break; | 617 break; |
736 } | 618 } |
737 | 619 |
620 case IOracleCommand::Type_ParseDicomFromWado: | |
621 Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release())); | |
622 break; | |
623 | |
738 default: | 624 default: |
739 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType(); | 625 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType(); |
740 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 626 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
741 } | 627 } |
742 | 628 |