Mercurial > hg > orthanc-databases
annotate MySQL/Plugins/IndexPlugin.cpp @ 40:5600949bfb12
preparing for release
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 08:28:02 +0200 |
parents | c0cb5d2cd696 |
children | 4c3f767ead03 |
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 | |
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
17f849b2af34
sharing plugin initialization code
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2
diff
changeset
|
24 #include "../../Framework/Plugins/PluginInitialization.h" |
0 | 25 |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
26 #include <Core/HttpClient.h> |
0 | 27 #include <Core/Logging.h> |
28 | |
29 static std::auto_ptr<OrthancDatabases::MySQLIndex> backend_; | |
30 | |
31 | |
32 extern "C" | |
33 { | |
34 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) | |
35 { | |
28
c0cb5d2cd696
checks depending on Orthanc version
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
24
diff
changeset
|
36 if (!OrthancDatabases::InitializePlugin(context, "MySQL", true)) |
0 | 37 { |
38 return -1; | |
39 } | |
40 | |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
41 Orthanc::HttpClient::GlobalInitialize(); |
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
42 |
0 | 43 OrthancPlugins::OrthancConfiguration configuration(context); |
44 | |
45 if (!configuration.IsSection("MySQL")) | |
46 { | |
47 LOG(WARNING) << "No available configuration for the MySQL index plugin"; | |
48 return 0; | |
49 } | |
50 | |
51 OrthancPlugins::OrthancConfiguration mysql; | |
52 configuration.GetSection(mysql, "MySQL"); | |
53 | |
54 bool enable; | |
55 if (!mysql.LookupBooleanValue(enable, "EnableIndex") || | |
56 !enable) | |
57 { | |
58 LOG(WARNING) << "The MySQL index is currently disabled, set \"EnableIndex\" " | |
59 << "to \"true\" in the \"MySQL\" section of the configuration file of Orthanc"; | |
60 return 0; | |
61 } | |
62 | |
63 try | |
64 { | |
65 OrthancDatabases::MySQLParameters parameters(mysql); | |
66 | |
67 /* Create the database back-end */ | |
68 backend_.reset(new OrthancDatabases::MySQLIndex(parameters)); | |
69 | |
70 /* Register the MySQL index into Orthanc */ | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
71 OrthancPlugins::DatabaseBackendAdapter::Register(context, *backend_); |
0 | 72 } |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
73 catch (Orthanc::OrthancException& e) |
0 | 74 { |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
75 LOG(ERROR) << e.What(); |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
76 return -1; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
77 } |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
78 catch (...) |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
79 { |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
80 LOG(ERROR) << "Native exception while initializing the plugin"; |
0 | 81 return -1; |
82 } | |
83 | |
84 return 0; | |
85 } | |
86 | |
87 | |
88 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
89 { | |
2
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
90 LOG(WARNING) << "MySQL index is finalizing"; |
17bce6a07b2b
storage plugin skeletons
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
91 |
0 | 92 backend_.reset(NULL); |
93 OrthancDatabases::MySQLDatabase::GlobalFinalization(); | |
40
5600949bfb12
preparing for release
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
28
diff
changeset
|
94 Orthanc::HttpClient::GlobalFinalize(); |
0 | 95 } |
96 | |
97 | |
98 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
99 { | |
100 return "mysql-index"; | |
101 } | |
102 | |
103 | |
104 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
105 { | |
106 return ORTHANC_PLUGIN_VERSION; | |
107 } | |
108 } |