summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2011-03-15 01:03:52 +0000
committerrandomdan <randomdan@localhost>2011-03-15 01:03:52 +0000
commitaaa8d4b938163e194b1f58cdaba379ef4148e813 (patch)
tree9cfbd5d0b87d6a167fcbffb64896b990404e12d0
parentFix linking problem where binaries linked against the installed libs, not the... (diff)
downloadproject2-aaa8d4b938163e194b1f58cdaba379ef4148e813.tar.bz2
project2-aaa8d4b938163e194b1f58cdaba379ef4148e813.tar.xz
project2-aaa8d4b938163e194b1f58cdaba379ef4148e813.zip
Add element handler for loading extra libraries at runtime
-rw-r--r--project2/Jamfile.jam5
-rw-r--r--project2/xmlObjectLoader.cpp25
2 files changed, 30 insertions, 0 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam
index 575d4f9..24fa691 100644
--- a/project2/Jamfile.jam
+++ b/project2/Jamfile.jam
@@ -13,6 +13,7 @@ alias libxslt : : : :
<cflags>"`pkg-config --cflags libexslt`"
<linkflags>"`pkg-config --libs libexslt`" ;
+lib dl : : <name>dl ;
lib fcgi : : <name>fcgi ;
lib fcgi++ : : <name>fcgi++ ;
lib boost_regex : : <name>boost_regex ;
@@ -63,10 +64,14 @@ lib p2common :
:
<include>../libmisc
<library>libxmlpp
+ <library>dl
<library>boost_system
<library>boost_filesystem
<library>boost_date_time
<library>boost_program_options
+ : :
+ <include>.
+ <include>../libmisc
;
lib p2xml :
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index e16c9e1..849cfa1 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -4,6 +4,7 @@
#include "logger.h"
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
+#include <dlfcn.h>
#include <libxml++/nodes/textnode.h>
unsigned int LoaderBase::depth = 0;
@@ -17,10 +18,34 @@ objLoaders()
return _objLoaders;
}
+SimpleMessageException(LoadLibraryFailed);
+
+class Library : public SourceObject {
+ public:
+ Library(const xmlpp::Element * p) :
+ SourceObject(p),
+ handle(dlopen(p->get_attribute_value("path").c_str(), RTLD_NOW))
+ {
+ if (!handle) {
+ throw LoadLibraryFailed(dlerror());
+ }
+ }
+ ~Library() {
+ dlclose(handle);
+ }
+ void loadComplete(const CommonObjects*) {
+ }
+ private:
+ void * handle;
+};
+Storage<Library>::Objects libraries;
+DECLARE_LOADER("library", Library);
+
LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
recursive(r),
ns(n)
{
+ supportedStorers.insert(Storer::into(&libraries));
}
LoaderBase::~LoaderBase()