# HG changeset patch # User Sebastien Jodogne # Date 1482505565 -3600 # Node ID 4b0e0f7c99571bb77a9364ef2cf082cf0b4165f0 # Parent 8fd5bf76bb8ea010dfb25ad77d2e9d5403fcdffa sync diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Applications/CMakeLists.txt --- 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 diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/Logging.cpp --- 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 + +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(message); + return *this; + } + } +} + + +#else /* ORTHANC_ENABLE_LOGGING_PLUGIN == 0 && ORTHANC_ENABLE_LOGGING == 1 */ /********************************************************* * Internal logger of Orthanc, that mimics some diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/Logging.h --- 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 +#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 +# 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 # define LOG(level) ::Orthanc::Logging::InternalLogger(#level, __FILE__, __LINE__) diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/SystemToolbox.cpp --- 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(microSeconds / static_cast(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/ diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/SystemToolbox.h --- 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(); diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/Toolbox.cpp --- 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(microSeconds / static_cast(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); diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/Toolbox.h --- 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 diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Core/WebServiceParameters.cpp --- 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 diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 Resources/Orthanc/Resources/CMake/BoostConfiguration.cmake --- 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") diff -r 8fd5bf76bb8e -r 4b0e0f7c9957 ViewerPlugin/CMakeLists.txt --- 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