changeset 92:4b0e0f7c9957

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 23 Dec 2016 16:06:05 +0100
parents 8fd5bf76bb8e
children 14146ecd1688
files Applications/CMakeLists.txt Resources/Orthanc/Core/Logging.cpp Resources/Orthanc/Core/Logging.h Resources/Orthanc/Core/SystemToolbox.cpp Resources/Orthanc/Core/SystemToolbox.h Resources/Orthanc/Core/Toolbox.cpp Resources/Orthanc/Core/Toolbox.h Resources/Orthanc/Core/WebServiceParameters.cpp Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake ViewerPlugin/CMakeLists.txt
diffstat 10 files changed, 150 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/Applications/CMakeLists.txt	Thu Dec 22 20:18:34 2016 +0100
+++ b/Applications/CMakeLists.txt	Fri Dec 23 16:06:05 2016 +0100
@@ -84,6 +84,7 @@
   -DORTHANC_ENABLE_DCMTK=1
   -DORTHANC_ENABLE_JPEG=0       # Disable DCMTK's support for JPEG
   -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_LOGGING_PLUGIN=0
   -DORTHANC_ENABLE_LUA=0        # For FromDcmtkBridge
   -DORTHANC_ENABLE_MD5=0
   -DORTHANC_ENABLE_PKCS11=0
--- a/Resources/Orthanc/Core/Logging.cpp	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/Logging.cpp	Fri Dec 23 16:06:05 2016 +0100
@@ -73,7 +73,74 @@
   }
 }
 
-#else
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+/*********************************************************
+ * Logger compatible with the Orthanc plugin SDK
+ *********************************************************/
+
+#include <boost/lexical_cast.hpp>
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    static OrthancPluginContext* context_ = NULL;
+
+    void Initialize(OrthancPluginContext* context)
+    {
+      context_ = context_;
+    }
+
+    InternalLogger::InternalLogger(const char* level,
+                                   const char* file  /* ignored */,
+                                   int line  /* ignored */) :
+      level_(level)
+    {
+    }
+
+    InternalLogger::~InternalLogger()
+    {
+      if (context_ != NULL)
+      {
+        if (level_ == "ERROR")
+        {
+          OrthancPluginLogError(context_, message_.c_str());
+        }
+        else if (level_ == "WARNING")
+        {
+          OrthancPluginLogWarning(context_, message_.c_str());
+        }
+        else if (level_ == "INFO")
+        {
+          OrthancPluginLogInfo(context_, message_.c_str());
+        }
+      }
+    }
+
+    InternalLogger& InternalLogger::operator<< (const std::string& message)
+    {
+      message_ += message;
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (const char* message)
+    {
+      message_ += std::string(message);
+      return *this;
+    }
+
+    InternalLogger& InternalLogger::operator<< (int message)
+    {
+      message_ += boost::lexical_cast<std::string>(message);
+      return *this;
+    }
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 /*********************************************************
  * Internal logger of Orthanc, that mimics some
--- a/Resources/Orthanc/Core/Logging.h	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/Logging.h	Fri Dec 23 16:06:05 2016 +0100
@@ -38,11 +38,27 @@
 #  error The macro ORTHANC_ENABLE_LOGGING must be defined
 #endif
 
+#if !defined(ORTHANC_ENABLE_LOGGING_PLUGIN)
+#  if ORTHANC_ENABLE_LOGGING == 1
+#    error The macro ORTHANC_ENABLE_LOGGING_PLUGIN must be defined
+#  else
+#    define ORTHANC_ENABLE_LOGGING_PLUGIN 0
+#  endif
+#endif
+
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+#  include <orthanc/OrthancCPlugin.h>
+#endif
+
 namespace Orthanc
 {
   namespace Logging
   {
+#if ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+    void Initialize(OrthancPluginContext* context);
+#else
     void Initialize();
+#endif
 
     void Finalize();
 
@@ -86,7 +102,41 @@
 #  define LOG(level)   ::Orthanc::Logging::NullStream()
 #  define VLOG(level)  ::Orthanc::Logging::NullStream()
 
-#else  /* ORTHANC_ENABLE_LOGGING == 1 */
+
+#elif ORTHANC_ENABLE_LOGGING_PLUGIN == 1
+
+#  include <boost/noncopyable.hpp>
+#  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
+#  define VLOG(level) ::Orthanc::Logging::InternalLogger("TRACE", __FILE__, __LINE__)
+
+namespace Orthanc
+{
+  namespace Logging
+  {
+    class InternalLogger : public boost::noncopyable
+    {
+    private:
+      std::string level_;
+      std::string message_;
+
+    public:
+      InternalLogger(const char* level,
+                     const char* file,
+                     int line);
+
+      ~InternalLogger();
+      
+      InternalLogger& operator<< (const std::string& message);
+
+      InternalLogger& operator<< (const char* message);
+
+      InternalLogger& operator<< (int message);
+    };
+  }
+}
+
+
+#else  /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */
 
 #  include <boost/thread/mutex.hpp>
 #  define LOG(level)  ::Orthanc::Logging::InternalLogger(#level,  __FILE__, __LINE__)
--- a/Resources/Orthanc/Core/SystemToolbox.cpp	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/SystemToolbox.cpp	Fri Dec 23 16:06:05 2016 +0100
@@ -123,7 +123,7 @@
     barrierEvent_ = ServerBarrierEvent_Stop;
     while (!(*stopFlag || finish_))
     {
-      Toolbox::USleep(100 * 1000);
+      SystemToolbox::USleep(100 * 1000);
     }
 
 #if defined(_WIN32)
@@ -152,6 +152,18 @@
   }
 
 
