changeset 54:06847108819c

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Nov 2016 12:59:50 +0100
parents 175d06fa292e
children b6432a00b103
files Framework/Orthanc/Core/Images/IImageWriter.cpp Framework/Orthanc/Core/Images/IImageWriter.h Framework/Orthanc/Core/Images/JpegReader.cpp Framework/Orthanc/Core/Images/JpegReader.h Framework/Orthanc/Core/Images/JpegWriter.cpp Framework/Orthanc/Core/Images/JpegWriter.h Framework/Orthanc/Core/Images/PngReader.cpp Framework/Orthanc/Core/Images/PngReader.h Framework/Orthanc/Core/Images/PngWriter.cpp Framework/Orthanc/Core/Images/PngWriter.h Framework/Orthanc/Core/SystemToolbox.cpp Framework/Orthanc/Core/SystemToolbox.h Framework/Orthanc/Core/TemporaryFile.cpp Framework/Orthanc/Core/Toolbox.cpp Framework/Orthanc/Core/Toolbox.h Framework/Orthanc/OrthancServer/FromDcmtkBridge.cpp Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h Framework/Orthanc/Resources/CMake/Compiler.cmake Framework/Orthanc/Resources/EmbedResources.py
diffstat 20 files changed, 141 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Orthanc/Core/Images/IImageWriter.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/IImageWriter.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -32,18 +32,13 @@
 
 #include "IImageWriter.h"
 
-#include "../OrthancException.h"
-
-#if !defined(ORTHANC_SANDBOXED)
-#  error The macro ORTHANC_SANDBOXED must be defined
-#endif
-
 #if ORTHANC_SANDBOXED == 0
 #  include "../SystemToolbox.h"
 #endif
 
 namespace Orthanc
 {
+#if ORTHANC_SANDBOXED == 0
   void IImageWriter::WriteToFileInternal(const std::string& path,
                                          unsigned int width,
                                          unsigned int height,
@@ -51,12 +46,9 @@
                                          PixelFormat format,
                                          const void* buffer)
   {
-#if ORTHANC_SANDBOXED == 0
     std::string compressed;
     WriteToMemoryInternal(compressed, width, height, pitch, format, buffer);
     SystemToolbox::WriteFile(compressed, path);
-#else
-    throw OrthancException(ErrorCode_CannotWriteFile);  // Unavailable in sandboxed environments
+  }
 #endif
-  }
 }
--- a/Framework/Orthanc/Core/Images/IImageWriter.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/IImageWriter.h	Thu Nov 24 12:59:50 2016 +0100
@@ -36,6 +36,10 @@
 
 #include <boost/noncopyable.hpp>
 
+#if !defined(ORTHANC_SANDBOXED)
+#  error The macro ORTHANC_SANDBOXED must be defined
+#endif
+
 namespace Orthanc
 {
   class IImageWriter : public boost::noncopyable
@@ -48,12 +52,14 @@
                                        PixelFormat format,
                                        const void* buffer) = 0;
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToFileInternal(const std::string& path,
                                      unsigned int width,
                                      unsigned int height,
                                      unsigned int pitch,
                                      PixelFormat format,
                                      const void* buffer);
+#endif
 
   public:
     virtual ~IImageWriter()
@@ -67,11 +73,13 @@
                             accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToFile(const std::string& path,
                              const ImageAccessor& accessor)
     {
       WriteToFileInternal(path, accessor.GetWidth(), accessor.GetHeight(),
                           accessor.GetPitch(), accessor.GetFormat(), accessor.GetConstBuffer());
     }
+#endif
   };
 }
--- a/Framework/Orthanc/Core/Images/JpegReader.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/JpegReader.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -36,7 +36,11 @@
 #include "JpegErrorManager.h"
 #include "../OrthancException.h"
 #include "../Logging.h"
