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