Mercurial > hg > orthanc-databases
annotate MySQL/Plugins/IndexPlugin.cpp @ 217:ee5858d438dc
TransactionType given to MySQLTransaction constructor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Mar 2021 18:02:34 +0100 |
parents | c2e4a909de0e |
children | c8e06b41feec |
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 | |
193
3236894320d6
upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
163
diff
changeset
|
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium |
0 | 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
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
24 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 25 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
26 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 27 #include <HttpClient.h> |
28 #include <Logging.h> | |
29 #include <Toolbox.h> | |
0 | 30 |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
31 static std::unique_ptr<OrthancDatabases::MySQLIndex> backend_; |
0 | 32 |
33 | |
34 extern "C" | |
35 { | |
36 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
37 { | |
28
c0cb5d2cd696
checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
38 if (!OrthancDatabases::InitializePlugin(context, "MySQL", true)) |
0 | 39 { |
40 return -1; | |
41 } | |
42 | |
42 | 43 Orthanc::Toolbox::InitializeOpenSsl(); |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
44 Orthanc::HttpClient::GlobalInitialize(); |
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
45 |
62
eedd082355f9
fix for compatibility with simplified OrthancPluginCppWrapper
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
42
diff
changeset
|
46 OrthancPlugins::OrthancConfiguration configuration; |
0 | 47 |
48 if (!configuration.IsSection("MySQL")) | |
49 { | |
50 LOG(WARNING) << "No available configuration for the MySQL index plugin"; | |
51 return 0; | |
52 } | |
53 | |
54 OrthancPlugins::OrthancConfiguration mysql; | |
55 configuration.GetSection(mysql, "MySQL"); | |
56 | |
57 bool enable; | |
58 if (!mysql.LookupBooleanValue(enable, "EnableIndex") || | |
59 !enable) | |
60 { | |
61 LOG(WARNING) << "The MySQL index is currently disabled, set \"EnableIndex\" " | |
62 << "to \"true\" in the \"MySQL\" section of the configuration file of Orthanc"; | |
63 return 0; | |
64 } | |
65 | |
66 try | |
67 { | |
163
4d32c9c8d6c0
Added support for TLS connections
Alain Mazy <alain@mazy.be>
parents:
157
diff
changeset
|
68 OrthancDatabases::MySQLParameters parameters(mysql, configuration); |
0 | 69 |
70 /* Create the database back-end */ | |
201
42990b2dd51b
create IDatabaseBackendOutput only if needed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
200
diff
changeset
|
71 backend_.reset(new OrthancDatabases::MySQLIndex(context, parameters)); |
0 | 72 |
73 /* Register the MySQL index into Orthanc */ | |
213
c2e4a909de0e
added IndexBackend::Register() to be used in all the index plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
207
diff
changeset
|
74 OrthancDatabases::IndexBackend::Register(*backend_); |
0 | 75 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
76 catch (Orthanc::OrthancException& e) |
0 | 77 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
79 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
80 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
81 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
82 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
83 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 84 return -1; |
85 } | |
86 | |
87 return 0; | |
88 } | |
89 | |
90 | |
91 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
92 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
93 LOG(WARNING) << "MySQL index is finalizing"; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
94 |
0 | 95 backend_.reset(NULL); |
96 OrthancDatabases::MySQLDatabase::GlobalFinalization(); | |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
97 Orthanc::HttpClient::GlobalFinalize(); |
42 | 98 Orthanc::Toolbox::FinalizeOpenSsl(); |
0 | 99 } |
100 | |
101 | |
102 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
103 { | |
104 return "mysql-index"; | |
105 } | |
106 | |
107 | |
108 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
109 { | |
110 return ORTHANC_PLUGIN_VERSION; | |
111 } | |
112 } |