-#include "../SystemToolbox.h"
+
+#if ORTHANC_SANDBOXED == 0
+#  include "../SystemToolbox.h"
+#endif
+
 
 namespace Orthanc
 {
@@ -94,6 +98,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void JpegReader::ReadFromFile(const std::string& filename)
   {
     FILE* fp = SystemToolbox::OpenFile(filename, FileMode_ReadBinary);
@@ -135,6 +140,7 @@
     jpeg_destroy_decompress(&cinfo);
     fclose(fp);
   }
+#endif
 
 
   void JpegReader::ReadFromMemory(const void* buffer,
--- a/Framework/Orthanc/Core/Images/JpegReader.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/JpegReader.h	Thu Nov 24 12:59:50 2016 +0100
@@ -37,6 +37,10 @@
 #include <string>
 #include <boost/noncopyable.hpp>
 
+#if !defined(ORTHANC_SANDBOXED)
+#  error The macro ORTHANC_SANDBOXED must be defined
+#endif
+
 namespace Orthanc
 {
   class JpegReader : 
@@ -47,7 +51,9 @@
     std::string  content_;
 
   public:
+#if ORTHANC_SANDBOXED == 0
     void ReadFromFile(const std::string& filename);
+#endif
 
     void ReadFromMemory(const void* buffer,
                         size_t size);
--- a/Framework/Orthanc/Core/Images/JpegWriter.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/JpegWriter.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -35,9 +35,11 @@
 
 #include "../OrthancException.h"
 #include "../Logging.h"
-#include "../SystemToolbox.h"
+#include "JpegErrorManager.h"
 
-#include "JpegErrorManager.h"
+#if ORTHANC_SANDBOXED == 0
+#  include "../SystemToolbox.h"
+#endif
 
 #include <stdlib.h>
 #include <vector>
@@ -112,6 +114,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void JpegWriter::WriteToFileInternal(const std::string& filename,
                                        unsigned int width,
                                        unsigned int height,
@@ -155,6 +158,7 @@
 
     fclose(fp);
   }
+#endif
 
 
   void JpegWriter::WriteToMemoryInternal(std::string& jpeg,
--- a/Framework/Orthanc/Core/Images/JpegWriter.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/JpegWriter.h	Thu Nov 24 12:59:50 2016 +0100
@@ -46,12 +46,14 @@
                                      PixelFormat format,
                                      const void* buffer);
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToMemoryInternal(std::string& jpeg,
                                        unsigned int width,
                                        unsigned int height,
                                        unsigned int pitch,
                                        PixelFormat format,
                                        const void* buffer);
+#endif
 
   private:
     uint8_t  quality_;
--- a/Framework/Orthanc/Core/Images/PngReader.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/PngReader.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -34,14 +34,18 @@
 #include "PngReader.h"
 
 #include "../OrthancException.h"
-#include "../SystemToolbox.h"
 #include "../Toolbox.h"
 
+#if ORTHANC_SANDBOXED == 0
+#  include "../SystemToolbox.h"
+#endif
+
 #include <png.h>
 #include <string.h>  // For memcpy()
 
 namespace Orthanc
 {
+#if ORTHANC_SANDBOXED == 0
   namespace 
   {
     struct FileRabi
@@ -66,6 +70,7 @@
       }
     };
   }
+#endif
 
 
   struct PngReader::PngRabi
@@ -207,6 +212,8 @@
     AssignWritable(format, width, height, pitch, &data_[0]);
   }
 
+
+#if ORTHANC_SANDBOXED == 0
   void PngReader::ReadFromFile(const std::string& filename)
   {
     FileRabi f(filename.c_str());
@@ -231,6 +238,7 @@
 
     Read(rabi);
   }
+#endif
 
 
   namespace
--- a/Framework/Orthanc/Core/Images/PngReader.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/PngReader.h	Thu Nov 24 12:59:50 2016 +0100
@@ -41,6 +41,10 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/noncopyable.hpp>
 
+#if !defined(ORTHANC_SANDBOXED)
+#  error The macro ORTHANC_SANDBOXED must be defined
+#endif
+
 namespace Orthanc
 {
   class PngReader : 
@@ -59,7 +63,9 @@
   public:
     PngReader();
 
+#if ORTHANC_SANDBOXED == 0
     void ReadFromFile(const std::string& filename);
+#endif
 
     void ReadFromMemory(const void* buffer,
                         size_t size);
--- a/Framework/Orthanc/Core/Images/PngWriter.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/PngWriter.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -39,7 +39,10 @@
 #include "../OrthancException.h"
 #include "../ChunkedBuffer.h"
 #include "../Toolbox.h"
-#include "../SystemToolbox.h"
+
+#if ORTHANC_SANDBOXED == 0
+#  include "../SystemToolbox.h"
+#endif
 
 
 // http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-4
@@ -203,6 +206,7 @@
   }
 
 
+#if ORTHANC_SANDBOXED == 0
   void PngWriter::WriteToFileInternal(const std::string& filename,
                                       unsigned int width,
                                       unsigned int height,
@@ -230,7 +234,7 @@
 
     fclose(fp);
   }
-
+#endif
 
 
   static void MemoryCallback(png_structp png_ptr, 
--- a/Framework/Orthanc/Core/Images/PngWriter.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Images/PngWriter.h	Thu Nov 24 12:59:50 2016 +0100
@@ -48,12 +48,14 @@
                                      PixelFormat format,
                                      const void* buffer);
 
+#if ORTHANC_SANDBOXED == 0
     virtual void WriteToMemoryInternal(std::string& png,
                                        unsigned int width,
                                        unsigned int height,
                                        unsigned int pitch,
                                        PixelFormat format,
                                        const void* buffer);
+#endif
 
   private:
     struct PImpl;
--- a/Framework/Orthanc/Core/SystemToolbox.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/SystemToolbox.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -35,30 +35,45 @@
 
 
 #if BOOST_HAS_DATE_TIME == 1
-#include <boost/date_time/posix_time/posix_time.hpp>
+#  include <boost/date_time/posix_time/posix_time.hpp>
 #endif
 
 
 #if defined(_WIN32)
-#include <windows.h>
-#include <process.h>   // For "_spawnvp()" and "_getpid()"
+#  include <windows.h>
+#  include <process.h>   // For "_spawnvp()" and "_getpid()"
 #else
-#include <unistd.h>    // For "execvp()"
-#include <sys/wait.h>  // For "waitpid()"
+#  include <unistd.h>    // For "execvp()"
+#  include <sys/wait.h>  // For "waitpid()"
 #endif
 
+
 #if defined(__APPLE__) && defined(__MACH__)
-#include <mach-o/dyld.h> /* _NSGetExecutablePath */
-#include <limits.h>      /* PATH_MAX */
+#  include <mach-o/dyld.h> /* _NSGetExecutablePath */
+#  include <limits.h>      /* PATH_MAX */
 #endif
 
+
 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-#include <limits.h>      /* PATH_MAX */
-#include <signal.h>
-#include <unistd.h>
+#  include <limits.h>      /* PATH_MAX */
+#  include <signal.h>
+#  include <unistd.h>
 #endif
 
 
+// Inclusions for UUID
+// http://stackoverflow.com/a/1626302
+
+extern "C"
+{
+#ifdef WIN32
+#  include <rpc.h>
+#else
+#  include <uuid/uuid.h>
+#endif
+}
+
+
 #include "Logging.h"
 #include "OrthancException.h"
 #include "Toolbox.h"
@@ -477,6 +492,28 @@
   }
 
 
