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