# HG changeset patch # User Sebastien Jodogne # Date 1443693325 -7200 # Node ID a412ad57f0f9c8c2095fc859ffc102051b188668 # Parent de1413733c97c96592d2dd0cb2b36e793164d0e7 refactoring of sample plugins, OrthancPluginReconstructMainDicomTags diff -r de1413733c97 -r a412ad57f0f9 OrthancServer/DatabaseWrapper.cpp --- a/OrthancServer/DatabaseWrapper.cpp Wed Sep 30 17:18:39 2015 +0200 +++ b/OrthancServer/DatabaseWrapper.cpp Thu Oct 01 11:55:25 2015 +0200 @@ -37,6 +37,7 @@ #include "../Core/Logging.h" #include "../Core/Uuid.h" #include "EmbeddedResources.h" +#include "ServerToolbox.h" #include #include @@ -890,9 +891,8 @@ // No change in the DB schema, the step from version 5 to 6 only // consists in reconstructing the main DICOM tags information. db_.BeginTransaction(); - SetGlobalProperty(GlobalProperty_DatabaseSchemaVersion, "6"); - SetGlobalProperty(GlobalProperty_ReconstructStudiesTags, "1"); - SetGlobalProperty(GlobalProperty_ReconstructSeriesTags, "1"); + Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Study); + Toolbox::ReconstructMainDicomTags(*this, storageArea, ResourceType_Series); db_.CommitTransaction(); version_ = 6; } diff -r de1413733c97 -r a412ad57f0f9 OrthancServer/ServerEnumerations.h --- a/OrthancServer/ServerEnumerations.h Wed Sep 30 17:18:39 2015 +0200 +++ b/OrthancServer/ServerEnumerations.h Thu Oct 01 11:55:25 2015 +0200 @@ -111,11 +111,7 @@ { GlobalProperty_DatabaseSchemaVersion = 1, // Unused in the Orthanc core as of Orthanc 0.9.5 GlobalProperty_FlushSleep = 2, - GlobalProperty_AnonymizationSequence = 3, - GlobalProperty_ReconstructPatientsTags = 4, - GlobalProperty_ReconstructStudiesTags = 5, - GlobalProperty_ReconstructSeriesTags = 6, - GlobalProperty_ReconstructInstancesTags = 7 + GlobalProperty_AnonymizationSequence = 3 }; enum MetadataType diff -r de1413733c97 -r a412ad57f0f9 OrthancServer/ServerToolbox.cpp --- a/OrthancServer/ServerToolbox.cpp Wed Sep 30 17:18:39 2015 +0200 +++ b/OrthancServer/ServerToolbox.cpp Thu Oct 01 11:55:25 2015 +0200 @@ -235,6 +235,32 @@ { // WARNING: The database should be locked with a transaction! + const char* plural = NULL; + + switch (level) + { + case ResourceType_Patient: + plural = "patients"; + break; + + case ResourceType_Study: + plural = "studies"; + break; + + case ResourceType_Series: + plural = "series"; + break; + + case ResourceType_Instance: + plural = "instances"; + break; + + default: + throw OrthancException(ErrorCode_InternalError); + } + + LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "..."; + std::list resources; database.GetAllPublicIds(resources, level); diff -r de1413733c97 -r a412ad57f0f9 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Wed Sep 30 17:18:39 2015 +0200 +++ b/OrthancServer/main.cpp Thu Oct 01 11:55:25 2015 +0200 @@ -613,114 +613,43 @@ } - - -static bool ReconstructLevel(IDatabaseWrapper& database, - IStorageArea& storageArea, - bool allowDatabaseUpgrade, - ResourceType level) -{ - GlobalProperty property; - const char* plural = NULL; - - switch (level) - { - case ResourceType_Patient: - plural = "patients"; - property = GlobalProperty_ReconstructPatientsTags; - break; - - case ResourceType_Study: - plural = "studies"; - property = GlobalProperty_ReconstructStudiesTags; - break; - - case ResourceType_Series: - plural = "series"; - property = GlobalProperty_ReconstructSeriesTags; - break; - - case ResourceType_Instance: - plural = "instances"; - property = GlobalProperty_ReconstructInstancesTags; - break; - - default: - throw OrthancException(ErrorCode_InternalError); - } - - std::string tmp; - if (database.LookupGlobalProperty(tmp, property) && tmp != "0") - { - if (!allowDatabaseUpgrade) - { - LOG(ERROR) << "The main DICOM tags of all the " << plural - << " must be reconstructed: " - << "Please run Orthanc with the \"--upgrade\" command-line option"; - return false; - } - - std::auto_ptr transaction(database.StartTransaction()); - transaction->Begin(); - - LOG(WARNING) << "Upgrade: Reconstructing the main DICOM tags of all the " << plural << "..."; - Toolbox::ReconstructMainDicomTags(database, storageArea, level); - - database.SetGlobalProperty(property, "0"); - - transaction->Commit(); - } - - return true; -} - - static bool UpgradeDatabase(IDatabaseWrapper& database, IStorageArea& storageArea, bool allowDatabaseUpgrade) { // Upgrade the schema of the database, if needed unsigned int currentVersion = database.GetDatabaseVersion(); - if (currentVersion != ORTHANC_DATABASE_VERSION) + if (currentVersion == ORTHANC_DATABASE_VERSION) { - if (currentVersion > ORTHANC_DATABASE_VERSION) - { - LOG(ERROR) << "The version of the database schema (" << currentVersion - << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; - return false; - } - - if (!allowDatabaseUpgrade) - { - LOG(ERROR) << "The database schema must be upgraded from version " - << currentVersion << " to " << ORTHANC_DATABASE_VERSION - << ": Please run Orthanc with the \"--upgrade\" command-line option"; - return false; - } - - LOG(WARNING) << "Upgrading the database from schema version " - << currentVersion << " to " << ORTHANC_DATABASE_VERSION; - database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); - - // Sanity check - currentVersion = database.GetDatabaseVersion(); - if (ORTHANC_DATABASE_VERSION != currentVersion) - { - LOG(ERROR) << "The database schema was not properly upgraded, it is still at version " << currentVersion; - throw OrthancException(ErrorCode_InternalError); - } + return true; } - - // Reconstruct the main DICOM tags at each level, if needed - if (!ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Patient) || - !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Study) || - !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Series) || - !ReconstructLevel(database, storageArea, allowDatabaseUpgrade, ResourceType_Instance)) + if (currentVersion > ORTHANC_DATABASE_VERSION) { + LOG(ERROR) << "The version of the database schema (" << currentVersion + << ") is too recent for this version of Orthanc. Please upgrade Orthanc."; return false; } + if (!allowDatabaseUpgrade) + { + LOG(ERROR) << "The database schema must be upgraded from version " + << currentVersion << " to " << ORTHANC_DATABASE_VERSION + << ": Please run Orthanc with the \"--upgrade\" command-line option"; + return false; + } + + LOG(WARNING) << "Upgrading the database from schema version " + << currentVersion << " to " << ORTHANC_DATABASE_VERSION; + database.Upgrade(ORTHANC_DATABASE_VERSION, storageArea); + + // Sanity check + currentVersion = database.GetDatabaseVersion(); + if (ORTHANC_DATABASE_VERSION != currentVersion) + { + LOG(ERROR) << "The database schema was not properly upgraded, it is still at version " << currentVersion; + throw OrthancException(ErrorCode_InternalError); + } return true; } diff -r de1413733c97 -r a412ad57f0f9 Plugins/Engine/OrthancPlugins.cpp --- a/Plugins/Engine/OrthancPlugins.cpp Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu Oct 01 11:55:25 2015 +0200 @@ -1709,6 +1709,22 @@ return true; } + case _OrthancPluginService_ReconstructMainDicomTags: + { + const _OrthancPluginReconstructMainDicomTags& p = + *reinterpret_cast(parameters); + + if (pimpl_->database_.get() == NULL) + { + LOG(ERROR) << "The service ReconstructMainDicomTags can only be invoked by custom database plugins"; + throw OrthancException(ErrorCode_DatabasePlugin); + } + + IStorageArea& storage = *reinterpret_cast(p.storageArea); + Toolbox::ReconstructMainDicomTags(*pimpl_->database_, storage, Plugins::Convert(p.level)); + return true; + } + default: { // This service is unknown to the Orthanc plugin engine diff -r de1413733c97 -r a412ad57f0f9 Plugins/Engine/PluginsEnumerations.cpp --- a/Plugins/Engine/PluginsEnumerations.cpp Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.cpp Thu Oct 01 11:55:25 2015 +0200 @@ -66,6 +66,28 @@ } + ResourceType Convert(OrthancPluginResourceType type) + { + switch (type) + { + case OrthancPluginResourceType_Patient: + return ResourceType_Patient; + + case OrthancPluginResourceType_Study: + return ResourceType_Study; + + case OrthancPluginResourceType_Series: + return ResourceType_Series; + + case OrthancPluginResourceType_Instance: + return ResourceType_Instance; + + default: + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + } + + OrthancPluginChangeType Convert(ChangeType type) { switch (type) diff -r de1413733c97 -r a412ad57f0f9 Plugins/Engine/PluginsEnumerations.h --- a/Plugins/Engine/PluginsEnumerations.h Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Engine/PluginsEnumerations.h Thu Oct 01 11:55:25 2015 +0200 @@ -45,6 +45,8 @@ { OrthancPluginResourceType Convert(ResourceType type); + ResourceType Convert(OrthancPluginResourceType type); + OrthancPluginChangeType Convert(ChangeType type); OrthancPluginPixelFormat Convert(PixelFormat format); diff -r de1413733c97 -r a412ad57f0f9 Plugins/Include/orthanc/OrthancCPlugin.h --- a/Plugins/Include/orthanc/OrthancCPlugin.h Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Thu Oct 01 11:55:25 2015 +0200 @@ -422,6 +422,7 @@ _OrthancPluginService_RestApiPostAfterPlugins = 3011, _OrthancPluginService_RestApiDeleteAfterPlugins = 3012, _OrthancPluginService_RestApiPutAfterPlugins = 3013, + _OrthancPluginService_ReconstructMainDicomTags = 3014, /* Access to DICOM instances */ _OrthancPluginService_GetInstanceRemoteAet = 4000, @@ -3766,6 +3767,27 @@ } + + + typedef struct + { + OrthancPluginStorageArea* storageArea; + OrthancPluginResourceType level; + } _OrthancPluginReconstructMainDicomTags; + + ORTHANC_PLUGIN_INLINE OrthancPluginErrorCode OrthancPluginReconstructMainDicomTags( + OrthancPluginContext* context, + OrthancPluginStorageArea* storageArea, + OrthancPluginResourceType level) + { + _OrthancPluginReconstructMainDicomTags params; + params.level = level; + params.storageArea = storageArea; + + return context->InvokeService(context, _OrthancPluginService_ReconstructMainDicomTags, ¶ms); + } + + #ifdef __cplusplus } #endif diff -r de1413733c97 -r a412ad57f0f9 Plugins/Samples/Common/OrthancPlugins.cmake --- a/Plugins/Samples/Common/OrthancPlugins.cmake Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Samples/Common/OrthancPlugins.cmake Thu Oct 01 11:55:25 2015 +0200 @@ -1,34 +1,11 @@ +set(ORTHANC_ROOT ${SAMPLES_ROOT}/../..) include(CheckIncludeFiles) +include(CheckIncludeFileCXX) include(CheckLibraryExists) - - -if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - link_libraries(uuid) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread") - -elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") - link_libraries(rpcrt4 ws2_32 secur32) - if (CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++") - endif() - - CHECK_LIBRARY_EXISTS(winpthread pthread_create "" HAVE_WIN_PTHREAD) - if (HAVE_WIN_PTHREAD) - # This line is necessary to compile with recent versions of MinGW, - # otherwise "libwinpthread-1.dll" is not statically linked. - SET(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic") - endif() -endif () - - -if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD" OR - ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--version-script=${SAMPLES_ROOT}/Common/VersionScript.map -Wl,--no-undefined") -elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -exported_symbols_list ${CMAKE_SOURCE_DIR}/Plugins/Samples/Common/ExportedSymbols.list") -endif() +include(FindPythonInterp) +include(${ORTHANC_ROOT}/Resources/CMake/AutoGeneratedCode.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) +include(${ORTHANC_ROOT}/Resources/CMake/Compiler.cmake) if (CMAKE_COMPILER_IS_GNUCXX) @@ -43,8 +20,10 @@ link_libraries(dl rt) endif() + include_directories(${SAMPLES_ROOT}/../Include/) + if (MSVC) include_directories(${SAMPLES_ROOT}/../../Resources/ThirdParty/VisualStudio/) endif() diff -r de1413733c97 -r a412ad57f0f9 Plugins/Samples/GdcmDecoding/CMakeLists.txt --- a/Plugins/Samples/GdcmDecoding/CMakeLists.txt Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Samples/GdcmDecoding/CMakeLists.txt Thu Oct 01 11:55:25 2015 +0200 @@ -3,18 +3,15 @@ project(GdcmDecoding) SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") -SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") -SET(USE_SYSTEM_GOOGLE_LOG ON CACHE BOOL "Use the system version of Google Log") +SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") -set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/../../..) -set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..) +SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of Boost") +SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") -include(CheckIncludeFiles) -include(CheckIncludeFileCXX) +set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..) include(${CMAKE_SOURCE_DIR}/../Common/OrthancPlugins.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) + include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/GoogleLogConfiguration.cmake) include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) find_package(GDCM REQUIRED) diff -r de1413733c97 -r a412ad57f0f9 Plugins/Samples/ServeFolders/CMakeLists.txt --- a/Plugins/Samples/ServeFolders/CMakeLists.txt Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Samples/ServeFolders/CMakeLists.txt Thu Oct 01 11:55:25 2015 +0200 @@ -5,16 +5,12 @@ SET(SERVE_FOLDERS_VERSION "0.0" CACHE STRING "Version of the plugin") SET(STATIC_BUILD OFF CACHE BOOL "Static build of the third-party libraries (necessary for Windows)") SET(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") + SET(USE_SYSTEM_JSONCPP ON CACHE BOOL "Use the system version of JsonCpp") SET(USE_SYSTEM_BOOST ON CACHE BOOL "Use the system version of boost") -set(ORTHANC_ROOT ${CMAKE_SOURCE_DIR}/../../../) set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..) - -include(CheckIncludeFiles) -include(CheckIncludeFileCXX) include(${CMAKE_SOURCE_DIR}/../Common/OrthancPlugins.cmake) -include(${ORTHANC_ROOT}/Resources/CMake/DownloadPackage.cmake) include(${ORTHANC_ROOT}/Resources/CMake/JsonCppConfiguration.cmake) include(${ORTHANC_ROOT}/Resources/CMake/BoostConfiguration.cmake) @@ -24,7 +20,6 @@ ${BOOST_SOURCES} ) - message("Setting the version of the plugin to ${SERVE_FOLDERS_VERSION}") add_definitions(-DSERVE_FOLDERS_VERSION="${SERVE_FOLDERS_VERSION}") diff -r de1413733c97 -r a412ad57f0f9 Plugins/Samples/WebSkeleton/CMakeLists.txt --- a/Plugins/Samples/WebSkeleton/CMakeLists.txt Wed Sep 30 17:18:39 2015 +0200 +++ b/Plugins/Samples/WebSkeleton/CMakeLists.txt Thu Oct 01 11:55:25 2015 +0200 @@ -5,11 +5,11 @@ SET(STANDALONE_BUILD ON CACHE BOOL "Standalone build (all the resources are embedded, necessary for releases)") SET(RESOURCES_ROOT ${CMAKE_SOURCE_DIR}/StaticResources) -include(Framework/Framework.cmake) - set(SAMPLES_ROOT ${CMAKE_SOURCE_DIR}/..) include(${SAMPLES_ROOT}/Common/OrthancPlugins.cmake) +include(Framework/Framework.cmake) + add_library(WebSkeleton SHARED ${AUTOGENERATED_SOURCES} )