+  void SystemToolbox::USleep(uint64_t microSeconds)
+  {
+#if defined(_WIN32)
+    ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
+#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__)
+    usleep(microSeconds);
+#else
+#error Support your platform here
+#endif
+  }
+
+
   static std::streamsize GetStreamSize(std::istream& f)
   {
     // http://www.cplusplus.com/reference/iostream/istream/tellg/
--- a/Resources/Orthanc/Core/SystemToolbox.h	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/SystemToolbox.h	Fri Dec 23 16:06:05 2016 +0100
@@ -50,6 +50,8 @@
 {
   namespace SystemToolbox
   {
+    void USleep(uint64_t microSeconds);
+
     ServerBarrierEvent ServerBarrier(const bool& stopFlag);
 
     ServerBarrierEvent ServerBarrier();
--- a/Resources/Orthanc/Core/Toolbox.cpp	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/Toolbox.cpp	Fri Dec 23 16:06:05 2016 +0100
@@ -90,18 +90,6 @@
 
 namespace Orthanc
 {
-  void Toolbox::USleep(uint64_t microSeconds)
-  {
-#if defined(_WIN32)
-    ::Sleep(static_cast<DWORD>(microSeconds / static_cast<uint64_t>(1000)));
-#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__native_client__)
-    usleep(microSeconds);
-#else
-#error Support your platform here
-#endif
-  }
-
-
   void Toolbox::ToUpperCase(std::string& s)
   {
     std::transform(s.begin(), s.end(), s.begin(), toupper);
--- a/Resources/Orthanc/Core/Toolbox.h	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/Toolbox.h	Fri Dec 23 16:06:05 2016 +0100
@@ -78,8 +78,6 @@
 
   namespace Toolbox
   {
-    void USleep(uint64_t microSeconds);
-
     void ToUpperCase(std::string& s);  // Inplace version
 
     void ToLowerCase(std::string& s);  // Inplace version
--- a/Resources/Orthanc/Core/WebServiceParameters.cpp	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Core/WebServiceParameters.cpp	Fri Dec 23 16:06:05 2016 +0100
@@ -34,7 +34,6 @@
 #include "WebServiceParameters.h"
 
 #include "../Core/Logging.h"
-#include "../Core/Toolbox.h"
 #include "../Core/OrthancException.h"
 
 #if ORTHANC_SANDBOXED == 0
--- a/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake	Thu Dec 22 20:18:34 2016 +0100
+++ b/Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake	Fri Dec 23 16:06:05 2016 +0100
@@ -99,6 +99,13 @@
       -DBOOST_LOCALE_NO_POSIX_BACKEND=1
       -DBOOST_LOCALE_NO_STD_BACKEND=1
       )
+
+  elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
+    add_definitions(
+      -DBOOST_LOCALE_NO_POSIX_BACKEND=1
+      -DBOOST_LOCALE_NO_STD_BACKEND=1
+      )
+
   else()
     message(FATAL_ERROR "Support your platform here")
   endif()
@@ -114,10 +121,15 @@
   list(APPEND BOOST_SOURCES
     ${BOOST_REGEX_SOURCES}
     ${BOOST_SOURCES_DIR}/libs/date_time/src/gregorian/greg_month.cpp
-    ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp
     ${BOOST_SOURCES_DIR}/libs/system/src/error_code.cpp
     )
 
+  if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
+    list(APPEND BOOST_SOURCES
+      ${BOOST_SOURCES_DIR}/libs/locale/src/encoding/codepage.cpp
+      )
+  endif()
+
   if (${CMAKE_SYSTEM_NAME} STREQUAL "PNaCl" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl32" OR
       ${CMAKE_SYSTEM_NAME} STREQUAL "NaCl64")
--- a/ViewerPlugin/CMakeLists.txt	Thu Dec 22 20:18:34 2016 +0100
+++ b/ViewerPlugin/CMakeLists.txt	Fri Dec 23 16:06:05 2016 +0100
@@ -61,7 +61,8 @@
   -DORTHANC_ENABLE_BASE64=0
   -DORTHANC_ENABLE_CURL=0
   -DORTHANC_ENABLE_DCMTK=0
-  -DORTHANC_ENABLE_LOGGING=0
+  -DORTHANC_ENABLE_LOGGING=1
+  -DORTHANC_ENABLE_LOGGING_PLUGIN=1
   -DORTHANC_ENABLE_MD5=0
   -DORTHANC_ENABLE_PUGIXML=0
   -DORTHANC_SANDBOXED=0