Mercurial > hg > orthanc-databases
annotate SQLite/Plugins/IndexPlugin.cpp @ 500:c27071770c04
typo
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 09 Apr 2024 15:47:30 +0200 |
parents | af6998ed73dd |
children | 54d518dcd74a |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "SQLiteIndex.h" | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
24 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 25 |
152 | 26 #include <Logging.h> |
0 | 27 |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
28 #include <google/protobuf/any.h> |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
29 |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
30 #define ORTHANC_PLUGIN_NAME "sqlite-index" |
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
31 |
0 | 32 |
33 extern "C" | |
34 { | |
35 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
36 { | |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
37 GOOGLE_PROTOBUF_VERIFY_VERSION; |
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
38 |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
39 if (!OrthancDatabases::InitializePlugin(context, ORTHANC_PLUGIN_NAME, "SQLite", true)) |
0 | 40 { |
41 return -1; | |
42 } | |
43 | |
44 #if 0 | |
62
eedd082355f9
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
45 OrthancPlugins::OrthancConfiguration configuration; |
0 | 46 |
47 if (!configuration.IsSection("SQLite")) | |
48 { | |
49 LOG(WARNING) << "No available configuration for the SQLite index plugin"; | |
50 return 0; | |
51 } | |
52 | |
53 OrthancPlugins::OrthancConfiguration sqlite; | |
54 configuration.GetSection(sqlite, "SQLite"); | |
55 | |
56 bool enable; | |
57 if (!sqlite.LookupBooleanValue(enable, "EnableIndex") || | |
58 !enable) | |
59 { | |
60 LOG(WARNING) << "The SQLite index is currently disabled, set \"EnableIndex\" " | |
61 << "to \"true\" in the \"SQLite\" section of the configuration file of Orthanc"; | |
62 return 0; | |
63 } | |
64 #endif | |
65 | |
66 try | |
67 { | |
68 /* Register the SQLite index into Orthanc */ | |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
69 OrthancDatabases::IndexBackend::Register( |
234
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
70 new OrthancDatabases::SQLiteIndex(context, "index.db"), // TODO parameter |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
71 1 /* only 1 connection is possible with SQLite */, |
d1b124d116c1
PostgreSQL index plugin handles retries for collisions between multiple writers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
222
diff
changeset
|
72 0 /* no collision is possible, as SQLite has a global lock */); |
0 | 73 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
74 catch (Orthanc::OrthancException& e) |
0 | 75 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
76 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
77 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
79 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
80 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
81 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 82 return -1; |
83 } | |
84 | |
85 return 0; | |
86 } | |
87 | |
88 | |
89 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
90 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
91 LOG(WARNING) << "SQLite index is finalizing"; |
222
c8e06b41feec
refactoring registration/finalization of index backend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
213
diff
changeset
|
92 OrthancDatabases::IndexBackend::Finalize(); |
381
9cde77ca9ad9
initializing and finalizing protobuf
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
359
diff
changeset
|
93 google::protobuf::ShutdownProtobufLibrary(); |
0 | 94 } |
95 | |
96 | |
97 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
98 { | |
492
af6998ed73dd
fix deprecated calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
459
diff
changeset
|
99 return ORTHANC_PLUGIN_NAME; |
0 | 100 } |
101 | |
102 | |
103 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
104 { | |
105 return ORTHANC_PLUGIN_VERSION; | |
106 } | |
107 } |