Mercurial > hg > orthanc-stone
comparison Framework/Oracle/WebAssemblyOracle.cpp @ 1244:b17959d4da06 broker
working on ParseDicomFromWadoCommand for wasm
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 06 Jan 2020 20:53:27 +0100 |
parents | 608983cc2512 |
children | 3d4dc87af04b |
comparison
equal
deleted
inserted
replaced
1243:608983cc2512 | 1244:b17959d4da06 |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "WebAssemblyOracle.h" | 22 #include "WebAssemblyOracle.h" |
23 | 23 |
24 #include "OracleCommandExceptionMessage.h" | |
24 #include "SleepOracleCommand.h" | 25 #include "SleepOracleCommand.h" |
25 #include "OracleCommandExceptionMessage.h" | 26 |
27 #if ORTHANC_ENABLE_DCMTK == 1 | |
28 # include "ParseDicomSuccessMessage.h" | |
29 #endif | |
26 | 30 |
27 #include <Core/OrthancException.h> | 31 #include <Core/OrthancException.h> |
28 #include <Core/Toolbox.h> | 32 #include <Core/Toolbox.h> |
29 | 33 |
30 #include <emscripten.h> | 34 #include <emscripten.h> |
168 * not contain a way to retrieve the HTTP headers of the | 172 * not contain a way to retrieve the HTTP headers of the |
169 * answer. We make the assumption that the "Content-Type" header | 173 * answer. We make the assumption that the "Content-Type" header |
170 * of the response is the same as the "Accept" header of the | 174 * of the response is the same as the "Accept" header of the |
171 * query. This should be fixed in future versions of emscripten. | 175 * query. This should be fixed in future versions of emscripten. |
172 * https://github.com/emscripten-core/emscripten/pull/8486 | 176 * https://github.com/emscripten-core/emscripten/pull/8486 |
177 * | |
178 * TODO - The function "emscripten_fetch_get_response_headers()" | |
179 * was added to "fetch.h" at emscripten-1.38.37 on 2019-06-26. | |
180 * https://github.com/emscripten-core/emscripten/blob/1.38.37/system/include/emscripten/fetch.h | |
173 **/ | 181 **/ |
174 | 182 |
175 HttpHeaders headers; | 183 HttpHeaders headers; |
176 if (fetch->userData != NULL) | 184 if (fetch->userData != NULL) |
177 { | 185 { |
229 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer | 237 context->GetTypedCommand<GetOrthancWebViewerJpegCommand>().ProcessHttpAnswer |
230 (context->GetReceiver(), context->GetEmitter(), answer); | 238 (context->GetReceiver(), context->GetEmitter(), answer); |
231 break; | 239 break; |
232 } | 240 } |
233 | 241 |
242 case IOracleCommand::Type_ParseDicomFromWado: | |
243 { | |
244 #if ORTHANC_ENABLE_DCMTK == 1 | |
245 size_t fileSize; | |
246 std::auto_ptr<Orthanc::ParsedDicomFile> dicom | |
247 (ParseDicomSuccessMessage::ParseWadoAnswer(fileSize, answer, headers)); | |
248 LOG(WARNING) << "bingo"; | |
249 #else | |
250 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
251 #endif | |
252 break; | |
253 } | |
254 | |
234 default: | 255 default: |
235 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " | 256 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in SuccessCallback): " |
236 << context->GetCommand().GetType(); | 257 << context->GetCommand().GetType(); |
237 } | 258 } |
238 } | 259 } |
239 } | 260 } |
240 catch (Orthanc::OrthancException& e) | 261 catch (Orthanc::OrthancException& e) |
572 | 593 |
573 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, | 594 void WebAssemblyOracle::Execute(boost::weak_ptr<IObserver> receiver, |
574 ParseDicomFromWadoCommand* command) | 595 ParseDicomFromWadoCommand* command) |
575 { | 596 { |
576 std::auto_ptr<ParseDicomFromWadoCommand> protection(command); | 597 std::auto_ptr<ParseDicomFromWadoCommand> protection(command); |
577 | 598 |
578 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 599 // TODO - CACHE |
600 | |
601 | |
602 switch (command->GetRestCommand().GetType()) | |
603 { | |
604 case IOracleCommand::Type_Http: | |
605 { | |
606 const HttpCommand& rest = | |
607 dynamic_cast<const HttpCommand&>(protection->GetRestCommand()); | |
608 | |
609 FetchCommand fetch(*this, receiver, protection.release()); | |
610 | |
611 fetch.SetMethod(rest.GetMethod()); | |
612 fetch.SetUrl(rest.GetUrl()); | |
613 fetch.AddHttpHeaders(rest.GetHttpHeaders()); | |
614 fetch.SetTimeout(rest.GetTimeout()); | |
615 | |
616 if (rest.GetMethod() == Orthanc::HttpMethod_Post || | |
617 rest.GetMethod() == Orthanc::HttpMethod_Put) | |
618 { | |
619 std::string body = rest.GetBody(); | |
620 fetch.SetBody(body); | |
621 } | |
622 | |
623 fetch.Execute(); | |
624 break; | |
625 } | |
626 | |
627 case IOracleCommand::Type_OrthancRestApi: | |
628 { | |
629 const OrthancRestApiCommand& rest = | |
630 dynamic_cast<const OrthancRestApiCommand&>(protection->GetRestCommand()); | |
631 | |
632 FetchCommand fetch(*this, receiver, protection.release()); | |
633 | |
634 fetch.SetMethod(rest.GetMethod()); | |
635 SetOrthancUrl(fetch, rest.GetUri()); | |
636 fetch.AddHttpHeaders(rest.GetHttpHeaders()); | |
637 fetch.SetTimeout(rest.GetTimeout()); | |
638 | |
639 if (rest.GetMethod() == Orthanc::HttpMethod_Post || | |
640 rest.GetMethod() == Orthanc::HttpMethod_Put) | |
641 { | |
642 std::string body = rest.GetBody(); | |
643 fetch.SetBody(body); | |
644 } | |
645 | |
646 fetch.Execute(); | |
647 break; | |
648 } | |
649 | |
650 default: | |
651 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
652 } | |
579 } | 653 } |
580 | 654 |
581 | 655 |
582 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, | 656 bool WebAssemblyOracle::Schedule(boost::shared_ptr<IObserver> receiver, |
583 IOracleCommand* command) | 657 IOracleCommand* command) |
616 new TimeoutContext(*this, receiver, protection.release())); | 690 new TimeoutContext(*this, receiver, protection.release())); |
617 break; | 691 break; |
618 } | 692 } |
619 | 693 |
620 case IOracleCommand::Type_ParseDicomFromWado: | 694 case IOracleCommand::Type_ParseDicomFromWado: |
695 #if ORTHANC_ENABLE_DCMTK == 1 | |
621 Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release())); | 696 Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release())); |
697 #else | |
698 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented, | |
699 "DCMTK must be enabled to parse DICOM files"); | |
700 #endif | |
622 break; | 701 break; |
623 | 702 |
624 default: | 703 default: |
625 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType(); | 704 LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in Schedule): " |
705 << command->GetType(); | |
626 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | 706 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
627 } | 707 } |
628 | 708 |
629 return true; | 709 return true; |
630 } | 710 } |