comparison PostgreSQL/Plugins/StoragePlugin.cpp @ 2:17bce6a07b2b

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