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