Mercurial > hg > orthanc-databases
comparison 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 |
comparison
equal
deleted
inserted
replaced
221:73cc85f3d9c1 | 222:c8e06b41feec |
---|---|
21 | 21 |
22 #include "MySQLIndex.h" | 22 #include "MySQLIndex.h" |
23 #include "../../Framework/MySQL/MySQLDatabase.h" | 23 #include "../../Framework/MySQL/MySQLDatabase.h" |
24 #include "../../Framework/Plugins/PluginInitialization.h" | 24 #include "../../Framework/Plugins/PluginInitialization.h" |
25 | 25 |
26 #include <Compatibility.h> // For std::unique_ptr<> | |
27 #include <HttpClient.h> | 26 #include <HttpClient.h> |
28 #include <Logging.h> | 27 #include <Logging.h> |
29 #include <Toolbox.h> | 28 #include <Toolbox.h> |
30 | |
31 static std::unique_ptr<OrthancDatabases::MySQLIndex> backend_; | |
32 | 29 |
33 | 30 |
34 extern "C" | 31 extern "C" |
35 { | 32 { |
36 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | 33 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
64 } | 61 } |
65 | 62 |
66 try | 63 try |
67 { | 64 { |
68 OrthancDatabases::MySQLParameters parameters(mysql, configuration); | 65 OrthancDatabases::MySQLParameters parameters(mysql, configuration); |
69 | 66 OrthancDatabases::IndexBackend::Register(new OrthancDatabases::MySQLIndex(context, parameters)); |
70 /* Create the database back-end */ | |
71 backend_.reset(new OrthancDatabases::MySQLIndex(context, parameters)); | |
72 | |
73 /* Register the MySQL index into Orthanc */ | |
74 OrthancDatabases::IndexBackend::Register(*backend_); | |
75 } | 67 } |
76 catch (Orthanc::OrthancException& e) | 68 catch (Orthanc::OrthancException& e) |
77 { | 69 { |
78 LOG(ERROR) << e.What(); | 70 LOG(ERROR) << e.What(); |
79 return -1; | 71 return -1; |
89 | 81 |
90 | 82 |
91 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | 83 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
92 { | 84 { |
93 LOG(WARNING) << "MySQL index is finalizing"; | 85 LOG(WARNING) << "MySQL index is finalizing"; |
86 OrthancDatabases::IndexBackend::Finalize(); | |
94 | 87 |
95 backend_.reset(NULL); | |
96 OrthancDatabases::MySQLDatabase::GlobalFinalization(); | 88 OrthancDatabases::MySQLDatabase::GlobalFinalization(); |
97 Orthanc::HttpClient::GlobalFinalize(); | 89 Orthanc::HttpClient::GlobalFinalize(); |
98 Orthanc::Toolbox::FinalizeOpenSsl(); | 90 Orthanc::Toolbox::FinalizeOpenSsl(); |
99 } | 91 } |
100 | 92 |