changeset 4105:c02a2d9efbc2

move FromDcmtkBridge::ExecuteToDicom() to LuaFunctionCall, to remove dependency of DCMTK on Lua
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jul 2020 13:48:10 +0200
parents d5c09b5f882f
children 50cb0fb99e34
files OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h OrthancFramework/Sources/Lua/LuaFunctionCall.cpp OrthancFramework/Sources/Lua/LuaFunctionCall.h OrthancFramework/Sources/SystemToolbox.h OrthancServer/Plugins/Engine/OrthancPlugins.cpp OrthancServer/Sources/OrthancFindRequestHandler.cpp OrthancServer/Sources/OrthancInitialization.cpp OrthancServer/Sources/QueryRetrieveHandler.cpp OrthancServer/UnitTestsSources/UnitTestsMain.cpp
diffstat 11 files changed, 60 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Resources/CMake/DownloadOrthancFramework.cmake	Mon Jul 06 13:48:10 2020 +0200
@@ -438,7 +438,7 @@
 
     # Look for mandatory dependency Boost (cf. BoostConfiguration.cmake)
     include(FindBoost)
-    find_package(Boost COMPONENTS filesystem thread system date_time regex)
+    find_package(Boost COMPONENTS filesystem thread system date_time regex ${ORTHANC_BOOST_COMPONENTS})
 
     if (NOT Boost_FOUND)
       message(FATAL_ERROR "Unable to locate Boost on this system")
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -2047,46 +2047,6 @@
   }
 
 
-#if ORTHANC_ENABLE_LUA == 1
-  void FromDcmtkBridge::ExecuteToDicom(DicomMap& target,
-                                       LuaFunctionCall& call)
-  {
-    Json::Value output;
-    call.ExecuteToJson(output, true /* keep strings */);
-
-    target.Clear();
-
-    if (output.type() == Json::arrayValue &&
-        output.size() == 0)
-    {
-      // This case happens for empty tables
-      return;
-    }
-
-    if (output.type() != Json::objectValue)
-    {
-      throw OrthancException(ErrorCode_LuaBadOutput,
-                             "Lua: The script must return a table");
-    }
-
-    Json::Value::Members members = output.getMemberNames();
-
-    for (size_t i = 0; i < members.size(); i++)
-    {
-      if (output[members[i]].type() != Json::stringValue)
-      {
-        throw OrthancException(ErrorCode_LuaBadOutput,
-                               "Lua: The script must return a table "
-                               "mapping names of DICOM tags to strings");
-      }
-
-      DicomTag tag(ParseTag(members[i]));
-      target.SetValue(tag, output[members[i]].asString(), false);
-    }
-  }
-#endif
-
-
   void FromDcmtkBridge::ExtractDicomSummary(DicomMap& target, 
                                             DcmItem& dataset,
                                             const std::set<DicomTag>& ignoreTagLength)
--- a/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h	Mon Jul 06 13:48:10 2020 +0200
@@ -43,10 +43,6 @@
 #include <dcmtk/dcmdata/dcfilefo.h>
 #include <json/json.h>
 
-#if !defined(ORTHANC_ENABLE_LUA)
-#  error The macro ORTHANC_ENABLE_LUA must be defined
-#endif
-
 #if ORTHANC_ENABLE_DCMTK != 1
 #  error The macro ORTHANC_ENABLE_DCMTK must be set to 1
 #endif
@@ -55,10 +51,6 @@
 #  include <gtest/gtest_prod.h>
 #endif
 
-#if ORTHANC_ENABLE_LUA == 1
-#  include "../Lua/LuaFunctionCall.h"
-#endif
-
 #if !defined(ORTHANC_ENABLE_DCMTK_JPEG)
 #  error The macro ORTHANC_ENABLE_DCMTK_JPEG must be defined
 #endif
@@ -244,11 +236,6 @@
     static void FromJson(DicomMap& values,
                          const Json::Value& result);
 
-#if ORTHANC_ENABLE_LUA == 1
-    static void ExecuteToDicom(DicomMap& target,
-                               LuaFunctionCall& call);
-#endif
-
     static void ExtractDicomSummary(DicomMap& target, 
                                     DcmItem& dataset,
                                     const std::set<DicomTag>& ignoreTagLength);
--- a/OrthancFramework/Sources/Lua/LuaFunctionCall.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Sources/Lua/LuaFunctionCall.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -37,6 +37,10 @@
 #include "../OrthancException.h"
 #include "../Logging.h"
 
+#if ORTHANC_ENABLE_DCMTK == 1
+#  include "../DicomParsing/FromDcmtkBridge.h"
+#endif
+
 #include <cassert>
 #include <stdio.h>
 #include <boost/lexical_cast.hpp>
@@ -188,4 +192,43 @@
 
     PushJson(value);
   }
