diff options
author | randomdan <randomdan@localhost> | 2011-03-16 14:30:22 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2011-03-16 14:30:22 +0000 |
commit | eb512ebb7f781a40aeb4edba2018ce1a5850b64e (patch) | |
tree | 02ef1f80933b5f5b3f9f91598540f65ca75af415 | |
parent | Add element handler for loading extra libraries at runtime (diff) | |
download | project2-eb512ebb7f781a40aeb4edba2018ce1a5850b64e.tar.bz2 project2-eb512ebb7f781a40aeb4edba2018ce1a5850b64e.tar.xz project2-eb512ebb7f781a40aeb4edba2018ce1a5850b64e.zip |
Properly unregister components when their library is unloaded
Unload dynamically loaded libraries onIteration
-rw-r--r-- | project2/Jamfile.jam | 4 | ||||
-rw-r--r-- | project2/iHaveParameters.cpp | 1 | ||||
-rw-r--r-- | project2/xmlObjectLoader.cpp | 18 | ||||
-rw-r--r-- | 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 : : : <include>. <include>../libmisc + <library>boost_system + <library>boost_program_options ; lib p2xml : @@ -187,6 +189,8 @@ lib p2web : <library>p2parts <library>p2xmlSession <library>p2uuid + <library>cgicc + <library>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 <boost/foreach.hpp> 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<std::string, boost::shared_ptr<ElementLoader> > 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<Library>::Objects libraries; -DECLARE_LOADER("library", Library); +class LibraryLoader : public ElementLoaderImpl<Library> { + 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<T>()); } + static void init_loader_##T() { LoaderBase::newLoader(N, new ElementLoaderImpl<T>()); } \ + 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 { |