diff PostgreSQL/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/PostgreSQL/Plugins/IndexPlugin.cpp	Tue Mar 30 10:40:34 2021 +0200
+++ b/PostgreSQL/Plugins/IndexPlugin.cpp	Thu Apr 01 11:16:13 2021 +0200
@@ -22,11 +22,8 @@
 #include "PostgreSQLIndex.h"
 #include "../../Framework/Plugins/PluginInitialization.h"
 
-#include <Compatibility.h>  // For std::unique_ptr<>
 #include <Logging.h>
 
-static std::unique_ptr<OrthancDatabases::PostgreSQLIndex> backend_;
-
 
 extern "C"
 {
@@ -60,12 +57,7 @@
     try
     {
       OrthancDatabases::PostgreSQLParameters parameters(postgresql);
-
-      /* Create the database back-end */
-      backend_.reset(new OrthancDatabases::PostgreSQLIndex(context, parameters));
-
-      /* Register the PostgreSQL index into Orthanc */
-      OrthancDatabases::IndexBackend::Register(*backend_);
+      OrthancDatabases::IndexBackend::Register(new OrthancDatabases::PostgreSQLIndex(context, parameters));
     }
     catch (Orthanc::OrthancException& e)
     {
@@ -85,7 +77,7 @@
   ORTHANC_PLUGINS_API void OrthancPluginFinalize()
   {
     LOG(WARNING) << "PostgreSQL index is finalizing";
-    backend_.reset(NULL);
+    OrthancDatabases::IndexBackend::Finalize();
   }