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