changeset 933:f75f6cb69c1b

Commented-out traces for debug
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 26 Jul 2019 20:09:42 +0200
parents 061a58c0011a
children 094d10ed7ec2
files Framework/Loaders/LoaderCache.cpp Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp Framework/Oracle/WebAssemblyOracle.cpp
diffstat 3 files changed, 90 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Loaders/LoaderCache.cpp	Wed Jul 24 18:46:25 2019 +0200
+++ b/Framework/Loaders/LoaderCache.cpp	Fri Jul 26 20:09:42 2019 +0200
@@ -59,6 +59,7 @@
   {
     try
     {
+      
       // normalize keys a little
       seriesUuid = Orthanc::Toolbox::StripSpaces(seriesUuid);
       Orthanc::Toolbox::ToLowerCase(seriesUuid);
@@ -66,14 +67,15 @@
       // find in cache
       if (seriesVolumeProgressiveLoaders_.find(seriesUuid) == seriesVolumeProgressiveLoaders_.end())
       {
+//        LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : CACHEMISS --> need to load seriesUUid = " << seriesUuid;
 #if ORTHANC_ENABLE_WASM == 1
-        LOG(WARNING) << "Performing request for series " << seriesUuid << " sbrk(0) = " << sbrk(0);
+//        LOG(TRACE) << "Performing request for series " << seriesUuid << " sbrk(0) = " << sbrk(0);
 #else
-        LOG(WARNING) << "Performing request for series " << seriesUuid;
+//        LOG(TRACE) << "Performing request for series " << seriesUuid;
 #endif
         boost::shared_ptr<DicomVolumeImage> volumeImage(new DicomVolumeImage);
         boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> loader;
-
+//        LOG(TRACE) << "volumeImage = " << volumeImage.get();
         {
 #if ORTHANC_ENABLE_WASM == 1
           loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, oracle_));
@@ -81,10 +83,16 @@
           LockingEmitter::WriterLock lock(lockingEmitter_);
           loader.reset(new OrthancSeriesVolumeProgressiveLoader(volumeImage, oracle_, lock.GetOracleObservable()));
 #endif
+//          LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : loader = " << loader.get();
           loader->LoadSeries(seriesUuid);
+//          LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : loader->LoadSeries successful";
         }
         seriesVolumeProgressiveLoaders_[seriesUuid] = loader;
       }
+      else
+      {
+//        LOG(TRACE) << "LoaderCache::GetSeriesVolumeProgressiveLoader : returning cached loader for seriesUUid = " << seriesUuid;
+      }
       return seriesVolumeProgressiveLoaders_[seriesUuid];
     }
     catch (const Orthanc::OrthancException& e)
--- a/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Wed Jul 24 18:46:25 2019 +0200
+++ b/Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.cpp	Fri Jul 26 20:09:42 2019 +0200
@@ -450,8 +450,10 @@
 
   void OrthancSeriesVolumeProgressiveLoader::LoadSeries(const std::string& seriesId)
   {
+//    LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries seriesId=" << seriesId;
     if (active_)
     {
+//      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries NOT ACTIVE! --> ERROR";
       throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
     }
     else
@@ -461,7 +463,9 @@
       std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
       command->SetUri("/series/" + seriesId + "/instances-tags");
 
+//      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries about to call oracle_.Schedule";
       oracle_.Schedule(*this, command.release());
+//      LOG(TRACE) << "OrthancSeriesVolumeProgressiveLoader::LoadSeries called oracle_.Schedule";
     }
   }
   
--- a/Framework/Oracle/WebAssemblyOracle.cpp	Wed Jul 24 18:46:25 2019 +0200
+++ b/Framework/Oracle/WebAssemblyOracle.cpp	Fri Jul 26 20:09:42 2019 +0200
@@ -153,6 +153,10 @@
        **/
       
       std::auto_ptr<FetchContext> context(reinterpret_cast<FetchContext*>(fetch->userData));
+      if (fetch->userData == NULL)
+      {
+        LOG(ERROR) << "WebAssemblyOracle::FetchContext::SuccessCallback fetch->userData is NULL!!!!!!!";
+      }
 
       std::string answer;
       if (fetch->numBytes > 0)
@@ -170,12 +174,14 @@
        **/
 
       HttpHeaders headers;
