annotate Plugins/Engine/PluginsManager.cpp @ 3916:0e3849268a55 transcoding

new plugin SDK primitives related to OrthancPluginDicomInstance
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 11 May 2020 21:07:36 +0200
parents 2a170a8f1faf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1672
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1272
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * In addition, as a special exception, the copyright holders of this
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * program give permission to link the code of its release with the
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * that use the same license as the "OpenSSL" library), and distribute
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * the linked executables. You must obey the GNU General Public License
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * in all respects for all of the code used other than "OpenSSL". If you
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * modify file(s) with this exception, you may extend this exception to
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * your version of the file(s), but you are not obligated to do so. If
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * you do not wish to do so, delete this exception statement from your
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * version. If you delete this exception statement from all source files
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 * in the program, then also delete it here.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful, but
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 * WITHOUT ANY WARRANTY; without even the implied warranty of
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 * General Public License for more details.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 *
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 **/
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
1625
c17b1142caab reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1624
diff changeset
34 #include "../../OrthancServer/PrecompiledHeadersServer.h"
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 #include "PluginsManager.h"
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1983
diff changeset
37 #if ORTHANC_ENABLE_PLUGINS != 1
1632
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
38 #error The plugin support is disabled
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
39 #endif
eb8fbcf008b5 fix build with plugins disabled
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
40
897
bafc9d592632 REST callbacks are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 896
diff changeset
41 #include "../../Core/HttpServer/HttpOutput.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1337
diff changeset
42 #include "../../Core/Logging.h"
2463
be5c0f4155f6 move SharedLibrary into OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
43 #include "../../Core/OrthancException.h"
be5c0f4155f6 move SharedLibrary into OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
44 #include "../../Core/Toolbox.h"
894
690aeb4cb899 REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 893
diff changeset
45
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #include <cassert>
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 #include <memory>
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
48 #include <boost/filesystem.hpp>
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
49
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
50 #ifdef WIN32
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
51 #define PLUGIN_EXTENSION ".dll"
2364
ae50eccd41b7 compilation succeeds on OpenBSD
jodogne
parents: 2244
diff changeset
52 #elif defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__)
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
53 #define PLUGIN_EXTENSION ".so"
1026
a13ccd93df28 fix OS X build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 944
diff changeset
54 #elif defined(__APPLE__) && defined(__MACH__)
a13ccd93df28 fix OS X build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 944
diff changeset
55 #define PLUGIN_EXTENSION ".dylib"
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
56 #else
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
57 #error Support your platform here
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
58 #endif
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
59
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 namespace Orthanc
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
63 PluginsManager::Plugin::Plugin(PluginsManager& pluginManager,
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
64 const std::string& path) :
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
65 library_(path),
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
66 pluginManager_(pluginManager)
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
67 {
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
68 memset(&context_, 0, sizeof(context_));
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
69 context_.pluginsManager = this;
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
70 context_.orthancVersion = ORTHANC_VERSION;
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
71 context_.Free = ::free;
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
72 context_.InvokeService = InvokeService;
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
73 }
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
74
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
75
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 static void CallInitialize(SharedLibrary& plugin,
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 const OrthancPluginContext& context)
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 typedef int32_t (*Initialize) (const OrthancPluginContext*);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
81 #if defined(_WIN32)
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
82 Initialize initialize = (Initialize) plugin.GetFunction("OrthancPluginInitialize");
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
83 #else
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 /**
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 * gcc would complain about "ISO C++ forbids casting between
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 * pointer-to-function and pointer-to-object" without the trick
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 * below, that is known as "the POSIX.1-2003 (Technical Corrigendum
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 * 1) workaround". See the man page of "dlsym()".
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 * http://www.trilithium.com/johan/2004/12/problem-with-dlsym/
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 * http://stackoverflow.com/a/14543811/881731
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 **/
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 Initialize initialize;
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 *(void **) (&initialize) = plugin.GetFunction("OrthancPluginInitialize");
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
95 #endif
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
96
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 assert(initialize != NULL);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 int32_t error = initialize(&context);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (error != 0)
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 LOG(ERROR) << "Error while initializing plugin " << plugin.GetPath()
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 << " (code " << error << ")";
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 throw OrthancException(ErrorCode_SharedLibrary);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 static void CallFinalize(SharedLibrary& plugin)
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 typedef void (*Finalize) ();
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
113 #if defined(_WIN32)
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
114 Finalize finalize = (Finalize) plugin.GetFunction("OrthancPluginFinalize");
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
115 #else
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 Finalize finalize;
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 *(void **) (&finalize) = plugin.GetFunction("OrthancPluginFinalize");
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
118 #endif
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
119
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 assert(finalize != NULL);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 finalize();
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
125 static const char* CallGetName(SharedLibrary& plugin)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
126 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
127 typedef const char* (*GetName) ();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
128
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
129 #if defined(_WIN32)
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
130 GetName getName = (GetName) plugin.GetFunction("OrthancPluginGetName");
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
131 #else
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
132 GetName getName;
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
133 *(void **) (&getName) = plugin.GetFunction("OrthancPluginGetName");
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
134 #endif
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
135
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
136 assert(getName != NULL);
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
137 return getName();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
138 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
139
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
140
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
141 static const char* CallGetVersion(SharedLibrary& plugin)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
142 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
143 typedef const char* (*GetVersion) ();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
144
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
145 #if defined(_WIN32)
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
146 GetVersion getVersion = (GetVersion) plugin.GetFunction("OrthancPluginGetVersion");
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
147 #else
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
148 GetVersion getVersion;
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
149 *(void **) (&getVersion) = plugin.GetFunction("OrthancPluginGetVersion");
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
150 #endif
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
151
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
152 assert(getVersion != NULL);
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
153 return getVersion();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
154 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
155
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
156
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
157 OrthancPluginErrorCode PluginsManager::InvokeService(OrthancPluginContext* context,
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
158 _OrthancPluginService service,
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
159 const void* params)
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
161 switch (service)
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
162 {
907
9b8298234254 documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 904
diff changeset
163 case _OrthancPluginService_LogError:
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
164 LOG(ERROR) << reinterpret_cast<const char*>(params);
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
165 return OrthancPluginErrorCode_Success;
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
166
907
9b8298234254 documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 904
diff changeset
167 case _OrthancPluginService_LogWarning:
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
168 LOG(WARNING) << reinterpret_cast<const char*>(params);
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
169 return OrthancPluginErrorCode_Success;
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
170
907
9b8298234254 documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 904
diff changeset
171 case _OrthancPluginService_LogInfo:
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
172 LOG(INFO) << reinterpret_cast<const char*>(params);
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
173 return OrthancPluginErrorCode_Success;
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
174
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
175 default:
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
176 break;
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
177 }
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
178
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
179 Plugin* that = reinterpret_cast<Plugin*>(context->pluginsManager);
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
180
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
181 for (std::list<IPluginServiceProvider*>::iterator
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
182 it = that->GetPluginManager().serviceProviders_.begin();
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
183 it != that->GetPluginManager().serviceProviders_.end(); ++it)
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
184 {
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
185 try
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
186 {
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
187 if ((*it)->InvokeService(that->GetSharedLibrary(), service, params))
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
188 {
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
189 return OrthancPluginErrorCode_Success;
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
190 }
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
191 }
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
192 catch (OrthancException& e)
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
193 {
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
194 // This service provider has failed
1983
0af087300b26 disable error log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
195 if (e.GetErrorCode() != ErrorCode_UnknownResource) // This error code is valid in plugins
0af087300b26 disable error log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
196 {
0af087300b26 disable error log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
197 LOG(ERROR) << "Exception while invoking plugin service " << service << ": " << e.What();
0af087300b26 disable error log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
198 }
0af087300b26 disable error log
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1976
diff changeset
199
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
200 return static_cast<OrthancPluginErrorCode>(e.GetErrorCode());
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
201 }
898
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
202 }
7000fc86fe62 improved plugin api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 897
diff changeset
203
1581
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
204 LOG(ERROR) << "Plugin invoking unknown service: " << service;
357c4bb15701 Plugins have access to explicit error codes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
205 return OrthancPluginErrorCode_UnknownPluginService;
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
899
bb0a51561016 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 898
diff changeset
209 PluginsManager::PluginsManager()
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 {
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 PluginsManager::~PluginsManager()
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
944
c068671d12a9 fixes thanks to cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 907
diff changeset
215 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); ++it)
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 {
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
217 if (it->second != NULL)
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
219 LOG(WARNING) << "Unregistering plugin '" << it->first
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
220 << "' (version " << it->second->GetVersion() << ")";
893
f57802f8b4dc plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 889
diff changeset
221
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
222 CallFinalize(it->second->GetSharedLibrary());
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
223 delete it->second;
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
228
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
229 static bool IsOrthancPlugin(SharedLibrary& library)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
230 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
231 return (library.HasFunction("OrthancPluginInitialize") &&
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
232 library.HasFunction("OrthancPluginFinalize") &&
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
233 library.HasFunction("OrthancPluginGetName") &&
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
234 library.HasFunction("OrthancPluginGetVersion"));
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
235 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
236
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 void PluginsManager::RegisterPlugin(const std::string& path)
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 {
1272
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
240 if (!boost::filesystem::exists(path))
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
241 {
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
242 LOG(ERROR) << "Inexistent path to plugins: " << path;
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
243 return;
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
244 }
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
245
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
246 if (boost::filesystem::is_directory(path))
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
247 {
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
248 ScanFolderForPlugins(path, false);
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
249 return;
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
250 }
7442097b41c9 Scan of folders for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1232
diff changeset
251
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
252 std::unique_ptr<Plugin> plugin(new Plugin(*this, path));
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
254 if (!IsOrthancPlugin(plugin->GetSharedLibrary()))
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
256 LOG(ERROR) << "Plugin " << plugin->GetSharedLibrary().GetPath()
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 << " does not declare the proper entry functions";
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 throw OrthancException(ErrorCode_SharedLibrary);
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
261 std::string name(CallGetName(plugin->GetSharedLibrary()));
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
262 if (plugins_.find(name) != plugins_.end())
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
263 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
264 LOG(ERROR) << "Plugin '" << name << "' already registered";
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
265 throw OrthancException(ErrorCode_SharedLibrary);
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
266 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
267
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
268 plugin->SetVersion(CallGetVersion(plugin->GetSharedLibrary()));
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
269 LOG(WARNING) << "Registering plugin '" << name
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
270 << "' (version " << plugin->GetVersion() << ")";
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
1630
ffd23c0104af "/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1625
diff changeset
272 CallInitialize(plugin->GetSharedLibrary(), plugin->GetContext());
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
274 plugins_[name] = plugin.release();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
275 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
276
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
277
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
278 void PluginsManager::ScanFolderForPlugins(const std::string& folder,
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
279 bool isRecursive)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
280 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
281 using namespace boost::filesystem;
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
282
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
283 if (!exists(folder))
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
284 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
285 return;
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
286 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
287
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
288 LOG(INFO) << "Scanning folder " << folder << " for plugins";
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
289
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
290 directory_iterator end_it; // default construction yields past-the-end
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
291 for (directory_iterator it(folder);
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
292 it != end_it;
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
293 ++it)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
294 {
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
295 std::string path = it->path().string();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
296
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
297 if (is_directory(it->status()))
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
298 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
299 if (isRecursive)
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
300 {
889
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 888
diff changeset
301 ScanFolderForPlugins(path, true);
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
302 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
303 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
304 else
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
305 {
1323
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
306 std::string extension = boost::filesystem::extension(it->path());
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
307 Toolbox::ToLowerCase(extension);
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
308
5a92665dee23 Sample plugin: Serve folders
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1304
diff changeset
309 if (extension == PLUGIN_EXTENSION)
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
310 {
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
311 LOG(INFO) << "Found a shared library: " << it->path();
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
312
1297
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
313 SharedLibrary plugin(path);
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
314 if (IsOrthancPlugin(plugin))
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
315 {
1297
501432928727 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
316 RegisterPlugin(path);
888
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
317 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
318 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
319 }
d44b845c1c89 recursive scan for plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 887
diff changeset
320 }
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 }
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
322
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
323
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
324 void PluginsManager::ListPlugins(std::list<std::string>& result) const
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
325 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
326 result.clear();
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
327
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
328 for (Plugins::const_iterator it = plugins_.begin();
1304
7b6925b0890d cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1297
diff changeset
329 it != plugins_.end(); ++it)
1232
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
330 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
331 result.push_back(it->first);
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
332 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
333 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
334
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
335
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
336 bool PluginsManager::HasPlugin(const std::string& name) const
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
337 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
338 return plugins_.find(name) != plugins_.end();
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
339 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
340
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
341
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
342 const std::string& PluginsManager::GetPluginVersion(const std::string& name) const
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
343 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
344 Plugins::const_iterator it = plugins_.find(name);
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
345 if (it == plugins_.end())
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
346 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
347 throw OrthancException(ErrorCode_ParameterOutOfRange);
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
348 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
349 else
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
350 {
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
351 return it->second->GetVersion();
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
352 }
f1c01451a8ee Introspection of plugins, Plugins can extend Orthanc Explorer with custom JavaScript
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1200
diff changeset
353 }
1644
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
354
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
355
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
356 std::string PluginsManager::GetPluginName(SharedLibrary& library)
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
357 {
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
358 return CallGetName(library);
939b921b2c81 plugin error dictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1632
diff changeset
359 }
887
4066e6f2d134 PluginsManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 }