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