-      if (!context->GetExpectedContentType().empty())
+      if (fetch->userData != NULL)
       {
-        headers["Content-Type"] = context->GetExpectedContentType();
+        if (!context->GetExpectedContentType().empty())
+        {
+          headers["Content-Type"] = context->GetExpectedContentType();
+        }
       }
       
-      
       emscripten_fetch_close(fetch);
 
 
@@ -394,22 +400,53 @@
   void WebAssemblyOracle::Execute(const IObserver& receiver,
                                   OrthancRestApiCommand* command)
   {
-    FetchCommand fetch(*this, receiver, command);
+    try
+    {
+      //LOG(TRACE) << "*********** WebAssemblyOracle::Execute.";
+      //LOG(TRACE) << "WebAssemblyOracle::Execute | command = " << command;
+      FetchCommand fetch(*this, receiver, command);
+
+      fetch.SetMethod(command->GetMethod());
+      fetch.SetUri(command->GetUri());
+      fetch.SetHttpHeaders(command->GetHttpHeaders());
+      fetch.SetTimeout(command->GetTimeout());
+
+      if (command->GetMethod() == Orthanc::HttpMethod_Post ||
+        command->GetMethod() == Orthanc::HttpMethod_Put)
+      {
+        std::string body;
+        command->SwapBody(body);
+        fetch.SetBody(body);
+      }
 
-    fetch.SetMethod(command->GetMethod());
-    fetch.SetUri(command->GetUri());
-    fetch.SetHttpHeaders(command->GetHttpHeaders());
-    fetch.SetTimeout(command->GetTimeout());
-      
-    if (command->GetMethod() == Orthanc::HttpMethod_Post ||
-        command->GetMethod() == Orthanc::HttpMethod_Put)
+      fetch.Execute();
+      //LOG(TRACE) << "*********** successful end of WebAssemblyOracle::Execute.";
+    }
+    catch (const Orthanc::OrthancException& e)
     {
-      std::string body;
-      command->SwapBody(body);
-      fetch.SetBody(body);
+      if (e.HasDetails())
+      {
+        LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What() << " Details: " << e.GetDetails();
+      }
+      else
+      {
+        LOG(ERROR) << "OrthancException in WebAssemblyOracle::Execute: " << e.What();
+      }
+      //LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
+      throw;
     }
-
-    fetch.Execute();
+    catch (const std::exception& e)
+    {
+      LOG(ERROR) << "std::exception in WebAssemblyOracle::Execute: " << e.what();
+//       LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
+      throw;
+    }
+    catch (...)
+    {
+      LOG(ERROR) << "Unknown exception in WebAssemblyOracle::Execute";
+//       LOG(TRACE) << "*********** failing end of WebAssemblyOracle::Execute.";
+      throw;
+    }
   }
     
     
@@ -453,14 +490,36 @@
     switch (command->GetType())
     {
       case IOracleCommand::Type_OrthancRestApi:
+        //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
+        //{
+        //  const IObserver* pReceiver = &receiver;
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule | pReceiver is " << pReceiver;
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule | command = " << command;
+        //  OrthancRestApiCommand* rac = dynamic_cast<OrthancRestApiCommand*>(protection.get());
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule | typed command = " << rac;
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
+        //}
+        //// END OF BLOCK TO REMOVE
         Execute(receiver, dynamic_cast<OrthancRestApiCommand*>(protection.release()));
         break;
         
       case IOracleCommand::Type_GetOrthancImage:
+        //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
+        //{
+        //  GetOrthancImageCommand* rac = dynamic_cast<GetOrthancImageCommand*>(protection.get());
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
+        //}
+        //// END OF BLOCK TO REMOVE
         Execute(receiver, dynamic_cast<GetOrthancImageCommand*>(protection.release()));
         break;
 
       case IOracleCommand::Type_GetOrthancWebViewerJpeg:
+        //// DIAGNOSTIC. PLEASE REMOVE IF IT HAS BEEN COMMITTED BY MISTAKE
+        //{
+        //  GetOrthancWebViewerJpegCommand* rac = dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.get());
+        //  LOG(TRACE) << "WebAssemblyOracle::Schedule" << rac->GetUri();
+        //}
+        //// END OF BLOCK TO REMOVE
         Execute(receiver, dynamic_cast<GetOrthancWebViewerJpegCommand*>(protection.release()));
         break;