Mercurial > hg > orthanc-databases
annotate PostgreSQL/Plugins/IndexPlugin.cpp @ 16:9e419261f1c9
mysql storage area working
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Jul 2018 10:10:35 +0200 |
parents | 0217486720b3 |
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 "PostgreSQLIndex.h" | |
23 | |
24 #include <Core/Logging.h> | |
25 | |
26 static std::auto_ptr<OrthancDatabases::PostgreSQLIndex> backend_; | |
27 | |
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 PostgreSQL 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 PostgreSQL database."); |
0 | 61 |
62 OrthancPlugins::OrthancConfiguration configuration(context); | |
63 | |
64 if (!configuration.IsSection("PostgreSQL")) | |
65 { | |
66 LOG(WARNING) << "No available configuration for the PostgreSQL index plugin"; | |
67 return 0; | |
68 } | |
69 | |
70 OrthancPlugins::OrthancConfiguration postgresql; | |
71 configuration.GetSection(postgresql, "PostgreSQL"); | |
72 | |
73 bool enable; | |
74 if (!postgresql.LookupBooleanValue(enable, "EnableIndex") || | |
75 !enable) | |
76 { | |
77 LOG(WARNING) << "The PostgreSQL index is currently disabled, set \"EnableIndex\" " | |
78 << "to \"true\" in the \"PostgreSQL\" section of the configuration file of Orthanc"; | |
79 return 0; | |
80 } | |
81 | |
82 try | |
83 { | |
84 OrthancDatabases::PostgreSQLParameters parameters(postgresql); | |
85 | |
86 /* Create the database back-end */ | |
87 backend_.reset(new OrthancDatabases::PostgreSQLIndex(parameters)); | |
88 | |
89 /* Register the PostgreSQL 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 { | |
11 | 109 LOG(WARNING) << "PostgreSQL index is finalizing"; |
0 | 110 backend_.reset(NULL); |
111 } | |
112 | |
113 | |
114 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
115 { | |
116 return "postgresql-index"; | |
117 } | |
118 | |
119 | |
120 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
121 { | |
122 return ORTHANC_PLUGIN_VERSION; | |
123 } | |
124 } |