From 21ea87265107fbece479a3f1c892789f9c18122c Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Tue, 7 Aug 2012 13:08:14 +0200 Subject: [PATCH] Gracefully deactivate all dynamic objects before shutting down. --- base/application.cpp | 2 ++ base/dynamicobject.cpp | 14 ++++++++++++++ base/dynamicobject.h | 1 + 3 files changed, 17 insertions(+) diff --git a/base/application.cpp b/base/application.cpp index 54d7d3487..f42f573cd 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -59,6 +59,8 @@ Application::~Application(void) { m_ShuttingDown = true; + DynamicObject::DeactivateObjects(); + #ifdef _WIN32 WSACleanup(); #endif /* _WIN32 */ diff --git a/base/dynamicobject.cpp b/base/dynamicobject.cpp index d6970f09b..1995808ad 100644 --- a/base/dynamicobject.cpp +++ b/base/dynamicobject.cpp @@ -442,6 +442,20 @@ void DynamicObject::RestoreObjects(const String& filename) } } +void DynamicObject::DeactivateObjects(void) +{ + DynamicObject::TypeMap::iterator tt; + for (tt = GetAllObjects().begin(); tt != GetAllObjects().end(); tt++) { + DynamicObject::NameMap::iterator nt; + + while ((nt = tt->second.begin()) != tt->second.end()) { + DynamicObject::Ptr object = nt->second; + + object->Unregister(); + } + } +} + DynamicObject::TypeMap& DynamicObject::GetAllObjects(void) { static TypeMap objects; diff --git a/base/dynamicobject.h b/base/dynamicobject.h index 9856e9b79..7e9546058 100644 --- a/base/dynamicobject.h +++ b/base/dynamicobject.h @@ -116,6 +116,7 @@ public: static void DumpObjects(const String& filename); static void RestoreObjects(const String& filename); + static void DeactivateObjects(void); static void RegisterClass(const String& type, Factory factory); static bool ClassExists(const String& type);