+  std::string SystemToolbox::GenerateUuid()
+  {
+#ifdef WIN32
+    UUID uuid;
+    UuidCreate ( &uuid );
+
+    unsigned char * str;
+    UuidToStringA ( &uuid, &str );
+
+    std::string s( ( char* ) str );
+
+    RpcStringFreeA ( &str );
+#else
+    uuid_t uuid;
+    uuid_generate_random ( uuid );
+    char s[37];
+    uuid_unparse ( uuid, s );
+#endif
+    return s;
+  }
+
+
 #if BOOST_HAS_DATE_TIME == 1
   std::string SystemToolbox::GetNowIsoString()
   {
--- a/Framework/Orthanc/Core/SystemToolbox.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/SystemToolbox.h	Thu Nov 24 12:59:50 2016 +0100
@@ -90,6 +90,8 @@
     FILE* OpenFile(const std::string& path,
                    FileMode mode);
 
+    std::string GenerateUuid();
+
 #if BOOST_HAS_DATE_TIME == 1
     std::string GetNowIsoString();
 
--- a/Framework/Orthanc/Core/TemporaryFile.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/TemporaryFile.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -51,7 +51,7 @@
 #endif
 
     // We use UUID to create unique path to temporary files
-    std::string filename = "Orthanc-" + Orthanc::Toolbox::GenerateUuid();
+    std::string filename = "Orthanc-" + Orthanc::SystemToolbox::GenerateUuid();
 
     if (extension != NULL)
     {
--- a/Framework/Orthanc/Core/Toolbox.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Toolbox.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -77,18 +77,9 @@
 #endif
 
 
-
-// Inclusions for UUID
-// http://stackoverflow.com/a/1626302
-
-extern "C"
-{
-#ifdef WIN32
-#  include <rpc.h>
-#else
-#  include <uuid/uuid.h>
+#if defined(_WIN32)
+#  include <windows.h>   // For ::Sleep
 #endif
-}
 
 
 #if ORTHANC_ENABLE_PUGIXML == 1
@@ -1226,28 +1217,6 @@
   }
 
 
-  std::string Toolbox::GenerateUuid()
-  {
-#ifdef WIN32
-    UUID uuid;
-    UuidCreate ( &uuid );
-
-    unsigned char * str;
-    UuidToStringA ( &uuid, &str );
-
-    std::string s( ( char* ) str );
-
-    RpcStringFreeA ( &str );
-#else
-    uuid_t uuid;
-    uuid_generate_random ( uuid );
-    char s[37];
-    uuid_unparse ( uuid, s );
-#endif
-    return s;
-  }
-
-
   bool Toolbox::IsUuid(const std::string& str)
   {
     if (str.size() != 36)
--- a/Framework/Orthanc/Core/Toolbox.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Core/Toolbox.h	Thu Nov 24 12:59:50 2016 +0100
@@ -204,8 +204,6 @@
                                              const std::string& key,
                                              unsigned int defaultValue);
 
-    std::string GenerateUuid();
-
     bool IsUuid(const std::string& str);
 
     bool StartsWithUuid(const std::string& str);
--- a/Framework/Orthanc/OrthancServer/FromDcmtkBridge.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/OrthancServer/FromDcmtkBridge.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -39,6 +39,7 @@
 #include "FromDcmtkBridge.h"
 #include "ToDcmtkBridge.h"
 #include "../Core/Logging.h"
+#include "../Core/SystemToolbox.h"
 #include "../Core/Toolbox.h"
 #include "../Core/TemporaryFile.h"
 #include "../Core/OrthancException.h"
@@ -1119,7 +1120,7 @@
         // The "PatientID" field is of type LO (Long String), 64
         // Bytes Maximum. An UUID is of length 36, thus it can be used
         // as a random PatientID.
-        return Toolbox::GenerateUuid();
+        return SystemToolbox::GenerateUuid();
 
       case ResourceType_Instance:
         return dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
--- a/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.cpp	Thu Nov 24 12:59:50 2016 +0100
@@ -368,6 +368,15 @@
   }
 
 
