From 18da6dee8eb94e1e1fca6e0c64a7914213f21847 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Fri, 7 Jul 2017 15:23:47 -0700 Subject: [PATCH] LogManager: remove per-container listeners --- Source/Core/Common/Logging/LogManager.cpp | 29 ++++-------- Source/Core/Common/Logging/LogManager.h | 7 ++- Source/Core/DolphinWX/LogConfigWindow.cpp | 57 +++-------------------- Source/Core/DolphinWX/LogWindow.cpp | 6 +-- 4 files changed, 21 insertions(+), 78 deletions(-) diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 7e73155c2e..56aeea9d27 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -8,7 +8,6 @@ #include #include -#include "Common/BitSet.h" #include "Common/CommonPaths.h" #include "Common/FileUtil.h" #include "Common/IniFile.h" @@ -58,19 +57,12 @@ public: std::string GetShortName() const { return m_short_name; } std::string GetFullName() const { return m_full_name; } - void AddListener(LogListener::LISTENER id) { m_listener_ids[id] = 1; } - void RemoveListener(LogListener::LISTENER id) { m_listener_ids[id] = 0; } bool IsEnabled() const { return m_enable; } void SetEnable(bool enable) { m_enable = enable; } - bool HasListeners() const { return bool(m_listener_ids); } - typedef class BitSet32::Iterator iterator; - iterator begin() const { return m_listener_ids.begin(); } - iterator end() const { return m_listener_ids.end(); } private: std::string m_full_name; std::string m_short_name; bool m_enable; - BitSet32 m_listener_ids; }; void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, int line, @@ -169,18 +161,15 @@ LogManager::LogManager() verbosity = MAX_LOGLEVEL; SetLogLevel(static_cast(verbosity)); + EnableListener(LogListener::FILE_LISTENER, write_file); + EnableListener(LogListener::CONSOLE_LISTENER, write_console); + EnableListener(LogListener::LOG_WINDOW_LISTENER, write_window); for (LogContainer* container : m_log) { bool enable; logs->Get(container->GetShortName(), &enable, false); container->SetEnable(enable); - if (enable && write_file) - container->AddListener(LogListener::FILE_LISTENER); - if (enable && write_console) - container->AddListener(LogListener::CONSOLE_LISTENER); - if (enable && write_window) - container->AddListener(LogListener::LOG_WINDOW_LISTENER); } m_path_cutoff_point = DeterminePathCutOffPoint(); @@ -208,7 +197,7 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE char temp[MAX_MSGLEN]; LogContainer* log = m_log[type]; - if (!log->IsEnabled() || level > GetLogLevel() || !log->HasListeners()) + if (!log->IsEnabled() || level > GetLogLevel() || !static_cast(m_listener_ids)) return; CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); @@ -217,7 +206,7 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE "%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, line, LogTypes::LOG_LEVEL_TO_CHAR[(int)level], log->GetShortName().c_str(), temp); - for (auto listener_id : *log) + for (auto listener_id : m_listener_ids) if (m_listeners[listener_id]) m_listeners[listener_id]->Log(level, msg.c_str()); } @@ -257,14 +246,14 @@ void LogManager::RegisterListener(LogListener::LISTENER id, LogListener* listene m_listeners[id] = listener; } -void LogManager::AddListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id) +void LogManager::EnableListener(LogListener::LISTENER id, bool enable) { - m_log[type]->AddListener(id); + m_listener_ids[id] = enable; } -void LogManager::RemoveListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id) +bool LogManager::IsListenerEnabled(LogListener::LISTENER id) const { - m_log[type]->RemoveListener(id); + return m_listener_ids[id]; } // Singleton. Ugh. diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 6c8a795992..a4e9d9032e 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -8,6 +8,7 @@ #include #include +#include "Common/BitSet.h" #include "Common/Logging/Log.h" #include "Common/NonCopyable.h" @@ -50,9 +51,10 @@ public: std::string GetShortName(LogTypes::LOG_TYPE type) const; std::string GetFullName(LogTypes::LOG_TYPE type) const; + void RegisterListener(LogListener::LISTENER id, LogListener* listener); - void AddListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id); - void RemoveListener(LogTypes::LOG_TYPE type, LogListener::LISTENER id); + void EnableListener(LogListener::LISTENER id, bool enable); + bool IsListenerEnabled(LogListener::LISTENER id) const; private: LogManager(); @@ -61,5 +63,6 @@ private: LogTypes::LOG_LEVELS m_level; LogContainer* m_log[LogTypes::NUMBER_OF_LOGS]; std::array m_listeners{}; + BitSet32 m_listener_ids; size_t m_path_cutoff_point = 0; }; diff --git a/Source/Core/DolphinWX/LogConfigWindow.cpp b/Source/Core/DolphinWX/LogConfigWindow.cpp index f50b868f4e..6592650040 100644 --- a/Source/Core/DolphinWX/LogConfigWindow.cpp +++ b/Source/Core/DolphinWX/LogConfigWindow.cpp @@ -163,47 +163,20 @@ void LogConfigWindow::OnVerbosityChange(wxCommandEvent& event) void LogConfigWindow::OnWriteFileChecked(wxCommandEvent& event) { - for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) - { - m_writeFile = event.IsChecked(); - if (m_checks->IsChecked(i)) - { - if (m_writeFile) - m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER); - else - m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::FILE_LISTENER); - } - } + m_writeFile = event.IsChecked(); + m_LogManager->EnableListener(LogListener::FILE_LISTENER, m_writeFile); } void LogConfigWindow::OnWriteConsoleChecked(wxCommandEvent& event) { - for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) - { - m_writeConsole = event.IsChecked(); - if (m_checks->IsChecked(i)) - { - if (m_writeConsole) - m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::CONSOLE_LISTENER); - else - m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::CONSOLE_LISTENER); - } - } + m_writeConsole = event.IsChecked(); + m_LogManager->EnableListener(LogListener::CONSOLE_LISTENER, m_writeConsole); } void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event) { - for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) - { - m_writeWindow = event.IsChecked(); - if (m_checks->IsChecked(i)) - { - if (m_writeWindow) - m_LogManager->AddListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER); - else - m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, LogListener::LOG_WINDOW_LISTENER); - } - } + m_writeWindow = event.IsChecked(); + m_LogManager->EnableListener(LogListener::LOG_WINDOW_LISTENER, m_writeWindow); } void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event)) @@ -217,26 +190,8 @@ void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event)) void LogConfigWindow::ToggleLog(int _logType, bool enable) { LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType; - m_checks->Check(_logType, enable); - m_LogManager->SetEnable(logType, enable); - - if (enable) - { - if (m_writeWindow) - m_LogManager->AddListener(logType, LogListener::LOG_WINDOW_LISTENER); - if (m_writeFile) - m_LogManager->AddListener(logType, LogListener::FILE_LISTENER); - if (m_writeConsole) - m_LogManager->AddListener(logType, LogListener::CONSOLE_LISTENER); - } - else - { - m_LogManager->RemoveListener(logType, LogListener::LOG_WINDOW_LISTENER); - m_LogManager->RemoveListener(logType, LogListener::FILE_LISTENER); - m_LogManager->RemoveListener(logType, LogListener::CONSOLE_LISTENER); - } } void LogConfigWindow::OnLogCheck(wxCommandEvent& event) diff --git a/Source/Core/DolphinWX/LogWindow.cpp b/Source/Core/DolphinWX/LogWindow.cpp index 2edb42254b..3de0469f30 100644 --- a/Source/Core/DolphinWX/LogWindow.cpp +++ b/Source/Core/DolphinWX/LogWindow.cpp @@ -133,11 +133,7 @@ void CLogWindow::RemoveAllListeners() return; m_has_listeners = false; - for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) - { - m_LogManager->RemoveListener(static_cast(i), - LogListener::LOG_WINDOW_LISTENER); - } + m_LogManager->EnableListener(LogListener::LOG_WINDOW_LISTENER, false); } void CLogWindow::SaveSettings()