diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/DynamicLibrary.cpp | 52 | ||||
-rw-r--r-- | cpp/src/Ice/PluginManagerI.cpp | 93 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 44 |
3 files changed, 68 insertions, 121 deletions
diff --git a/cpp/src/Ice/DynamicLibrary.cpp b/cpp/src/Ice/DynamicLibrary.cpp index c0b197dcfdb..e713ea2e5f0 100644 --- a/cpp/src/Ice/DynamicLibrary.cpp +++ b/cpp/src/Ice/DynamicLibrary.cpp @@ -38,6 +38,58 @@ IceInternal::DynamicLibrary::~DynamicLibrary() } } +IceInternal::DynamicLibrary::symbol_type +IceInternal::DynamicLibrary::loadEntryPoint(const string& entryPoint) +{ + string::size_type colon = entryPoint.rfind(':'); + string::size_type comma = entryPoint.find(','); + if (colon == string::npos || colon == entryPoint.size() - 1 || + (comma != string::npos && (comma > colon || comma == colon - 1))) + { + _err = "invalid entry point format `" + entryPoint + "'"; + return 0; + } + string libSpec = entryPoint.substr(0, colon); + string funcName = entryPoint.substr(colon + 1); + string libName, version, debug; + if (comma == string::npos) + { + libName = libSpec; + version = ICE_STRING_VERSION; + } + else + { + libName = libSpec.substr(0, comma); + version = libSpec.substr(comma + 1); + } + + string lib; + +#ifdef _WIN32 + lib = libName; + for (string::size_type n = 0; n < version.size(); n++) + { + if (version[n] != '.') // Remove periods + { + lib += version[n]; + } + } +# ifdef _DEBUG + lib += 'd'; +# endif + lib += ".dll"; +#else + lib = "lib" + libName + ".so." + version; +#endif + + if (!load(lib)) + { + return 0; + } + + return getSymbol(funcName); +} + bool IceInternal::DynamicLibrary::load(const string& lib) { diff --git a/cpp/src/Ice/PluginManagerI.cpp b/cpp/src/Ice/PluginManagerI.cpp index c0e6ecbf983..9d18d2ebfd6 100644 --- a/cpp/src/Ice/PluginManagerI.cpp +++ b/cpp/src/Ice/PluginManagerI.cpp @@ -137,101 +137,16 @@ void Ice::PluginManagerI::loadPlugin(const string& name, const string& entryPoint, const StringSeq& args) { // - // Parse the entry point. An entry point has the following format: - // - // name[,version]:function - // - // The name of the shared library/DLL is constructed from the - // given information. If no version is supplied, the Ice version - // is used. For example, consider the following entry point: - // - // foo:create - // - // This would result in libfoo.so.0.0.1 (Unix) and foo001.dll (Windows), - // where the Ice version is 0.0.1. - // - // Now consider this entry point: - // - // foo,1.1:create - // - // The library names in this case are libfoo.so.1.1 (Unix) and - // foo11.dll (Windows). - // - // On Windows platforms, a 'd' is appended to the version for debug - // builds. - // - string::size_type colon = entryPoint.rfind(':'); - string::size_type comma = entryPoint.find(','); - if (colon == string::npos || colon == entryPoint.size() - 1 || - (comma != string::npos && (comma > colon || comma == colon - 1))) - { - Error out(_instance->logger()); - out << "PluginManager: invalid entry point format `" << entryPoint << "'"; - SystemException ex(__FILE__, __LINE__); - ex.error = 0; - throw ex; - } - string libSpec = entryPoint.substr(0, colon); - string funcName = entryPoint.substr(colon + 1); - string libName, version, debug; - if (comma == string::npos) - { - libName = libSpec; - version = ICE_STRING_VERSION; - } - else - { - libName = libSpec.substr(0, comma); - version = libSpec.substr(comma + 1); - } - - string lib; - -#ifdef _WIN32 - lib = libName; - for (string::size_type n = 0; n < version.size(); n++) - { - if (version[n] != '.') // Remove periods - { - lib += version[n]; - } - } -# ifdef _DEBUG - lib += 'd'; -# endif - lib += ".dll"; -#else - lib = "lib" + libName + ".so." + version; -#endif - - // - // Load the dynamic library. + // Load the entry point symbol. // PluginInfo info; info.library = new DynamicLibrary(); - if (!info.library->load(lib)) - { - Error out(_instance->logger()); - string msg = info.library->getErrorMessage(); - out << "PluginManager: unable to load library `" << lib << "'"; - if (!msg.empty()) - { - out << ": " + msg; - } - SystemException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); - throw ex; - } - - // - // Lookup the factory function. - // - DynamicLibrary::symbol_type sym = info.library->getSymbol(funcName); + DynamicLibrary::symbol_type sym = info.library->loadEntryPoint(entryPoint); if (sym == 0) { Error out(_instance->logger()); string msg = info.library->getErrorMessage(); - out << "PluginManager: unable to find function `" << funcName << "' in library `" << lib << "'"; + out << "PluginManager: unable to load entry point `" << entryPoint << "'"; if (!msg.empty()) { out << ": " + msg; @@ -252,7 +167,7 @@ Ice::PluginManagerI::loadPlugin(const string& name, const string& entryPoint, co catch (const Exception& ex) { Error out(_instance->logger()); - out << "PluginManager: exception in factory function `" << funcName << "': " << ex.ice_name(); + out << "PluginManager: exception in entry point `" << entryPoint << "': " << ex.ice_name(); SystemException e(__FILE__, __LINE__); e.error = 0; throw e; diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index 28c6c47dd1c..e07a107139e 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -68,7 +68,7 @@ IceBox::ServiceManagerI::run() // with the prefix "IceBox.Service.". These properties should // have the following format: // - // IceBox.Service.Foo=libFoo.so:create [args] + // IceBox.Service.Foo=entry_point [args] // const string prefix = "IceBox.Service."; PropertiesPtr properties = _communicator->getProperties(); @@ -81,16 +81,16 @@ IceBox::ServiceManagerI::run() // // Separate the entry point from the arguments. // - string exec; + string entryPoint; StringSeq args; string::size_type pos = value.find_first_of(" \t\n"); if (pos == string::npos) { - exec = value; + entryPoint = value; } else { - exec = value.substr(0, pos); + entryPoint = value.substr(0, pos); string::size_type beg = value.find_first_not_of(" \t\n", pos); while (beg != string::npos) { @@ -108,7 +108,7 @@ IceBox::ServiceManagerI::run() } } - init(name, exec, args); + init(name, entryPoint, args); } // @@ -182,7 +182,7 @@ IceBox::ServiceManagerI::run() } IceBox::ServicePtr -IceBox::ServiceManagerI::init(const string& service, const string& exec, const StringSeq& args) +IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, const StringSeq& args) { // // We need to create a property set to pass to init(). @@ -225,23 +225,15 @@ IceBox::ServiceManagerI::init(const string& service, const string& exec, const S serviceArgs = serviceProperties->parseCommandLineOptions(service, serviceArgs); // - // Load the dynamic library. + // Load the entry point. // - string::size_type colon = exec.rfind(':'); - if (colon == string::npos || colon == exec.size() - 1) - { - FailureException ex; - ex.reason = "ServiceManager: invalid factory format `" + exec + "'"; - throw ex; - } - string libName = exec.substr(0, colon); - string funcName = exec.substr(colon + 1); DynamicLibraryPtr library = new DynamicLibrary(); - if (!library->load(libName)) + DynamicLibrary::symbol_type sym = library->loadEntryPoint(entryPoint); + if (sym == 0) { string msg = library->getErrorMessage(); FailureException ex; - ex.reason = "ServiceManager: unable to load library `" + libName + "'"; + ex.reason = "ServiceManager: unable to load entry point `" + entryPoint + "'"; if (!msg.empty()) { ex.reason += ": " + msg; @@ -250,20 +242,8 @@ IceBox::ServiceManagerI::init(const string& service, const string& exec, const S } // - // Lookup the factory function and invoke it. + // Invoke the factory function. // - DynamicLibrary::symbol_type sym = library->getSymbol(funcName); - if (sym == 0) - { - string msg = library->getErrorMessage(); - FailureException ex; - ex.reason = "ServiceManager: unable to load symbol `" + funcName + "'"; - if (!msg.empty()) - { - ex.reason += ": " + msg; - } - throw ex; - } SERVICE_FACTORY factory = (SERVICE_FACTORY)sym; ServiceInfo info; try @@ -273,7 +253,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& exec, const S catch (const Exception& ex) { FailureException e; - e.reason = "ServiceManager: exception in factory function `" + funcName + "': " + ex.ice_name(); + e.reason = "ServiceManager: exception in entry point `" + entryPoint + "': " + ex.ice_name(); throw e; } |