comparison SQLite/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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/ 19 **/
20 20
21 21
22 #include "SQLiteIndex.h" 22 #include "SQLiteIndex.h"
23 #include "../../Framework/Plugins/DatabaseBackendAdapterV3.h"
24 #include "../../Framework/Plugins/PluginInitialization.h" 23 #include "../../Framework/Plugins/PluginInitialization.h"
25 24
26 #include <Compatibility.h> // For std::unique_ptr<>
27 #include <Logging.h> 25 #include <Logging.h>
28
29 static std::unique_ptr<OrthancDatabases::SQLiteIndex> backend_;
30 26
31 27
32 extern "C" 28 extern "C"
33 { 29 {
34 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) 30 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
60 } 56 }
61 #endif 57 #endif
62 58
63 try 59 try
64 { 60 {
65 /* Create the database back-end */
66 backend_.reset(new OrthancDatabases::SQLiteIndex(context, "index.db")); // TODO parameter
67
68 /* Register the SQLite index into Orthanc */ 61 /* Register the SQLite index into Orthanc */
69 OrthancDatabases::IndexBackend::Register(*backend_); 62 OrthancDatabases::IndexBackend::Register(
63 new OrthancDatabases::SQLiteIndex(context, "index.db")); // TODO parameter
70 } 64 }
71 catch (Orthanc::OrthancException& e) 65 catch (Orthanc::OrthancException& e)
72 { 66 {
73 LOG(ERROR) << e.What(); 67 LOG(ERROR) << e.What();
74 return -1; 68 return -1;
84 78
85 79
86 ORTHANC_PLUGINS_API void OrthancPluginFinalize() 80 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
87 { 81 {
88 LOG(WARNING) << "SQLite index is finalizing"; 82 LOG(WARNING) << "SQLite index is finalizing";
89 backend_.reset(NULL); 83 OrthancDatabases::IndexBackend::Finalize();
90 } 84 }
91 85
92 86
93 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() 87 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
94 { 88 {