diff options
author | Mark Spruiell <mes@zeroc.com> | 2006-04-26 03:22:49 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2006-04-26 03:22:49 +0000 |
commit | d24b35ce1f999f86c6f856821d51f4adf72c76e6 (patch) | |
tree | b1d1dbe50724a4d42ce1e46622aa49fde0a5492d /cpp/src/Ice/PluginManagerI.cpp | |
parent | use two stages for plugin initialization; refactoring to remove Context (diff) | |
download | ice-d24b35ce1f999f86c6f856821d51f4adf72c76e6.tar.bz2 ice-d24b35ce1f999f86c6f856821d51f4adf72c76e6.tar.xz ice-d24b35ce1f999f86c6f856821d51f4adf72c76e6.zip |
use two stages for plugin initialization
Diffstat (limited to 'cpp/src/Ice/PluginManagerI.cpp')
-rw-r--r-- | cpp/src/Ice/PluginManagerI.cpp | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/cpp/src/Ice/PluginManagerI.cpp b/cpp/src/Ice/PluginManagerI.cpp index 7d65df2234c..c5cf4648f0e 100644 --- a/cpp/src/Ice/PluginManagerI.cpp +++ b/cpp/src/Ice/PluginManagerI.cpp @@ -19,10 +19,55 @@ using namespace std; using namespace Ice; using namespace IceInternal; -const char * const Ice::PluginManagerI::_kindOfObject = "plug-in"; +const char * const Ice::PluginManagerI::_kindOfObject = "plugin"; typedef Ice::Plugin* (*PLUGIN_FACTORY)(const CommunicatorPtr&, const string&, const StringSeq&); +void +Ice::PluginManagerI::initializePlugins() +{ + if(_initialized) + { + InitializationException ex(__FILE__, __LINE__); + ex.reason = "plugins already initialized"; + throw ex; + } + + // + // Invoke initialize() on the plugins, in the order they were loaded. + // + vector<PluginPtr> initializedPlugins; + try + { + for(vector<PluginPtr>::iterator p = _initOrder.begin(); p != _initOrder.end(); ++p) + { + (*p)->initialize(); + initializedPlugins.push_back(*p); + } + } + catch(...) + { + // + // Destroy the plugins that have been successfully initialized, in the + // reverse order. + // + for(vector<PluginPtr>::reverse_iterator p = initializedPlugins.rbegin(); p != initializedPlugins.rend(); ++p) + { + try + { + (*p)->destroy(); + } + catch(...) + { + // Ignore. + } + } + throw; + } + + _initialized = true; +} + PluginPtr Ice::PluginManagerI::getPlugin(const string& name) { @@ -88,7 +133,8 @@ Ice::PluginManagerI::destroy() Ice::PluginManagerI::PluginManagerI(const CommunicatorPtr& communicator, const DynamicLibraryListPtr& libraries) : _communicator(communicator), - _libraries(libraries) + _libraries(libraries), + _initialized(false) { } @@ -115,7 +161,7 @@ Ice::PluginManagerI::loadPlugins(int& argc, char* argv[]) PropertyDict plugins = properties->getPropertiesForPrefix(prefix); string loadOrder = properties->getProperty("Ice.PluginLoadOrder"); - string::size_type beg = 0;
+ string::size_type beg = 0; if(!loadOrder.empty()) { const string delim = ", \t\n"; @@ -169,6 +215,16 @@ Ice::PluginManagerI::loadPlugins(int& argc, char* argv[]) } stringSeqToArgs(cmdArgs, argc, argv); + + // + // An application can set Ice.InitPlugins=0 if it wants to postpone + // initialization until after it has interacted directly with the + // plugins. + // + if(properties->getPropertyAsIntWithDefault("Ice.InitPlugins", 1) > 0) + { + initializePlugins(); + } } void @@ -253,4 +309,5 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& pluginSpec, St _libraries->add(library); _plugins[name] = plugin; + _initOrder.push_back(plugin); } |