comparison PostgreSQL/Plugins/IndexPlugin.cpp @ 0:7cea966b6829

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