+  bool OrthancConfiguration::IsSection(const std::string& key) const
+  {
+    assert(configuration_.type() == Json::objectValue);
+
+    return (configuration_.isMember(key) &&
+            configuration_[key].type() == Json::objectValue);
+  }
+
+
   void OrthancConfiguration::GetSection(OrthancConfiguration& target,
                                         const std::string& key) const
   {
--- a/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Plugins/Samples/Common/OrthancPluginCppWrapper.h	Thu Nov 24 12:59:50 2016 +0100
@@ -191,7 +191,7 @@
   {
   private:
     OrthancPluginContext*  context_;
-    Json::Value            configuration_;
+    Json::Value            configuration_;  // Necessarily a Json::objectValue
     std::string            path_;
 
     std::string GetPath(const std::string& key) const;
@@ -210,6 +210,8 @@
       return configuration_;
     }
 
+    bool IsSection(const std::string& key) const;
+
     void GetSection(OrthancConfiguration& target,
                     const std::string& key) const;
 
--- a/Framework/Orthanc/Resources/CMake/Compiler.cmake	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Resources/CMake/Compiler.cmake	Thu Nov 24 12:59:50 2016 +0100
@@ -164,6 +164,23 @@
 endif()
 
 
+if (DEFINED ENABLE_PROFILING AND ENABLE_PROFILING)
+  if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
+    message(WARNING "Enabling profiling on a non-debug build will not produce full information")
+  endif()
+
+  if (CMAKE_COMPILER_IS_GNUCXX)
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
+    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
+    set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -pg")
+    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
+  else()
+    message(FATAL_ERROR "Don't know how to enable profiling on your configuration")
+  endif()
+endif()
+
+
 if (STATIC_BUILD)
   add_definitions(-DORTHANC_STATIC=1)
 else()
--- a/Framework/Orthanc/Resources/EmbedResources.py	Thu Nov 17 15:47:09 2016 +0100
+++ b/Framework/Orthanc/Resources/EmbedResources.py	Thu Nov 24 12:59:50 2016 +0100
@@ -159,6 +159,10 @@
 #include <string>
 #include <list>
 
+#if defined(_MSC_VER)
+#  pragma warning(disable: 4065)  // "Switch statement contains 'default' but no 'case' labels"
+#endif
+
 namespace %s
 {
   namespace EmbeddedResources