From 87a90d56403667f873f9d9c2f278fb6e35cffe51 Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 15 Mar 2011 01:03:52 +0000 Subject: Add element handler for loading extra libraries at runtime --- project2/Jamfile.jam | 5 +++++ project2/xmlObjectLoader.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) 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 : : : : "`pkg-config --cflags libexslt`" "`pkg-config --libs libexslt`" ; +lib dl : : dl ; lib fcgi : : fcgi ; lib fcgi++ : : fcgi++ ; lib boost_regex : : boost_regex ; @@ -63,10 +64,14 @@ lib p2common : : ../libmisc libxmlpp + dl boost_system boost_filesystem boost_date_time boost_program_options + : : + . + ../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 #include +#include #include 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::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() -- cgit v1.2.3