Mercurial > hg > orthanc-databases
annotate SQLite/Plugins/IndexPlugin.cpp @ 2:17bce6a07b2b
storage plugin skeletons
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 05 Jul 2018 15:06:32 +0200 |
parents | 7cea966b6829 |
children | 17f849b2af34 |
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" | |
23 | |
24 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> | |
25 #include <Core/Logging.h> | |
26 | |
27 static std::auto_ptr<OrthancDatabases::SQLiteIndex> backend_; | |
28 | |
29 | |
30 static bool DisplayPerformanceWarning() | |
31 { | |
32 (void) DisplayPerformanceWarning; // Disable warning about unused function | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
33 LOG(WARNING) << "Performance warning in SQLite index: " |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
34 << "Non-release build, runtime debug assertions are turned on"; |
0 | 35 return true; |
36 } | |
37 | |
38 | |
39 extern "C" | |
40 { | |
41 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
42 { | |
43 Orthanc::Logging::Initialize(context); | |
44 | |
45 assert(DisplayPerformanceWarning()); | |
46 | |
47 /* Check the version of the Orthanc core */ | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
48 if (OrthancPluginCheckVersion(context) == 0) |
0 | 49 { |
50 char info[1024]; | |
51 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
52 context->orthancVersion, |
0 | 53 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
54 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
55 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
56 OrthancPluginLogError(context, info); |
0 | 57 return -1; |
58 } | |
59 | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
60 OrthancPluginSetDescription(context, "Stores the Orthanc index into a SQLite database."); |
0 | 61 |
62 #if 0 | |
63 OrthancPlugins::OrthancConfiguration configuration(context); | |
64 | |
65 if (!configuration.IsSection("SQLite")) | |
66 { | |
67 LOG(WARNING) << "No available configuration for the SQLite index plugin"; | |
68 return 0; | |
69 } | |
70 | |
71 OrthancPlugins::OrthancConfiguration sqlite; | |
72 configuration.GetSection(sqlite, "SQLite"); | |
73 | |
74 bool enable; | |
75 if (!sqlite.LookupBooleanValue(enable, "EnableIndex") || | |
76 !enable) | |
77 { | |
78 LOG(WARNING) << "The SQLite index is currently disabled, set \"EnableIndex\" " | |
79 << "to \"true\" in the \"SQLite\" section of the configuration file of Orthanc"; | |
80 return 0; | |
81 } | |
82 #endif | |
83 | |
84 try | |
85 { | |
86 /* Create the database back-end */ | |
87 backend_.reset(new OrthancDatabases::SQLiteIndex("index.db")); // TODO parameter | |
88 | |
89 /* Register the SQLite index into Orthanc */ | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
90 OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); |
0 | 91 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
92 catch (Orthanc::OrthancException& e) |
0 | 93 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
94 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
95 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
96 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
97 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
98 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
99 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 100 return -1; |
101 } | |
102 | |
103 return 0; | |
104 } | |
105 | |
106 | |
107 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
108 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
109 LOG(WARNING) << "SQLite index is finalizing"; |
0 | 110 backend_.reset(NULL); |
111 } | |
112 | |
113 | |
114 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
115 { | |
116 return "sqlite-index"; | |
117 } | |
118 | |
119 | |
120 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
121 { | |
122 return ORTHANC_PLUGIN_VERSION; | |
123 } | |
124 } |