summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/client/LoadPlugins.cpp
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2008-10-26 01:04:32 +0000
committerStephen D. Huston <shuston@apache.org>2008-10-26 01:04:32 +0000
commit04083c21d70aa054ccc82caab4743b2aae0d93c0 (patch)
tree13820d1543bd9c8229fbe7f6962059b907411283 /cpp/src/qpid/client/LoadPlugins.cpp
parent5a36012aa3f1d1aeb26a548089f327e89cddf651 (diff)
downloadqpid-python-04083c21d70aa054ccc82caab4743b2aae0d93c0.tar.gz
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
Diffstat (limited to 'cpp/src/qpid/client/LoadPlugins.cpp')
-rw-r--r--cpp/src/qpid/client/LoadPlugins.cpp72
1 files changed, 13 insertions, 59 deletions
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 <boost/filesystem/operations.hpp>
-#include <boost/filesystem/path.hpp>
-
-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<string> 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 <string>
+#include <vector>
+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<string>::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