Mercurial > hg > orthanc-databases
diff MySQL/Plugins/IndexPlugin.cpp @ 2:17bce6a07b2b
storage plugin skeletons
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Jul 2018 15:06:32 +0200 |
parents | 7cea966b6829 |
children | 17f849b2af34 |
line wrap: on
line diff
--- 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(); }