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