+
+
+#if ORTHANC_ENABLE_DCMTK == 1
+  void LuaFunctionCall::ExecuteToDicom(DicomMap& target)
+  {
+    Json::Value output;
+    ExecuteToJson(output, true /* keep strings */);
+    
+    target.Clear();
+
+    if (output.type() == Json::arrayValue &&
+        output.size() == 0)
+    {
+      // This case happens for empty tables
+      return;
+    }
+
+    if (output.type() != Json::objectValue)
+    {
+      throw OrthancException(ErrorCode_LuaBadOutput,
+                             "Lua: The script must return a table");
+    }
+    
+    Json::Value::Members members = output.getMemberNames();
+    
+    for (size_t i = 0; i < members.size(); i++)
+    {
+      if (output[members[i]].type() != Json::stringValue)
+      {
+        throw OrthancException(ErrorCode_LuaBadOutput,
+                               "Lua: The script must return a table "
+                               "mapping names of DICOM tags to strings");
+      }
+
+      DicomTag tag(FromDcmtkBridge::ParseTag(members[i]));
+      target.SetValue(tag, output[members[i]].asString(), false);
+    }
+  }
+#endif
 }
--- a/OrthancFramework/Sources/Lua/LuaFunctionCall.h	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Sources/Lua/LuaFunctionCall.h	Mon Jul 06 13:48:10 2020 +0200
@@ -33,6 +33,10 @@
 
 #pragma once
 
+#if !defined(ORTHANC_ENABLE_DCMTK)
+#  error The macro ORTHANC_ENABLE_DCMTK must be defined
+#endif
+
 #include "LuaContext.h"
 
 #include "../DicomFormat/DicomArray.h"
@@ -89,5 +93,9 @@
                        bool keepStrings);
 
     void ExecuteToString(std::string& result);
+
+#if ORTHANC_ENABLE_DCMTK == 1
+    void ExecuteToDicom(DicomMap& target);
+#endif
   };
 }
--- a/OrthancFramework/Sources/SystemToolbox.h	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancFramework/Sources/SystemToolbox.h	Mon Jul 06 13:48:10 2020 +0200
@@ -33,6 +33,8 @@
 
 #pragma once
 
+#include "OrthancFramework.h"  // Must be before "ORTHANC_SANDBOXED"
+
 #if !defined(ORTHANC_SANDBOXED)
 #  error The macro ORTHANC_SANDBOXED must be defined
 #endif
@@ -42,7 +44,6 @@
 #endif
 
 #include "Enumerations.h"
-#include "OrthancFramework.h"
 
 #include <map>
 #include <vector>
--- a/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancServer/Plugins/Engine/OrthancPlugins.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -58,6 +58,7 @@
 #include "../../../OrthancFramework/Sources/Images/PngReader.h"
 #include "../../../OrthancFramework/Sources/Images/PngWriter.h"
 #include "../../../OrthancFramework/Sources/Logging.h"
+#include "../../../OrthancFramework/Sources/Lua/LuaFunctionCall.h"
 #include "../../../OrthancFramework/Sources/MetricsRegistry.h"
 #include "../../../OrthancFramework/Sources/OrthancException.h"
 #include "../../../OrthancFramework/Sources/SerializationToolbox.h"
--- a/OrthancServer/Sources/OrthancFindRequestHandler.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancServer/Sources/OrthancFindRequestHandler.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -478,7 +478,7 @@
       LuaFunctionCall call(lock.GetLua(), LUA_CALLBACK);
       call.PushDicom(source);
       call.PushJson(origin);
-      FromDcmtkBridge::ExecuteToDicom(target, call);
+      call.ExecuteToDicom(target);
 
       return true;
     }
--- a/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancServer/Sources/OrthancInitialization.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -42,6 +42,7 @@
 
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../OrthancFramework/Sources/FileStorage/FilesystemStorage.h"
+#include "../../OrthancFramework/Sources/HttpClient.h"
 #include "../../OrthancFramework/Sources/Logging.h"
 #include "../../OrthancFramework/Sources/OrthancException.h"
 
--- a/OrthancServer/Sources/QueryRetrieveHandler.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancServer/Sources/QueryRetrieveHandler.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -39,6 +39,7 @@
 #include "../../OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../OrthancFramework/Sources/Logging.h"
+#include "../../OrthancFramework/Sources/Lua/LuaFunctionCall.h"
 #include "LuaScripting.h"
 #include "ServerContext.h"
 
@@ -58,7 +59,7 @@
       LuaFunctionCall call(lock.GetLua(), LUA_CALLBACK);
       call.PushDicom(query);
       call.PushJson(modality);
-      FromDcmtkBridge::ExecuteToDicom(query, call);
+      call.ExecuteToDicom(query);
     }
   }
 
--- a/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Mon Jul 06 11:45:39 2020 +0200
+++ b/OrthancServer/UnitTestsSources/UnitTestsMain.cpp	Mon Jul 06 13:48:10 2020 +0200
@@ -34,6 +34,7 @@
 #include "PrecompiledHeadersUnitTests.h"
 #include <gtest/gtest.h>
 
+#include "../../OrthancFramework/Sources/DicomFormat/DicomArray.h"
 #include "../../OrthancFramework/Sources/DicomParsing/FromDcmtkBridge.h"
 #include "../../OrthancFramework/Sources/DicomParsing/ParsedDicomFile.h"
 #include "../../OrthancFramework/Sources/DicomParsing/ToDcmtkBridge.h"