changeset 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
files Framework/Oracle/WebAssemblyOracle.cpp
diffstat 1 files changed, 84 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Oracle/WebAssemblyOracle.cpp	Mon Jan 06 20:06:23 2020 +0100
+++ b/Framework/Oracle/WebAssemblyOracle.cpp	Mon Jan 06 20:53:27 2020 +0100
@@ -21,8 +21,12 @@
 
 #include "WebAssemblyOracle.h"
 
+#include "OracleCommandExceptionMessage.h"
 #include "SleepOracleCommand.h"
-#include "OracleCommandExceptionMessage.h"
+
+#if ORTHANC_ENABLE_DCMTK == 1
+#  include "ParseDicomSuccessMessage.h"
+#endif
 
 #include <Core/OrthancException.h>
 #include <Core/Toolbox.h>
@@ -170,6 +174,10 @@
        * of the response is the same as the "Accept" header of the
        * query. This should be fixed in future versions of emscripten.
        * https://github.com/emscripten-core/emscripten/pull/8486
+       *
+       * TODO - The function "emscripten_fetch_get_response_headers()"
+       * was added to "fetch.h" at emscripten-1.38.37 on 2019-06-26.
+       * https://github.com/emscripten-core/emscripten/blob/1.38.37/system/include/emscripten/fetch.h
        **/
 
       HttpHeaders headers;
@@ -231,8 +239,21 @@
               break;
             }
 
+            case IOracleCommand::Type_ParseDicomFromWado:
+            {
+#if ORTHANC_ENABLE_DCMTK == 1
+              size_t fileSize;
+              std::auto_ptr<Orthanc::ParsedDicomFile> dicom
+                (ParseDicomSuccessMessage::ParseWadoAnswer(fileSize, answer, headers));
+              LOG(WARNING) << "bingo";
+#else
+              throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
+#endif
+              break;
+            }
+
             default:
-              LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: "
+              LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in SuccessCallback): "
                          << context->GetCommand().GetType();
           }
         }
@@ -574,8 +595,61 @@
                                   ParseDicomFromWadoCommand* command)
   {
     std::auto_ptr<ParseDicomFromWadoCommand> protection(command);
+    
+    // TODO - CACHE
 
-    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+    
+    switch (command->GetRestCommand().GetType())
+    {
+      case IOracleCommand::Type_Http:
+      {
+        const HttpCommand& rest =
+          dynamic_cast<const HttpCommand&>(protection->GetRestCommand());
+        
+        FetchCommand fetch(*this, receiver, protection.release());
+    
+        fetch.SetMethod(rest.GetMethod());
+        fetch.SetUrl(rest.GetUrl());
+        fetch.AddHttpHeaders(rest.GetHttpHeaders());
+        fetch.SetTimeout(rest.GetTimeout());
+    
+        if (rest.GetMethod() == Orthanc::HttpMethod_Post ||
+            rest.GetMethod() == Orthanc::HttpMethod_Put)
+        {
+          std::string body = rest.GetBody();
+          fetch.SetBody(body);
+        }
+    
+        fetch.Execute();
+        break;
+      }
+
+      case IOracleCommand::Type_OrthancRestApi:
+      {
+        const OrthancRestApiCommand& rest =
+          dynamic_cast<const OrthancRestApiCommand&>(protection->GetRestCommand());
+        
+        FetchCommand fetch(*this, receiver, protection.release());
+
+        fetch.SetMethod(rest.GetMethod());
+        SetOrthancUrl(fetch, rest.GetUri());
+        fetch.AddHttpHeaders(rest.GetHttpHeaders());
+        fetch.SetTimeout(rest.GetTimeout());
+
+        if (rest.GetMethod() == Orthanc::HttpMethod_Post ||
+            rest.GetMethod() == Orthanc::HttpMethod_Put)
+        {
+          std::string body = rest.GetBody();
+          fetch.SetBody(body);
+        }
+
+        fetch.Execute();
+        break;
+      }
+
+      default:
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+    }
   }
 
 
@@ -618,11 +692,17 @@
       }
             
       case IOracleCommand::Type_ParseDicomFromWado:
+#if ORTHANC_ENABLE_DCMTK == 1
         Execute(receiver, dynamic_cast<ParseDicomFromWadoCommand*>(protection.release()));
+#else
+          throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
+                                          "DCMTK must be enabled to parse DICOM files");
+#endif
         break;
             
       default:
-        LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle: " << command->GetType();
+        LOG(ERROR) << "Command type not implemented by the WebAssembly Oracle (in Schedule): "
+                   << command->GetType();
         throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
     }