From 04083c21d70aa054ccc82caab4743b2aae0d93c0 Mon Sep 17 00:00:00 2001 From: "Stephen D. Huston" Date: Sun, 26 Oct 2008 01:04:32 +0000 Subject: Refactor duplicated Module-handling from broker/client to common git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@707924 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/client/LoadPlugins.cpp | 72 +++++++------------------------------ 1 file changed, 13 insertions(+), 59 deletions(-) (limited to 'cpp/src/qpid/client') diff --git a/cpp/src/qpid/client/LoadPlugins.cpp b/cpp/src/qpid/client/LoadPlugins.cpp index ddfa179c07..b395226859 100644 --- a/cpp/src/qpid/client/LoadPlugins.cpp +++ b/cpp/src/qpid/client/LoadPlugins.cpp @@ -18,78 +18,32 @@ * under the License. * */ -#include "qpid/log/Statement.h" -#include "qpid/log/Options.h" -#include "qpid/log/Logger.h" -#include "qpid/sys/Shlib.h" -#include -#include - -using namespace qpid; -using namespace qpid::sys; -using namespace qpid::log; -using namespace std; -namespace fs=boost::filesystem; - -struct ModuleOptions : public qpid::Options { - string loadDir; - vector load; - bool noLoad; - ModuleOptions() : qpid::Options("Module options"), loadDir(MODULE_DIR), noLoad(false) - { - addOptions() - ("module-dir", optValue(loadDir, "DIR"), "Load all .so modules in this directory") - ("load-module", optValue(load, "FILE"), "Specifies additional module(s) to be loaded") - ("no-module-dir", optValue(noLoad), "Don't load modules from module directory"); - } -}; - -// TODO: The following is copied from qpidd.cpp - it needs to be common code -void tryShlib(const char* libname, bool noThrow) { - try { - Shlib shlib(libname); - QPID_LOG (info, "Loaded Module: " << libname); - } - catch (const exception& e) { - if (!noThrow) - throw; - } -} - -void loadModuleDir (string dirname, bool isDefault) -{ - fs::path dirPath (dirname, fs::native); - if (!fs::exists (dirPath)) - { - if (isDefault) - return; - throw Exception ("Directory not found: " + dirname); - } +#include "qpid/Modules.h" +#include "qpid/sys/Shlib.h" +#include +#include +using std::vector; +using std::string; - fs::directory_iterator endItr; - for (fs::directory_iterator itr (dirPath); itr != endItr; ++itr) - { - if (!fs::is_directory(*itr) && - itr->string().find (".so") == itr->string().length() - 3) - tryShlib (itr->string().data(), true); - } -} +namespace { struct LoadtimeInitialise { LoadtimeInitialise() { - ModuleOptions moduleOptions; - string defaultPath (moduleOptions.loadDir); + qpid::ModuleOptions moduleOptions(MODULE_DIR); + string defaultPath (moduleOptions.loadDir); moduleOptions.parse (0, 0, CONF_FILE, true); for (vector::iterator iter = moduleOptions.load.begin(); iter != moduleOptions.load.end(); iter++) - tryShlib (iter->data(), false); + qpid::tryShlib (iter->data(), false); if (!moduleOptions.noLoad) { bool isDefault = defaultPath == moduleOptions.loadDir; - loadModuleDir (moduleOptions.loadDir, isDefault); + qpid::loadModuleDir (moduleOptions.loadDir, isDefault); } } } init; + +} // namespace -- cgit v1.2.1