Mercurial > hg > orthanc-databases
changeset 2:17bce6a07b2b
storage plugin skeletons
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Jul 2018 15:06:32 +0200 |
parents | d17b2631bb67 |
children | e490cdd766b9 a84b487ccbdc |
files | MySQL/CMakeLists.txt MySQL/Plugins/IndexPlugin.cpp MySQL/Plugins/StoragePlugin.cpp PostgreSQL/CMakeLists.txt PostgreSQL/Plugins/IndexPlugin.cpp PostgreSQL/Plugins/StoragePlugin.cpp Resources/CMake/DatabasesPluginParameters.cmake SQLite/Plugins/IndexPlugin.cpp |
diffstat | 8 files changed, 308 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/MySQL/CMakeLists.txt Wed Jul 04 18:05:24 2018 +0200 +++ b/MySQL/CMakeLists.txt Thu Jul 05 15:06:32 2018 +0200 @@ -29,6 +29,12 @@ ${AUTOGENERATED_SOURCES} ) +add_library(OrthancMySQLStorage SHARED + Plugins/StoragePlugin.cpp + ${DATABASES_SOURCES} + ${AUTOGENERATED_SOURCES} + ) + message("Setting the version of the libraries to ${ORTHANC_PLUGIN_VERSION}") add_definitions( @@ -36,11 +42,11 @@ -DHAS_ORTHANC_EXCEPTION=1 ) -#set_target_properties(OrthancMySQLStorage PROPERTIES -# VERSION ${ORTHANC_PLUGIN_VERSION} -# SOVERSION ${ORTHANC_PLUGIN_VERSION} -# COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1 -# ) +set_target_properties(OrthancMySQLStorage PROPERTIES + VERSION ${ORTHANC_PLUGIN_VERSION} + SOVERSION ${ORTHANC_PLUGIN_VERSION} + COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1 + ) set_target_properties(OrthancMySQLIndex PROPERTIES VERSION ${ORTHANC_PLUGIN_VERSION} @@ -49,7 +55,7 @@ ) install( - TARGETS OrthancMySQLIndex # OrthancMySQLStorage TODO + TARGETS OrthancMySQLIndex OrthancMySQLStorage RUNTIME DESTINATION lib # Destination for Windows LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux )
--- a/MySQL/Plugins/IndexPlugin.cpp Wed Jul 04 18:05:24 2018 +0200 +++ b/MySQL/Plugins/IndexPlugin.cpp Thu Jul 05 15:06:32 2018 +0200 @@ -25,16 +25,14 @@ #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Core/Logging.h> -static OrthancPluginContext* context_ = NULL; static std::auto_ptr<OrthancDatabases::MySQLIndex> backend_; - static bool DisplayPerformanceWarning() { (void) DisplayPerformanceWarning; // Disable warning about unused function - OrthancPluginLogWarning(context_, "Performance warning in MySQL index: " - "Non-release build, runtime debug assertions are turned on"); + LOG(WARNING) << "Performance warning in MySQL index: " + << "Non-release build, runtime debug assertions are turned on"; return true; } @@ -45,23 +43,22 @@ { Orthanc::Logging::Initialize(context); - context_ = context; assert(DisplayPerformanceWarning()); /* Check the version of the Orthanc core */ - if (OrthancPluginCheckVersion(context_) == 0) + if (OrthancPluginCheckVersion(context) == 0) { char info[1024]; sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", - context_->orthancVersion, + context->orthancVersion, ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); - OrthancPluginLogError(context_, info); + OrthancPluginLogError(context, info); return -1; } - OrthancPluginSetDescription(context_, "Stores the Orthanc index into a MySQL database."); + OrthancPluginSetDescription(context, "Stores the Orthanc index into a MySQL database."); OrthancPlugins::OrthancConfiguration configuration(context); @@ -91,11 +88,16 @@ backend_.reset(new OrthancDatabases::MySQLIndex(parameters)); /* Register the MySQL index into Orthanc */ - OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); + OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); } - catch (std::runtime_error& e) + catch (Orthanc::OrthancException& e) { - OrthancPluginLogError(context_, e.what()); + LOG(ERROR) << e.What(); + return -1; + } + catch (...) + { + LOG(ERROR) << "Native exception while initializing the plugin"; return -1; } @@ -105,9 +107,9 @@ ORTHANC_PLUGINS_API void OrthancPluginFinalize() { - OrthancPluginLogWarning(context_, "MySQL index is finalizing"); + LOG(WARNING) << "MySQL index is finalizing"; + backend_.reset(NULL); - OrthancDatabases::MySQLDatabase::GlobalFinalization(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MySQL/Plugins/StoragePlugin.cpp Thu Jul 05 15:06:32 2018 +0200 @@ -0,0 +1,120 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../../Framework/MySQL/MySQLDatabase.h" +#include "../../Framework/Plugins/StorageBackend.h" + +#include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> +#include <Core/Logging.h> + + +static bool DisplayPerformanceWarning() +{ + (void) DisplayPerformanceWarning; // Disable warning about unused function + LOG(WARNING) << "Performance warning in MySQL storage area: " + << "Non-release build, runtime debug assertions are turned on"; + return true; +} + + +extern "C" +{ + ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) + { + Orthanc::Logging::Initialize(context); + + assert(DisplayPerformanceWarning()); + + /* Check the version of the Orthanc core */ + if (OrthancPluginCheckVersion(context) == 0) + { + char info[1024]; + sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", + context->orthancVersion, + ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); + OrthancPluginLogError(context, info); + return -1; + } + + OrthancPluginSetDescription(context, "Stores the Orthanc storage area into a MySQL database."); + + OrthancPlugins::OrthancConfiguration configuration(context); + + if (!configuration.IsSection("MySQL")) + { + LOG(WARNING) << "No available configuration for the MySQL storage area plugin"; + return 0; + } + + OrthancPlugins::OrthancConfiguration mysql; + configuration.GetSection(mysql, "MySQL"); + + bool enable; + if (!mysql.LookupBooleanValue(enable, "EnableStorage") || + !enable) + { + LOG(WARNING) << "The MySQL storage area is currently disabled, set \"EnableStorage\" " + << "to \"true\" in the \"MySQL\" section of the configuration file of Orthanc"; + return 0; + } + + try + { + // TODO + //OrthancDatabases::StorageBackend::Register(); + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << e.What(); + return -1; + } + catch (...) + { + LOG(ERROR) << "Native exception while initializing the plugin"; + return -1; + } + + return 0; + } + + + ORTHANC_PLUGINS_API void OrthancPluginFinalize() + { + LOG(WARNING) << "MySQL storage area is finalizing"; + + OrthancDatabases::StorageBackend::Finalize(); + OrthancDatabases::MySQLDatabase::GlobalFinalization(); + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetName() + { + return "mysql-storage"; + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() + { + return ORTHANC_PLUGIN_VERSION; + } +}
--- a/PostgreSQL/CMakeLists.txt Wed Jul 04 18:05:24 2018 +0200 +++ b/PostgreSQL/CMakeLists.txt Thu Jul 05 15:06:32 2018 +0200 @@ -29,6 +29,12 @@ ${AUTOGENERATED_SOURCES} ) +add_library(OrthancPostgreSQLStorage SHARED + Plugins/StoragePlugin.cpp + ${DATABASES_SOURCES} + ${AUTOGENERATED_SOURCES} + ) + message("Setting the version of the libraries to ${ORTHANC_PLUGIN_VERSION}") add_definitions( @@ -36,11 +42,11 @@ -DHAS_ORTHANC_EXCEPTION=1 ) -#set_target_properties(OrthancPostgreSQLStorage PROPERTIES -# VERSION ${ORTHANC_PLUGIN_VERSION} -# SOVERSION ${ORTHANC_PLUGIN_VERSION} -# COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1 -# ) +set_target_properties(OrthancPostgreSQLStorage PROPERTIES + VERSION ${ORTHANC_PLUGIN_VERSION} + SOVERSION ${ORTHANC_PLUGIN_VERSION} + COMPILE_FLAGS -DORTHANC_ENABLE_LOGGING_PLUGIN=1 + ) set_target_properties(OrthancPostgreSQLIndex PROPERTIES VERSION ${ORTHANC_PLUGIN_VERSION} @@ -49,7 +55,7 @@ ) install( - TARGETS OrthancPostgreSQLIndex # OrthancPostgreSQLStorage TODO + TARGETS OrthancPostgreSQLIndex OrthancPostgreSQLStorage RUNTIME DESTINATION lib # Destination for Windows LIBRARY DESTINATION share/orthanc/plugins # Destination for Linux )
--- a/PostgreSQL/Plugins/IndexPlugin.cpp Wed Jul 04 18:05:24 2018 +0200 +++ b/PostgreSQL/Plugins/IndexPlugin.cpp Thu Jul 05 15:06:32 2018 +0200 @@ -21,10 +21,8 @@ #include "PostgreSQLIndex.h" -#include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Core/Logging.h> -static OrthancPluginContext* context_ = NULL; static std::auto_ptr<OrthancDatabases::PostgreSQLIndex> backend_; @@ -32,8 +30,8 @@ static bool DisplayPerformanceWarning() { (void) DisplayPerformanceWarning; // Disable warning about unused function - OrthancPluginLogWarning(context_, "Performance warning in PostgreSQL index: " - "Non-release build, runtime debug assertions are turned on"); + LOG(WARNING) << "Performance warning in PostgreSQL index: " + << "Non-release build, runtime debug assertions are turned on"; return true; } @@ -44,23 +42,22 @@ { Orthanc::Logging::Initialize(context); - context_ = context; assert(DisplayPerformanceWarning()); /* Check the version of the Orthanc core */ - if (OrthancPluginCheckVersion(context_) == 0) + if (OrthancPluginCheckVersion(context) == 0) { char info[1024]; sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", - context_->orthancVersion, + context->orthancVersion, ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); - OrthancPluginLogError(context_, info); + OrthancPluginLogError(context, info); return -1; } - OrthancPluginSetDescription(context_, "Stores the Orthanc index into a PostgreSQL database."); + OrthancPluginSetDescription(context, "Stores the Orthanc index into a PostgreSQL database."); OrthancPlugins::OrthancConfiguration configuration(context); @@ -90,11 +87,16 @@ backend_.reset(new OrthancDatabases::PostgreSQLIndex(parameters)); /* Register the PostgreSQL index into Orthanc */ - OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); + OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); } - catch (std::runtime_error& e) + catch (Orthanc::OrthancException& e) { - OrthancPluginLogError(context_, e.what()); + LOG(ERROR) << e.What(); + return -1; + } + catch (...) + { + LOG(ERROR) << "Native exception while initializing the plugin"; return -1; } @@ -104,7 +106,7 @@ ORTHANC_PLUGINS_API void OrthancPluginFinalize() { - OrthancPluginLogWarning(context_, "PostgreSQL index is finalizing"); + LOG(WARNING) << "PostgreSQL storage area is finalizing"; backend_.reset(NULL); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PostgreSQL/Plugins/StoragePlugin.cpp Thu Jul 05 15:06:32 2018 +0200 @@ -0,0 +1,117 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics + * Department, University Hospital of Liege, Belgium + * Copyright (C) 2017-2018 Osimis S.A., Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "../../Framework/Plugins/StorageBackend.h" + +#include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> +#include <Core/Logging.h> + + +static bool DisplayPerformanceWarning() +{ + (void) DisplayPerformanceWarning; // Disable warning about unused function + LOG(WARNING) << "Performance warning in PostgreSQL storage area: " + << "Non-release build, runtime debug assertions are turned on"; + return true; +} + + +extern "C" +{ + ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) + { + Orthanc::Logging::Initialize(context); + + assert(DisplayPerformanceWarning()); + + /* Check the version of the Orthanc core */ + if (OrthancPluginCheckVersion(context) == 0) + { + char info[1024]; + sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", + context->orthancVersion, + ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, + ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); + OrthancPluginLogError(context, info); + return -1; + } + + OrthancPluginSetDescription(context, "Stores the Orthanc storage area into a PostgreSQL database."); + + OrthancPlugins::OrthancConfiguration configuration(context); + + if (!configuration.IsSection("PostgreSQL")) + { + LOG(WARNING) << "No available configuration for the PostgreSQL storage area plugin"; + return 0; + } + + OrthancPlugins::OrthancConfiguration postgresql; + configuration.GetSection(postgresql, "PostgreSQL"); + + bool enable; + if (!postgresql.LookupBooleanValue(enable, "EnableStorage") || + !enable) + { + LOG(WARNING) << "The PostgreSQL storage area is currently disabled, set \"EnableStorage\" " + << "to \"true\" in the \"PostgreSQL\" section of the configuration file of Orthanc"; + return 0; + } + + try + { + // TODO + //OrthancDatabases::StorageBackend::Register(); + } + catch (Orthanc::OrthancException& e) + { + LOG(ERROR) << e.What(); + return -1; + } + catch (...) + { + LOG(ERROR) << "Native exception while initializing the plugin"; + return -1; + } + + return 0; + } + + + ORTHANC_PLUGINS_API void OrthancPluginFinalize() + { + LOG(WARNING) << "PostgreSQL storage area is finalizing"; + OrthancDatabases::StorageBackend::Finalize(); + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetName() + { + return "postgresql-storage"; + } + + + ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() + { + return ORTHANC_PLUGIN_VERSION; + } +}
--- a/Resources/CMake/DatabasesPluginParameters.cmake Wed Jul 04 18:05:24 2018 +0200 +++ b/Resources/CMake/DatabasesPluginParameters.cmake Thu Jul 05 15:06:32 2018 +0200 @@ -18,7 +18,7 @@ -set(ALLOW_DOWNLOADS ON CACHE BOOL "Allow CMake to download packages") +set(ALLOW_DOWNLOADS OFF CACHE BOOL "Allow CMake to download packages") set(ORTHANC_FRAMEWORK_SOURCE "${ORTHANC_FRAMEWORK_DEFAULT_SOURCE}" CACHE STRING "Source of the Orthanc source code (can be \"hg\", \"archive\", \"web\" or \"path\")") set(ORTHANC_FRAMEWORK_ARCHIVE "" CACHE STRING "Path to the Orthanc archive, if ORTHANC_FRAMEWORK_SOURCE is \"archive\"") set(ORTHANC_FRAMEWORK_ROOT "" CACHE STRING "Path to the Orthanc source directory, if ORTHANC_FRAMEWORK_SOURCE is \"path\"")
--- a/SQLite/Plugins/IndexPlugin.cpp Wed Jul 04 18:05:24 2018 +0200 +++ b/SQLite/Plugins/IndexPlugin.cpp Thu Jul 05 15:06:32 2018 +0200 @@ -24,16 +24,14 @@ #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> #include <Core/Logging.h> -static OrthancPluginContext* context_ = NULL; static std::auto_ptr<OrthancDatabases::SQLiteIndex> backend_; - static bool DisplayPerformanceWarning() { (void) DisplayPerformanceWarning; // Disable warning about unused function - OrthancPluginLogWarning(context_, "Performance warning in SQLite index: " - "Non-release build, runtime debug assertions are turned on"); + LOG(WARNING) << "Performance warning in SQLite index: " + << "Non-release build, runtime debug assertions are turned on"; return true; } @@ -44,23 +42,22 @@ { Orthanc::Logging::Initialize(context); - context_ = context; assert(DisplayPerformanceWarning()); /* Check the version of the Orthanc core */ - if (OrthancPluginCheckVersion(context_) == 0) + if (OrthancPluginCheckVersion(context) == 0) { char info[1024]; sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", - context_->orthancVersion, + context->orthancVersion, ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); - OrthancPluginLogError(context_, info); + OrthancPluginLogError(context, info); return -1; } - OrthancPluginSetDescription(context_, "Stores the Orthanc index into a SQLite database."); + OrthancPluginSetDescription(context, "Stores the Orthanc index into a SQLite database."); #if 0 OrthancPlugins::OrthancConfiguration configuration(context); @@ -90,11 +87,16 @@ backend_.reset(new OrthancDatabases::SQLiteIndex("index.db")); // TODO parameter /* Register the SQLite index into Orthanc */ - OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); + OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); } - catch (std::runtime_error& e) + catch (Orthanc::OrthancException& e) { - OrthancPluginLogError(context_, e.what()); + LOG(ERROR) << e.What(); + return -1; + } + catch (...) + { + LOG(ERROR) << "Native exception while initializing the plugin"; return -1; } @@ -104,7 +106,7 @@ ORTHANC_PLUGINS_API void OrthancPluginFinalize() { - OrthancPluginLogWarning(context_, "SQLite index is finalizing"); + LOG(WARNING) << "SQLite index is finalizing"; backend_.reset(NULL); }