From eb512ebb7f781a40aeb4edba2018ce1a5850b64e Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 16 Mar 2011 14:30:22 +0000 Subject: Properly unregister components when their library is unloaded Unload dynamically loaded libraries onIteration --- project2/Jamfile.jam | 4 ++++ project2/iHaveParameters.cpp | 1 - project2/xmlObjectLoader.cpp | 18 ++++++++++++++---- project2/xmlObjectLoader.h | 8 ++++++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam index 24fa691..b82c457 100644 --- a/project2/Jamfile.jam +++ b/project2/Jamfile.jam @@ -72,6 +72,8 @@ lib p2common : : : . ../libmisc + boost_system + boost_program_options ; lib p2xml : @@ -187,6 +189,8 @@ lib p2web : p2parts p2xmlSession p2uuid + cgicc + p2common ; exe p2cgi : diff --git a/project2/iHaveParameters.cpp b/project2/iHaveParameters.cpp index 6431fc6..323cc0b 100644 --- a/project2/iHaveParameters.cpp +++ b/project2/iHaveParameters.cpp @@ -1,7 +1,6 @@ #include "iHaveParameters.h" #include "exceptions.h" #include "appEngine.h" -#include "xmlObjectLoader.h" #include IHaveParameters::IHaveParameters(const xmlpp::Element * p) diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp index 849cfa1..2745d61 100644 --- a/project2/xmlObjectLoader.cpp +++ b/project2/xmlObjectLoader.cpp @@ -14,11 +14,12 @@ typedef std::map > ElementLoaderMa ElementLoaderMap & objLoaders() { - static ElementLoaderMap _objLoaders; - return _objLoaders; + static ElementLoaderMap * _objLoaders = new ElementLoaderMap(); + return *_objLoaders; } SimpleMessageException(LoadLibraryFailed); +SimpleMessageException(UnloadLibraryFailed); class Library : public SourceObject { public: @@ -31,7 +32,9 @@ class Library : public SourceObject { } } ~Library() { - dlclose(handle); + if (dlclose(handle)) { + throw UnloadLibraryFailed(dlerror()); + } } void loadComplete(const CommonObjects*) { } @@ -39,7 +42,14 @@ class Library : public SourceObject { void * handle; }; Storage::Objects libraries; -DECLARE_LOADER("library", Library); +class LibraryLoader : public ElementLoaderImpl { + public: + void onIteration() + { + libraries.clear(); + } +}; +DECLARE_CUSTOM_LOADER("library", LibraryLoader); LoaderBase::LoaderBase(const Glib::ustring & n, bool r) : recursive(r), diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index 40e6d5d..9dd3881 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -48,10 +48,14 @@ class LoaderBase { #define DECLARE_CUSTOM_LOADER(N, T) \ static void init_loader_##T() __attribute__ ((constructor(201))); \ - static void init_loader_##T() { LoaderBase::newLoader(N, new T()); } + static void init_loader_##T() { LoaderBase::newLoader(N, new T()); } \ + static void kill_loader_##T() __attribute__ ((destructor(201))); \ + static void kill_loader_##T() { LoaderBase::removeLoader(N); } #define DECLARE_LOADER(N, T) \ static void init_loader_##T() __attribute__ ((constructor(201))); \ - static void init_loader_##T() { LoaderBase::newLoader(N, new ElementLoaderImpl()); } + static void init_loader_##T() { LoaderBase::newLoader(N, new ElementLoaderImpl()); } \ + static void kill_loader_##T() __attribute__ ((destructor(201))); \ + static void kill_loader_##T() { LoaderBase::removeLoader(N); } /// Helper for loading and maintaining Project2 script components class ElementLoader { -- cgit v1.2.3