From: Maxim Mamontov Date: Sun, 20 Dec 2015 20:04:44 +0000 (+0200) Subject: Stop plugins before stopping core. X-Git-Tag: 2.409~174^2~4 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/367181dd32e2f94d68f3f040bd9d9a20ba1250c3?hp=d61fa7a7d848f470abd5b5df804624b258e8416b Stop plugins before stopping core. --- diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 73786c4e..3c216977 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -363,6 +363,8 @@ while (running) WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); +manager.stop(); + if (loop.Stop()) WriteServLog("Event loop not stopped."); diff --git a/projects/stargazer/plugin_mgr.cpp b/projects/stargazer/plugin_mgr.cpp index 5346db8b..b87ab277 100644 --- a/projects/stargazer/plugin_mgr.cpp +++ b/projects/stargazer/plugin_mgr.cpp @@ -97,23 +97,7 @@ PluginManager::PluginManager(const SETTINGS_IMPL& settings, PluginManager::~PluginManager() { - std::sort(m_modules.begin(), m_modules.end(), StopModCmp); - for (size_t i = 0; i < m_modules.size(); ++i) - { - PLUGIN & plugin = m_modules[i]->GetPlugin(); - if (m_modules[i]->Stop()) - { - m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), - plugin.GetStrError().c_str()); - } - else - { - m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); - printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); - } - } + stop(); for (size_t i = 0; i < m_modules.size(); ++i) delete m_modules[i]; } @@ -132,3 +116,26 @@ void PluginManager::reload() } } } + +void PluginManager::stop() +{ + std::sort(m_modules.begin(), m_modules.end(), StopModCmp); + for (size_t i = 0; i < m_modules.size(); ++i) + { + if (!m_modules[i]->IsRunning()) + continue; + PLUGIN & plugin = m_modules[i]->GetPlugin(); + if (m_modules[i]->Stop()) + { + m_log("Failed to stop module '%s': '%s'", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + printfd(__FILE__, "Failed to stop module '%s': '%s'\n", plugin.GetVersion().c_str(), + plugin.GetStrError().c_str()); + } + else + { + m_log("Module '%s' stopped successfully.", plugin.GetVersion().c_str()); + printfd(__FILE__, "Module '%s' stopped successfully.\n", plugin.GetVersion().c_str()); + } + } +} diff --git a/projects/stargazer/plugin_mgr.h b/projects/stargazer/plugin_mgr.h index 79b6cae9..c9ec8dff 100644 --- a/projects/stargazer/plugin_mgr.h +++ b/projects/stargazer/plugin_mgr.h @@ -49,6 +49,7 @@ class PluginManager ~PluginManager(); void reload(); + void stop(); private: std::vector m_modules;