diff MySQL/Plugins/IndexPlugin.cpp @ 222:c8e06b41feec

refactoring registration/finalization of index backend
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Apr 2021 11:16:13 +0200
parents c2e4a909de0e
children d1b124d116c1
line wrap: on
line diff
--- a/MySQL/Plugins/IndexPlugin.cpp	Tue Mar 30 10:40:34 2021 +0200
+++ b/MySQL/Plugins/IndexPlugin.cpp	Thu Apr 01 11:16:13 2021 +0200
@@ -23,13 +23,10 @@
 #include "../../Framework/MySQL/MySQLDatabase.h"
 #include "../../Framework/Plugins/PluginInitialization.h"
 
-#include <Compatibility.h>  // For std::unique_ptr<>
 #include <HttpClient.h>
 #include <Logging.h>
 #include <Toolbox.h>
 
-static std::unique_ptr<OrthancDatabases::MySQLIndex> backend_;
-
 
 extern "C"
 {
@@ -66,12 +63,7 @@
     try
     {
       OrthancDatabases::MySQLParameters parameters(mysql, configuration);
-
-      /* Create the database back-end */
-      backend_.reset(new OrthancDatabases::MySQLIndex(context, parameters));
-
-      /* Register the MySQL index into Orthanc */
-      OrthancDatabases::IndexBackend::Register(*backend_);
+      OrthancDatabases::IndexBackend::Register(new OrthancDatabases::MySQLIndex(context, parameters));
     }
     catch (Orthanc::OrthancException& e)
     {
@@ -91,8 +83,8 @@
   ORTHANC_PLUGINS_API void OrthancPluginFinalize()
   {
     LOG(WARNING) << "MySQL index is finalizing";
+    OrthancDatabases::IndexBackend::Finalize();
 
-    backend_.reset(NULL);
     OrthancDatabases::MySQLDatabase::GlobalFinalization();
     Orthanc::HttpClient::GlobalFinalize();
     Orthanc::Toolbox::FinalizeOpenSsl();