comparison 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
comparison
equal deleted inserted replaced
221:73cc85f3d9c1 222:c8e06b41feec
20 20
21 21
22 #include "PostgreSQLIndex.h" 22 #include "PostgreSQLIndex.h"
23 #include "../../Framework/Plugins/PluginInitialization.h" 23 #include "../../Framework/Plugins/PluginInitialization.h"
24 24
25 #include <Compatibility.h> // For std::unique_ptr<>
26 #include <Logging.h> 25 #include <Logging.h>
27
28 static std::unique_ptr<OrthancDatabases::PostgreSQLIndex> backend_;
29 26
30 27
31 extern "C" 28 extern "C"
32 { 29 {
33 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) 30 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
58 } 55 }
59 56
60 try 57 try
61 { 58 {
62 OrthancDatabases::PostgreSQLParameters parameters(postgresql); 59 OrthancDatabases::PostgreSQLParameters parameters(postgresql);
63 60 OrthancDatabases::IndexBackend::Register(new OrthancDatabases::PostgreSQLIndex(context, parameters));
64 /* Create the database back-end */
65 backend_.reset(new OrthancDatabases::PostgreSQLIndex(context, parameters));
66
67 /* Register the PostgreSQL index into Orthanc */
68 OrthancDatabases::IndexBackend::Register(*backend_);
69 } 61 }
70 catch (Orthanc::OrthancException& e) 62 catch (Orthanc::OrthancException& e)
71 { 63 {
72 LOG(ERROR) << e.What(); 64 LOG(ERROR) << e.What();
73 return -1; 65 return -1;
83 75
84 76
85 ORTHANC_PLUGINS_API void OrthancPluginFinalize() 77 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
86 { 78 {
87 LOG(WARNING) << "PostgreSQL index is finalizing"; 79 LOG(WARNING) << "PostgreSQL index is finalizing";
88 backend_.reset(NULL); 80 OrthancDatabases::IndexBackend::Finalize();
89 } 81 }
90 82
91 83
92 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 84 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
93 { 85 {