Mercurial > hg > orthanc
annotate OrthancServer/Resources/Graveyard/DatabasePluginSample/Plugin.cpp @ 5765:247fc5368693 find-refactoring
un-sharing DatabaseConstraint and ISqlLookupFormatter with orthanc-databases
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 09 Sep 2024 16:14:22 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
1671 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1671 | 4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1671 | 8 * |
9 * This program is free software: you can redistribute it and/or | |
10 * modify it under the terms of the GNU General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, but | |
15 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 * General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "Database.h" | |
25 | |
26 #include <memory> | |
27 #include <iostream> | |
28 #include <boost/algorithm/string/predicate.hpp> | |
29 | |
30 static OrthancPluginContext* context_ = NULL; | |
31 static std::auto_ptr<OrthancPlugins::IDatabaseBackend> backend_; | |
32 | |
33 | |
34 extern "C" | |
35 { | |
36 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* c) | |
37 { | |
38 context_ = c; | |
39 OrthancPluginLogWarning(context_, "Sample plugin is initializing"); | |
40 | |
41 /* Check the version of the Orthanc core */ | |
42 if (OrthancPluginCheckVersion(c) == 0) | |
43 { | |
44 char info[256]; | |
45 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", | |
46 c->orthancVersion, | |
47 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, | |
48 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, | |
49 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); | |
50 OrthancPluginLogError(context_, info); | |
51 return -1; | |
52 } | |
53 | |
54 std::string path = "SampleDatabase.sqlite"; | |
55 uint32_t argCount = OrthancPluginGetCommandLineArgumentsCount(context_); | |
56 for (uint32_t i = 0; i < argCount; i++) | |
57 { | |
58 char* tmp = OrthancPluginGetCommandLineArgument(context_, i); | |
59 std::string argument(tmp); | |
60 OrthancPluginFreeString(context_, tmp); | |
61 | |
62 if (boost::starts_with(argument, "--database=")) | |
63 { | |
64 path = argument.substr(11); | |
65 } | |
66 } | |
67 | |
68 std::string s = "Using the following SQLite database: " + path; | |
69 OrthancPluginLogWarning(context_, s.c_str()); | |
70 | |
71 backend_.reset(new Database(path)); | |
72 OrthancPlugins::DatabaseBackendAdapter::Register(context_, *backend_); | |
73 | |
74 return 0; | |
75 } | |
76 | |
77 ORTHANC_PLUGINS_API void OrthancPluginFinalize() | |
78 { | |
79 backend_.reset(NULL); | |
80 } | |
81 | |
82 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() | |
83 { | |
84 return "sample-database"; | |
85 } | |
86 | |
87 | |
88 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() | |
89 { | |
90 return "1.0"; | |
91 } | |
92 } |