Mercurial > hg > orthanc-databases
annotate SQLite/Plugins/IndexPlugin.cpp @ 24:17f849b2af34
sharing plugin initialization code
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 12 Jul 2018 12:17:39 +0200 |
parents | 17bce6a07b2b |
children | c0cb5d2cd696 |
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 | |
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "SQLiteIndex.h" | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
23 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 24 |
25 #include <Core/Logging.h> | |
26 | |
27 static std::auto_ptr<OrthancDatabases::SQLiteIndex> backend_; | |
28 | |
29 | |
30 extern "C" | |
31 { | |
32 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
33 { | |
24
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
34 if (!OrthancDatabases::InitializePlugin |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
35 (context, "SQLite index", |
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
36 "Stores the Orthanc index into a SQLite database.")) |
0 | 37 { |
38 return -1; | |
39 } | |
40 | |
41 #if 0 | |
42 OrthancPlugins::OrthancConfiguration configuration(context); | |
43 | |
44 if (!configuration.IsSection("SQLite")) | |
45 { | |
46 LOG(WARNING) << "No available configuration for the SQLite index plugin"; | |
47 return 0; | |
48 } | |
49 | |
50 OrthancPlugins::OrthancConfiguration sqlite; | |
51 configuration.GetSection(sqlite, "SQLite"); | |
52 | |
53 bool enable; | |
54 if (!sqlite.LookupBooleanValue(enable, "EnableIndex") || | |
55 !enable) | |
56 { | |
57 LOG(WARNING) << "The SQLite index is currently disabled, set \"EnableIndex\" " | |
58 << "to \"true\" in the \"SQLite\" section of the configuration file of Orthanc"; | |
59 return 0; | |
60 } | |
61 #endif | |
62 | |
63 try | |
64 { | |
65 /* Create the database back-end */ | |
66 backend_.reset(new OrthancDatabases::SQLiteIndex("index.db")); // TODO parameter | |
67 | |
68 /* Register the SQLite index into Orthanc */ | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
69 OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); |
0 | 70 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
71 catch (Orthanc::OrthancException& e) |
0 | 72 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
73 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
74 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
75 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
76 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
77 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 79 return -1; |
80 } | |
81 | |
82 return 0; | |
83 } | |
84 | |
85 | |
86 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
87 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
88 LOG(WARNING) << "SQLite index is finalizing"; |
0 | 89 backend_.reset(NULL); |
90 } | |
91 | |
92 | |
93 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
94 { | |
95 return "sqlite-index"; | |
96 } | |
97 | |
98 | |
99 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
100 { | |
101 return ORTHANC_PLUGIN_VERSION; | |
102 } | |
103 } |