comparison Plugins/Engine/PluginsManager.cpp @ 1630:ffd23c0104af

"/system" URI gives information about the plugins used for storage area and DB back-end
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Sep 2015 13:26:45 +0200
parents c17b1142caab
children eb8fbcf008b5
comparison
equal deleted inserted replaced
1629:bad4772b605c 1630:ffd23c0104af
52 #endif 52 #endif
53 53
54 54
55 namespace Orthanc 55 namespace Orthanc
56 { 56 {
57 PluginsManager::Plugin::Plugin(PluginsManager& pluginManager,
58 const std::string& path) :
59 library_(path),
60 pluginManager_(pluginManager)
61 {
62 memset(&context_, 0, sizeof(context_));
63 context_.pluginsManager = this;
64 context_.orthancVersion = ORTHANC_VERSION;
65 context_.Free = ::free;
66 context_.InvokeService = InvokeService;
67 }
68
69
57 static void CallInitialize(SharedLibrary& plugin, 70 static void CallInitialize(SharedLibrary& plugin,
58 const OrthancPluginContext& context) 71 const OrthancPluginContext& context)
59 { 72 {
60 typedef int32_t (*Initialize) (const OrthancPluginContext*); 73 typedef int32_t (*Initialize) (const OrthancPluginContext*);
61 74
155 168
156 default: 169 default:
157 break; 170 break;
158 } 171 }
159 172
160 PluginsManager* that = reinterpret_cast<PluginsManager*>(context->pluginsManager); 173 Plugin* that = reinterpret_cast<Plugin*>(context->pluginsManager);
161 174
162 for (std::list<IPluginServiceProvider*>::iterator 175 for (std::list<IPluginServiceProvider*>::iterator
163 it = that->serviceProviders_.begin(); 176 it = that->GetPluginManager().serviceProviders_.begin();
164 it != that->serviceProviders_.end(); ++it) 177 it != that->GetPluginManager().serviceProviders_.end(); ++it)
165 { 178 {
166 try 179 try
167 { 180 {
168 if ((*it)->InvokeService(service, params)) 181 if ((*it)->InvokeService(that->GetSharedLibrary(), service, params))
169 { 182 {
170 return OrthancPluginErrorCode_Success; 183 return OrthancPluginErrorCode_Success;
171 } 184 }
172 } 185 }
173 catch (OrthancException& e) 186 catch (OrthancException& e)
183 } 196 }
184 197
185 198
186 PluginsManager::PluginsManager() 199 PluginsManager::PluginsManager()
187 { 200 {
188 memset(&context_, 0, sizeof(context_));
189 context_.pluginsManager = this;
190 context_.orthancVersion = ORTHANC_VERSION;
191 context_.Free = ::free;
192 context_.InvokeService = InvokeService;
193 } 201 }
194 202
195 PluginsManager::~PluginsManager() 203 PluginsManager::~PluginsManager()
196 { 204 {
197 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); ++it) 205 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); ++it)
199 if (it->second != NULL) 207 if (it->second != NULL)
200 { 208 {
201 LOG(WARNING) << "Unregistering plugin '" << it->first 209 LOG(WARNING) << "Unregistering plugin '" << it->first
202 << "' (version " << it->second->GetVersion() << ")"; 210 << "' (version " << it->second->GetVersion() << ")";
203 211
204 CallFinalize(it->second->GetLibrary()); 212 CallFinalize(it->second->GetSharedLibrary());
205 delete it->second; 213 delete it->second;
206 } 214 }
207 } 215 }
208 } 216 }
209 217
229 { 237 {
230 ScanFolderForPlugins(path, false); 238 ScanFolderForPlugins(path, false);
231 return; 239 return;
232 } 240 }
233 241
234 std::auto_ptr<Plugin> plugin(new Plugin(path)); 242 std::auto_ptr<Plugin> plugin(new Plugin(*this, path));
235 243
236 if (!IsOrthancPlugin(plugin->GetLibrary())) 244 if (!IsOrthancPlugin(plugin->GetSharedLibrary()))
237 { 245 {
238 LOG(ERROR) << "Plugin " << plugin->GetLibrary().GetPath() 246 LOG(ERROR) << "Plugin " << plugin->GetSharedLibrary().GetPath()
239 << " does not declare the proper entry functions"; 247 << " does not declare the proper entry functions";
240 throw OrthancException(ErrorCode_SharedLibrary); 248 throw OrthancException(ErrorCode_SharedLibrary);
241 } 249 }
242 250
243 std::string name(CallGetName(plugin->GetLibrary())); 251 std::string name(CallGetName(plugin->GetSharedLibrary()));
244 if (plugins_.find(name) != plugins_.end()) 252 if (plugins_.find(name) != plugins_.end())
245 { 253 {
246 LOG(ERROR) << "Plugin '" << name << "' already registered"; 254 LOG(ERROR) << "Plugin '" << name << "' already registered";
247 throw OrthancException(ErrorCode_SharedLibrary); 255 throw OrthancException(ErrorCode_SharedLibrary);
248 } 256 }
249 257
250 plugin->SetVersion(CallGetVersion(plugin->GetLibrary())); 258 plugin->SetVersion(CallGetVersion(plugin->GetSharedLibrary()));
251 LOG(WARNING) << "Registering plugin '" << name 259 LOG(WARNING) << "Registering plugin '" << name
252 << "' (version " << plugin->GetVersion() << ")"; 260 << "' (version " << plugin->GetVersion() << ")";
253 261
254 CallInitialize(plugin->GetLibrary(), context_); 262 CallInitialize(plugin->GetSharedLibrary(), plugin->GetContext());
255 263
256 plugins_[name] = plugin.release(); 264 plugins_[name] = plugin.release();
257 } 265 }
258 266
259 267
331 else 339 else
332 { 340 {
333 return it->second->GetVersion(); 341 return it->second->GetVersion();
334 } 342 }
335 } 343 }
336
337 } 344 }