From ba107819ec9bc826fd910bdfc6c65fcdecae3f9e Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 24 Apr 2021 19:26:27 -0700 Subject: [PATCH 1/2] Create EnumMap --- Source/Core/Common/CMakeLists.txt | 1 + Source/Core/Common/ChunkFile.h | 7 +++ Source/Core/Common/EnumFormatter.h | 21 +++++--- Source/Core/Common/EnumMap.h | 83 ++++++++++++++++++++++++++++++ Source/Core/Common/TypeUtils.h | 17 ++++++ Source/Core/DolphinLib.props | 1 + 6 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 Source/Core/Common/EnumMap.h diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index 1b806129fd..b1e25af45b 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -42,6 +42,7 @@ add_library(common ENetUtil.cpp ENetUtil.h EnumFormatter.h + EnumMap.h Event.h FileSearch.cpp FileSearch.h diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index 85507354af..8b84a4cf1c 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -27,6 +27,7 @@ #include "Common/Assert.h" #include "Common/CommonTypes.h" +#include "Common/EnumMap.h" #include "Common/Flag.h" #include "Common/Inline.h" #include "Common/Logging/Log.h" @@ -175,6 +176,12 @@ public: DoArray(x.data(), static_cast(x.size())); } + template + void DoArray(Common::EnumMap& x) + { + DoArray(x.data(), static_cast(x.size())); + } + template , int> = 0> void DoArray(T* x, u32 count) { diff --git a/Source/Core/Common/EnumFormatter.h b/Source/Core/Common/EnumFormatter.h index f590e761d4..1ab6bbeadd 100644 --- a/Source/Core/Common/EnumFormatter.h +++ b/Source/Core/Common/EnumFormatter.h @@ -3,7 +3,8 @@ #pragma once -#include +#include "Common/EnumMap.h" + #include #include @@ -41,11 +42,15 @@ * formatter() : EnumFormatter(names) {} * }; */ -template (last_member) + 1, - std::enable_if_t, bool> = true> +template class EnumFormatter { + // The second template argument is needed to avoid compile errors from ambiguity with multiple + // enums with the same number of members in GCC prior to 8. See https://godbolt.org/z/xcKaW1seW + // and https://godbolt.org/z/hz7Yqq1P5 + using T = decltype(last_member); + static_assert(std::is_enum_v); + public: constexpr auto parse(fmt::format_parse_context& ctx) { @@ -61,19 +66,19 @@ public: { const auto value_s = static_cast>(e); // Possibly signed const auto value_u = static_cast>(value_s); // Always unsigned - const bool has_name = value_s >= 0 && value_u < size && m_names[value_u] != nullptr; + const bool has_name = m_names.InBounds(e) && m_names[e] != nullptr; if (!formatting_for_shader) { if (has_name) - return fmt::format_to(ctx.out(), "{} ({})", m_names[value_u], value_s); + return fmt::format_to(ctx.out(), "{} ({})", m_names[e], value_s); else return fmt::format_to(ctx.out(), "Invalid ({})", value_s); } else { if (has_name) - return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value_u, m_names[value_u]); + return fmt::format_to(ctx.out(), "{:#x}u /* {} */", value_u, m_names[e]); else return fmt::format_to(ctx.out(), "{:#x}u /* Invalid */", value_u); } @@ -81,7 +86,7 @@ public: protected: // This is needed because std::array deduces incorrectly if nullptr is included in the list - using array_type = std::array; + using array_type = Common::EnumMap; constexpr explicit EnumFormatter(const array_type names) : m_names(std::move(names)) {} diff --git a/Source/Core/Common/EnumMap.h b/Source/Core/Common/EnumMap.h new file mode 100644 index 0000000000..478ff42ec7 --- /dev/null +++ b/Source/Core/Common/EnumMap.h @@ -0,0 +1,83 @@ +// Copyright 2021 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +#include "Common/TypeUtils.h" + +template +struct BitField; + +namespace Common +{ +// A type that allows lookup of values associated with an enum as the key. +// Designed for enums whose numeric values start at 0 and increment continuously with few gaps. +template +class EnumMap final +{ + // The third template argument is needed to avoid compile errors from ambiguity with multiple + // enums with the same number of members in GCC prior to 8. See https://godbolt.org/z/xcKaW1seW + // and https://godbolt.org/z/hz7Yqq1P5 + using T = decltype(last_member); + static_assert(std::is_enum_v); + static constexpr size_t s_size = static_cast(last_member) + 1; + + using array_type = std::array; + using iterator = typename array_type::iterator; + using const_iterator = typename array_type::const_iterator; + +public: + constexpr EnumMap() = default; + constexpr EnumMap(const EnumMap& other) = default; + constexpr EnumMap& operator=(const EnumMap& other) = default; + constexpr EnumMap(EnumMap&& other) = default; + constexpr EnumMap& operator=(EnumMap&& other) = default; + + // Constructor that accepts exactly size Vs (enforcing that all must be specified). + template ::value>> + constexpr EnumMap(T... values) : m_array{static_cast(values)...} + { + } + + constexpr const V& operator[](T key) const { return m_array[static_cast(key)]; } + constexpr V& operator[](T key) { return m_array[static_cast(key)]; } + + // These only exist to perform the safety check; without them, BitField's implicit conversion + // would work (but since BitField is used for game-generated data, we need to be careful about + // bounds-checking) + template + constexpr const V& operator[](BitField key) const + { + static_assert(1 << bits == s_size, "Unsafe indexing into EnumMap (may go out of bounds)"); + return m_array[static_cast(key.Value())]; + } + template + constexpr V& operator[](BitField key) + { + static_assert(1 << bits == s_size, "Unsafe indexing into EnumMap (may go out of bounds)"); + return m_array[static_cast(key.value())]; + } + + constexpr bool InBounds(T key) const { return static_cast(key) < s_size; } + + constexpr size_t size() const noexcept { return s_size; } + + constexpr V* data() { return m_array.data(); } + constexpr const V* data() const { return m_array.data(); } + + constexpr iterator begin() { return m_array.begin(); } + constexpr iterator end() { return m_array.end(); } + constexpr const_iterator begin() const { return m_array.begin(); } + constexpr const_iterator end() const { return m_array.end(); } + constexpr const_iterator cbegin() const { return m_array.cbegin(); } + constexpr const_iterator cend() const { return m_array.cend(); } + + constexpr void fill(const V& v) { m_array.fill(v); } + +private: + array_type m_array{}; +}; +} // namespace Common diff --git a/Source/Core/Common/TypeUtils.h b/Source/Core/Common/TypeUtils.h index c6875948c7..47077e11fb 100644 --- a/Source/Core/Common/TypeUtils.h +++ b/Source/Core/Common/TypeUtils.h @@ -3,6 +3,7 @@ #pragma once +#include #include namespace Common @@ -66,4 +67,20 @@ static_assert(std::is_same_v, Bar>); static_assert(std::is_same_v, Foo>); static_assert(!std::is_same_v, Bar>); } // namespace detail + +// Template for checking if Types is count occurrences of T. +template +struct IsNOf : std::integral_constant...> && + sizeof...(Ts) == count> +{ +}; + +static_assert(IsNOf::value); +static_assert(!IsNOf::value); +static_assert(IsNOf::value); +static_assert(!IsNOf::value); +static_assert(!IsNOf::value); +static_assert(IsNOf::value); +static_assert(IsNOf::value); // Type conversions ARE allowed +static_assert(!IsNOf::value); } // namespace Common diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index b7e9bf3b32..fc429c0ab4 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -43,6 +43,7 @@ + From 04d8cdfe88c00dfc1f6b449a728dad6d96d82d8e Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Thu, 21 Oct 2021 12:11:07 -0700 Subject: [PATCH 2/2] Convert LOG_TYPE and LOG_LEVELS to enum class --- .../ui/SettingsFragmentPresenter.java | 4 +- .../app/src/main/res/values/arrays.xml | 2 +- Source/Core/AudioCommon/CubebUtils.cpp | 3 +- Source/Core/Common/Assert.h | 4 +- Source/Core/Common/Logging/ConsoleListener.h | 2 +- .../Common/Logging/ConsoleListenerDroid.cpp | 12 +- .../Common/Logging/ConsoleListenerNix.cpp | 8 +- .../Common/Logging/ConsoleListenerWin.cpp | 2 +- Source/Core/Common/Logging/Log.h | 34 ++-- Source/Core/Common/Logging/LogManager.cpp | 149 +++++++++--------- Source/Core/Common/Logging/LogManager.h | 23 +-- Source/Core/Core/ActionReplay.cpp | 2 +- .../Core/Core/Debugger/Debugger_SymbolMap.cpp | 9 +- .../Core/Core/Debugger/Debugger_SymbolMap.h | 4 +- Source/Core/Core/HW/DVD/FileMonitor.cpp | 4 +- Source/Core/Core/HW/SI/SI_DeviceGBA.cpp | 8 +- Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 8 +- Source/Core/Core/IOS/DI/DI.cpp | 8 +- Source/Core/Core/IOS/Device.cpp | 20 +-- Source/Core/Core/IOS/Device.h | 22 +-- Source/Core/Core/IOS/ES/ES.cpp | 3 +- Source/Core/Core/IOS/FS/FileSystemProxy.cpp | 5 +- Source/Core/Core/IOS/Network/IP/Top.cpp | 14 +- .../Core/Core/IOS/Network/KD/NetKDRequest.cpp | 2 +- Source/Core/Core/IOS/Network/KD/NetKDTime.cpp | 2 +- Source/Core/Core/IOS/Network/SSL.cpp | 4 +- Source/Core/Core/IOS/Network/Socket.cpp | 2 +- Source/Core/Core/IOS/Network/WD/Command.cpp | 2 +- Source/Core/Core/IOS/STM/STM.cpp | 2 +- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp | 6 +- .../Core/IOS/USB/Bluetooth/WiimoteDevice.cpp | 8 +- Source/Core/Core/IOS/USB/OH0/OH0.cpp | 12 +- Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp | 4 +- Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp | 7 +- Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp | 5 +- Source/Core/Core/IOS/WFS/WFSI.cpp | 3 +- Source/Core/Core/IOS/WFS/WFSSRV.cpp | 3 +- .../Core/PowerPC/Interpreter/Interpreter.cpp | 2 +- .../Core/DolphinQt/Config/LogConfigWidget.cpp | 38 ++--- Source/Core/DolphinQt/Config/LogWidget.cpp | 14 +- Source/Core/DolphinQt/Config/LogWidget.h | 4 +- Source/Core/VideoBackends/OGL/OGLRender.cpp | 8 +- Source/Core/VideoBackends/Vulkan/VKMain.cpp | 4 +- .../VideoBackends/Vulkan/VulkanContext.cpp | 8 +- .../VideoBackends/Vulkan/VulkanLoader.cpp | 6 +- .../Core/VideoBackends/Vulkan/VulkanLoader.h | 8 +- 46 files changed, 254 insertions(+), 250 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java index fe58749387..a5660d599d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsFragmentPresenter.java @@ -1336,7 +1336,7 @@ public final class SettingsFragmentPresenter private static int getLogVerbosityEntries() { - // Value obtained from LOG_LEVELS in Common/Logging/Log.h + // Value obtained from LogLevel in Common/Logging/Log.h if (NativeLibrary.GetMaxLogLevel() == 5) { return R.array.logVerbosityEntriesMaxLevelDebug; @@ -1349,7 +1349,7 @@ public final class SettingsFragmentPresenter private static int getLogVerbosityValues() { - // Value obtained from LOG_LEVELS in Common/Logging/Log.h + // Value obtained from LogLevel in Common/Logging/Log.h if (NativeLibrary.GetMaxLogLevel() == 5) { return R.array.logVerbosityValuesMaxLevelDebug; diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index c7960258fa..39a4d075b6 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -145,7 +145,7 @@ 0 - + Notice Error diff --git a/Source/Core/AudioCommon/CubebUtils.cpp b/Source/Core/AudioCommon/CubebUtils.cpp index 1bd41249e2..512535ee7f 100644 --- a/Source/Core/AudioCommon/CubebUtils.cpp +++ b/Source/Core/AudioCommon/CubebUtils.cpp @@ -29,7 +29,8 @@ static void LogCallback(const char* format, ...) const std::string message = StringFromFormatV(adapted_format.c_str(), args); va_end(args); - instance->Log(Common::Log::LNOTICE, Common::Log::AUDIO, filename, lineno, message.c_str()); + instance->Log(Common::Log::LogLevel::LNOTICE, Common::Log::LogType::AUDIO, filename, lineno, + message.c_str()); } static void DestroyContext(cubeb* ctx) diff --git a/Source/Core/Common/Assert.h b/Source/Core/Common/Assert.h index 72cf460643..ca27a83e60 100644 --- a/Source/Core/Common/Assert.h +++ b/Source/Core/Common/Assert.h @@ -21,7 +21,7 @@ #define DEBUG_ASSERT_MSG(_t_, _a_, _msg_, ...) \ do \ { \ - if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LOG_LEVELS::LDEBUG) \ + if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \ { \ if (!(_a_)) \ { \ @@ -43,6 +43,6 @@ #define DEBUG_ASSERT(_a_) \ do \ { \ - if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LOG_LEVELS::LDEBUG) \ + if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \ ASSERT(_a_); \ } while (0) diff --git a/Source/Core/Common/Logging/ConsoleListener.h b/Source/Core/Common/Logging/ConsoleListener.h index 7310204377..2c5e744751 100644 --- a/Source/Core/Common/Logging/ConsoleListener.h +++ b/Source/Core/Common/Logging/ConsoleListener.h @@ -11,7 +11,7 @@ public: ConsoleListener(); ~ConsoleListener(); - void Log(Common::Log::LOG_LEVELS level, const char* text) override; + void Log(Common::Log::LogLevel level, const char* text) override; private: bool m_use_color = false; diff --git a/Source/Core/Common/Logging/ConsoleListenerDroid.cpp b/Source/Core/Common/Logging/ConsoleListenerDroid.cpp index 35889ec7ce..f6832ce187 100644 --- a/Source/Core/Common/Logging/ConsoleListenerDroid.cpp +++ b/Source/Core/Common/Logging/ConsoleListenerDroid.cpp @@ -13,26 +13,26 @@ ConsoleListener::~ConsoleListener() { } -void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text) +void ConsoleListener::Log(Common::Log::LogLevel level, const char* text) { android_LogPriority logLevel = ANDROID_LOG_UNKNOWN; // Map dolphin's log levels to android's switch (level) { - case Common::Log::LOG_LEVELS::LDEBUG: + case Common::Log::LogLevel::LDEBUG: logLevel = ANDROID_LOG_DEBUG; break; - case Common::Log::LOG_LEVELS::LINFO: + case Common::Log::LogLevel::LINFO: logLevel = ANDROID_LOG_INFO; break; - case Common::Log::LOG_LEVELS::LWARNING: + case Common::Log::LogLevel::LWARNING: logLevel = ANDROID_LOG_WARN; break; - case Common::Log::LOG_LEVELS::LERROR: + case Common::Log::LogLevel::LERROR: logLevel = ANDROID_LOG_ERROR; break; - case Common::Log::LOG_LEVELS::LNOTICE: + case Common::Log::LogLevel::LNOTICE: logLevel = ANDROID_LOG_INFO; break; } diff --git a/Source/Core/Common/Logging/ConsoleListenerNix.cpp b/Source/Core/Common/Logging/ConsoleListenerNix.cpp index e7ef99367b..7908bddb89 100644 --- a/Source/Core/Common/Logging/ConsoleListenerNix.cpp +++ b/Source/Core/Common/Logging/ConsoleListenerNix.cpp @@ -21,7 +21,7 @@ ConsoleListener::~ConsoleListener() fflush(nullptr); } -void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text) +void ConsoleListener::Log(Common::Log::LogLevel level, const char* text) { char color_attr[16] = ""; char reset_attr[16] = ""; @@ -31,15 +31,15 @@ void ConsoleListener::Log(Common::Log::LOG_LEVELS level, const char* text) strcpy(reset_attr, "\x1b[0m"); switch (level) { - case Common::Log::LOG_LEVELS::LNOTICE: + case Common::Log::LogLevel::LNOTICE: // light green strcpy(color_attr, "\x1b[92m"); break; - case Common::Log::LOG_LEVELS::LERROR: + case Common::Log::LogLevel::LERROR: // light red strcpy(color_attr, "\x1b[91m"); break; - case Common::Log::LOG_LEVELS::LWARNING: + case Common::Log::LogLevel::LWARNING: // light yellow strcpy(color_attr, "\x1b[93m"); break; diff --git a/Source/Core/Common/Logging/ConsoleListenerWin.cpp b/Source/Core/Common/Logging/ConsoleListenerWin.cpp index d59833b6dd..741c2e3eb8 100644 --- a/Source/Core/Common/Logging/ConsoleListenerWin.cpp +++ b/Source/Core/Common/Logging/ConsoleListenerWin.cpp @@ -14,7 +14,7 @@ ConsoleListener::~ConsoleListener() { } -void ConsoleListener::Log([[maybe_unused]] Common::Log::LOG_LEVELS level, const char* text) +void ConsoleListener::Log([[maybe_unused]] Common::Log::LogLevel level, const char* text) { ::OutputDebugStringW(UTF8ToWString(text).c_str()); } diff --git a/Source/Core/Common/Logging/Log.h b/Source/Core/Common/Logging/Log.h index 30098f77ee..a6eedff39b 100644 --- a/Source/Core/Common/Logging/Log.h +++ b/Source/Core/Common/Logging/Log.h @@ -10,7 +10,7 @@ namespace Common::Log { -enum LOG_TYPE +enum class LogType : int { ACTIONREPLAY, AUDIO, @@ -67,7 +67,7 @@ enum LOG_TYPE NUMBER_OF_LOGS // Must be last }; -enum LOG_LEVELS +enum class LogLevel : int { LNOTICE = 1, // VERY important information that is NOT errors. Like startup and OSReports. LERROR = 2, // Critical errors @@ -77,18 +77,18 @@ enum LOG_LEVELS }; #if defined(_DEBUG) || defined(DEBUGFAST) -constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LDEBUG; +constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LDEBUG; #else -constexpr auto MAX_LOGLEVEL = Common::Log::LOG_LEVELS::LINFO; +constexpr auto MAX_LOGLEVEL = Common::Log::LogLevel::LINFO; #endif // logging static const char LOG_LEVEL_TO_CHAR[7] = "-NEWID"; -void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, +void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, fmt::string_view format, const fmt::format_args& args); template -void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const S& format, +void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, const S& format, const Args&... args) { static_assert(NumFields == sizeof...(args), @@ -98,7 +98,7 @@ void GenericLogFmt(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, fmt::make_args_checked(format, args...)); } -void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...) +void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...) #ifdef __GNUC__ __attribute__((format(printf, 5, 6))) #endif @@ -116,27 +116,27 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con #define ERROR_LOG(t, ...) \ do \ { \ - GENERIC_LOG(Common::Log::t, Common::Log::LERROR, __VA_ARGS__); \ + GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \ } while (0) #define WARN_LOG(t, ...) \ do \ { \ - GENERIC_LOG(Common::Log::t, Common::Log::LWARNING, __VA_ARGS__); \ + GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \ } while (0) #define NOTICE_LOG(t, ...) \ do \ { \ - GENERIC_LOG(Common::Log::t, Common::Log::LNOTICE, __VA_ARGS__); \ + GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \ } while (0) #define INFO_LOG(t, ...) \ do \ { \ - GENERIC_LOG(Common::Log::t, Common::Log::LINFO, __VA_ARGS__); \ + GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \ } while (0) #define DEBUG_LOG(t, ...) \ do \ { \ - GENERIC_LOG(Common::Log::t, Common::Log::LDEBUG, __VA_ARGS__); \ + GENERIC_LOG(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \ } while (0) // fmtlib capable API @@ -156,25 +156,25 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con #define ERROR_LOG_FMT(t, ...) \ do \ { \ - GENERIC_LOG_FMT(Common::Log::t, Common::Log::LERROR, __VA_ARGS__); \ + GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \ } while (0) #define WARN_LOG_FMT(t, ...) \ do \ { \ - GENERIC_LOG_FMT(Common::Log::t, Common::Log::LWARNING, __VA_ARGS__); \ + GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \ } while (0) #define NOTICE_LOG_FMT(t, ...) \ do \ { \ - GENERIC_LOG_FMT(Common::Log::t, Common::Log::LNOTICE, __VA_ARGS__); \ + GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \ } while (0) #define INFO_LOG_FMT(t, ...) \ do \ { \ - GENERIC_LOG_FMT(Common::Log::t, Common::Log::LINFO, __VA_ARGS__); \ + GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \ } while (0) #define DEBUG_LOG_FMT(t, ...) \ do \ { \ - GENERIC_LOG_FMT(Common::Log::t, Common::Log::LDEBUG, __VA_ARGS__); \ + GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \ } while (0) diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 2249447945..64f1786975 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -31,7 +31,8 @@ const Config::Info LOGGER_WRITE_TO_CONSOLE{ {Config::System::Logger, "Options", "WriteToConsole"}, true}; const Config::Info LOGGER_WRITE_TO_WINDOW{ {Config::System::Logger, "Options", "WriteToWindow"}, true}; -const Config::Info LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0}; +const Config::Info LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, + LogLevel::LNOTICE}; class FileLogListener : public LogListener { @@ -42,7 +43,7 @@ public: SetEnable(true); } - void Log(LOG_LEVELS, const char* msg) override + void Log(LogLevel, const char* msg) override { if (!IsEnabled() || !IsValid()) return; @@ -61,7 +62,7 @@ private: bool m_enable; }; -void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...) +void GenericLog(LogLevel level, LogType type, const char* file, int line, const char* fmt, ...) { auto* instance = LogManager::GetInstance(); if (instance == nullptr) @@ -79,7 +80,7 @@ void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, con instance->Log(level, type, file, line, message); } -void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, +void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, fmt::string_view format, const fmt::format_args& args) { auto* instance = LogManager::GetInstance(); @@ -115,79 +116,75 @@ static size_t DeterminePathCutOffPoint() LogManager::LogManager() { // create log containers - m_log[ACTIONREPLAY] = {"ActionReplay", "Action Replay"}; - m_log[AUDIO] = {"Audio", "Audio Emulator"}; - m_log[AUDIO_INTERFACE] = {"AI", "Audio Interface"}; - m_log[BOOT] = {"BOOT", "Boot"}; - m_log[COMMANDPROCESSOR] = {"CP", "Command Processor"}; - m_log[COMMON] = {"COMMON", "Common"}; - m_log[CONSOLE] = {"CONSOLE", "Dolphin Console"}; - m_log[CONTROLLERINTERFACE] = {"CI", "Controller Interface"}; - m_log[CORE] = {"CORE", "Core"}; - m_log[DISCIO] = {"DIO", "Disc IO"}; - m_log[DSPHLE] = {"DSPHLE", "DSP HLE"}; - m_log[DSPLLE] = {"DSPLLE", "DSP LLE"}; - m_log[DSP_MAIL] = {"DSPMails", "DSP Mails"}; - m_log[DSPINTERFACE] = {"DSP", "DSP Interface"}; - m_log[DVDINTERFACE] = {"DVD", "DVD Interface"}; - m_log[DYNA_REC] = {"JIT", "JIT Dynamic Recompiler"}; - m_log[EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"}; - m_log[FILEMON] = {"FileMon", "File Monitor"}; - m_log[FRAMEDUMP] = {"FRAMEDUMP", "FrameDump"}; - m_log[GDB_STUB] = {"GDB_STUB", "GDB Stub"}; - m_log[GPFIFO] = {"GP", "GatherPipe FIFO"}; - m_log[HOST_GPU] = {"Host GPU", "Host GPU"}; - m_log[IOS] = {"IOS", "IOS"}; - m_log[IOS_DI] = {"IOS_DI", "IOS - Drive Interface"}; - m_log[IOS_ES] = {"IOS_ES", "IOS - ETicket Services"}; - m_log[IOS_FS] = {"IOS_FS", "IOS - Filesystem Services"}; - m_log[IOS_SD] = {"IOS_SD", "IOS - SDIO"}; - m_log[IOS_SSL] = {"IOS_SSL", "IOS - SSL"}; - m_log[IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"}; - m_log[IOS_NET] = {"IOS_NET", "IOS - Network"}; - m_log[IOS_USB] = {"IOS_USB", "IOS - USB"}; - m_log[IOS_WC24] = {"IOS_WC24", "IOS - WiiConnect24"}; - m_log[IOS_WFS] = {"IOS_WFS", "IOS - WFS"}; - m_log[IOS_WIIMOTE] = {"IOS_WIIMOTE", "IOS - Wii Remote"}; - m_log[MASTER_LOG] = {"MASTER", "Master Log"}; - m_log[MEMCARD_MANAGER] = {"MemCard Manager", "Memory Card Manager"}; - m_log[MEMMAP] = {"MI", "Memory Interface & Memory Map"}; - m_log[NETPLAY] = {"NETPLAY", "Netplay"}; - m_log[OSHLE] = {"HLE", "OSHLE"}; - m_log[OSREPORT] = {"OSREPORT", "OSReport EXI"}; - m_log[OSREPORT_HLE] = {"OSREPORT_HLE", "OSReport HLE"}; - m_log[PIXELENGINE] = {"PE", "Pixel Engine"}; - m_log[PROCESSORINTERFACE] = {"PI", "Processor Interface"}; - m_log[POWERPC] = {"PowerPC", "PowerPC IBM CPU"}; - m_log[SERIALINTERFACE] = {"SI", "Serial Interface"}; - m_log[SP1] = {"SP1", "Serial Port 1"}; - m_log[SYMBOLS] = {"SYMBOLS", "Symbols"}; - m_log[VIDEO] = {"Video", "Video Backend"}; - m_log[VIDEOINTERFACE] = {"VI", "Video Interface"}; - m_log[WIIMOTE] = {"Wiimote", "Wii Remote"}; - m_log[WII_IPC] = {"WII_IPC", "WII IPC"}; + m_log[LogType::ACTIONREPLAY] = {"ActionReplay", "Action Replay"}; + m_log[LogType::AUDIO] = {"Audio", "Audio Emulator"}; + m_log[LogType::AUDIO_INTERFACE] = {"AI", "Audio Interface"}; + m_log[LogType::BOOT] = {"BOOT", "Boot"}; + m_log[LogType::COMMANDPROCESSOR] = {"CP", "Command Processor"}; + m_log[LogType::COMMON] = {"COMMON", "Common"}; + m_log[LogType::CONSOLE] = {"CONSOLE", "Dolphin Console"}; + m_log[LogType::CONTROLLERINTERFACE] = {"CI", "Controller Interface"}; + m_log[LogType::CORE] = {"CORE", "Core"}; + m_log[LogType::DISCIO] = {"DIO", "Disc IO"}; + m_log[LogType::DSPHLE] = {"DSPHLE", "DSP HLE"}; + m_log[LogType::DSPLLE] = {"DSPLLE", "DSP LLE"}; + m_log[LogType::DSP_MAIL] = {"DSPMails", "DSP Mails"}; + m_log[LogType::DSPINTERFACE] = {"DSP", "DSP Interface"}; + m_log[LogType::DVDINTERFACE] = {"DVD", "DVD Interface"}; + m_log[LogType::DYNA_REC] = {"JIT", "JIT Dynamic Recompiler"}; + m_log[LogType::EXPANSIONINTERFACE] = {"EXI", "Expansion Interface"}; + m_log[LogType::FILEMON] = {"FileMon", "File Monitor"}; + m_log[LogType::FRAMEDUMP] = {"FRAMEDUMP", "FrameDump"}; + m_log[LogType::GDB_STUB] = {"GDB_STUB", "GDB Stub"}; + m_log[LogType::GPFIFO] = {"GP", "GatherPipe FIFO"}; + m_log[LogType::HOST_GPU] = {"Host GPU", "Host GPU"}; + m_log[LogType::IOS] = {"IOS", "IOS"}; + m_log[LogType::IOS_DI] = {"IOS_DI", "IOS - Drive Interface"}; + m_log[LogType::IOS_ES] = {"IOS_ES", "IOS - ETicket Services"}; + m_log[LogType::IOS_FS] = {"IOS_FS", "IOS - Filesystem Services"}; + m_log[LogType::IOS_SD] = {"IOS_SD", "IOS - SDIO"}; + m_log[LogType::IOS_SSL] = {"IOS_SSL", "IOS - SSL"}; + m_log[LogType::IOS_STM] = {"IOS_STM", "IOS - State Transition Manager"}; + m_log[LogType::IOS_NET] = {"IOS_NET", "IOS - Network"}; + m_log[LogType::IOS_USB] = {"IOS_USB", "IOS - USB"}; + m_log[LogType::IOS_WC24] = {"IOS_WC24", "IOS - WiiConnect24"}; + m_log[LogType::IOS_WFS] = {"IOS_WFS", "IOS - WFS"}; + m_log[LogType::IOS_WIIMOTE] = {"IOS_WIIMOTE", "IOS - Wii Remote"}; + m_log[LogType::MASTER_LOG] = {"MASTER", "Master Log"}; + m_log[LogType::MEMCARD_MANAGER] = {"MemCard Manager", "Memory Card Manager"}; + m_log[LogType::MEMMAP] = {"MI", "Memory Interface & Memory Map"}; + m_log[LogType::NETPLAY] = {"NETPLAY", "Netplay"}; + m_log[LogType::OSHLE] = {"HLE", "OSHLE"}; + m_log[LogType::OSREPORT] = {"OSREPORT", "OSReport EXI"}; + m_log[LogType::OSREPORT_HLE] = {"OSREPORT_HLE", "OSReport HLE"}; + m_log[LogType::PIXELENGINE] = {"PE", "Pixel Engine"}; + m_log[LogType::PROCESSORINTERFACE] = {"PI", "Processor Interface"}; + m_log[LogType::POWERPC] = {"PowerPC", "PowerPC IBM CPU"}; + m_log[LogType::SERIALINTERFACE] = {"SI", "Serial Interface"}; + m_log[LogType::SP1] = {"SP1", "Serial Port 1"}; + m_log[LogType::SYMBOLS] = {"SYMBOLS", "Symbols"}; + m_log[LogType::VIDEO] = {"Video", "Video Backend"}; + m_log[LogType::VIDEOINTERFACE] = {"VI", "Video Interface"}; + m_log[LogType::WIIMOTE] = {"Wiimote", "Wii Remote"}; + m_log[LogType::WII_IPC] = {"WII_IPC", "WII IPC"}; RegisterListener(LogListener::FILE_LISTENER, new FileLogListener(File::GetUserPath(F_MAINLOG_IDX))); RegisterListener(LogListener::CONSOLE_LISTENER, new ConsoleListener()); // Set up log listeners - int verbosity = Config::Get(LOGGER_VERBOSITY); + LogLevel verbosity = Config::Get(LOGGER_VERBOSITY); - // Ensure the verbosity level is valid - if (verbosity < 1) - verbosity = 1; - if (verbosity > MAX_LOGLEVEL) - verbosity = MAX_LOGLEVEL; - - SetLogLevel(static_cast(verbosity)); + SetLogLevel(verbosity); EnableListener(LogListener::FILE_LISTENER, Config::Get(LOGGER_WRITE_TO_FILE)); EnableListener(LogListener::CONSOLE_LISTENER, Config::Get(LOGGER_WRITE_TO_CONSOLE)); EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW)); - for (LogContainer& container : m_log) + for (auto& container : m_log) + { container.m_enable = Config::Get( Config::Info{{Config::System::Logger, "Logs", container.m_short_name}, false}); + } m_path_cutoff_point = DeterminePathCutOffPoint(); } @@ -208,7 +205,7 @@ void LogManager::SaveSettings() IsListenerEnabled(LogListener::CONSOLE_LISTENER)); Config::SetBaseOrCurrent(LOGGER_WRITE_TO_WINDOW, IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER)); - Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast(GetLogLevel())); + Config::SetBaseOrCurrent(LOGGER_VERBOSITY, GetLogLevel()); for (const auto& container : m_log) { @@ -219,8 +216,7 @@ void LogManager::SaveSettings() Config::Save(); } -void LogManager::Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, - const char* message) +void LogManager::Log(LogLevel level, LogType type, const char* file, int line, const char* message) { if (!IsEnabled(type, level) || !static_cast(m_listener_ids)) return; @@ -228,7 +224,7 @@ void LogManager::Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line LogWithFullPath(level, type, file + m_path_cutoff_point, line, message); } -void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, +void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, int line, const char* message) { const std::string msg = @@ -242,22 +238,22 @@ void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* fi } } -LOG_LEVELS LogManager::GetLogLevel() const +LogLevel LogManager::GetLogLevel() const { return m_level; } -void LogManager::SetLogLevel(LOG_LEVELS level) +void LogManager::SetLogLevel(LogLevel level) { - m_level = level; + m_level = std::clamp(level, LogLevel::LNOTICE, MAX_LOGLEVEL); } -void LogManager::SetEnable(LOG_TYPE type, bool enable) +void LogManager::SetEnable(LogType type, bool enable) { m_log[type].m_enable = enable; } -bool LogManager::IsEnabled(LOG_TYPE type, LOG_LEVELS level) const +bool LogManager::IsEnabled(LogType type, LogLevel level) const { return m_log[type].m_enable && GetLogLevel() >= level; } @@ -267,18 +263,17 @@ std::map LogManager::GetLogTypes() std::map log_types; for (const auto& container : m_log) - { log_types.emplace(container.m_short_name, container.m_full_name); - } + return log_types; } -const char* LogManager::GetShortName(LOG_TYPE type) const +const char* LogManager::GetShortName(LogType type) const { return m_log[type].m_short_name; } -const char* LogManager::GetFullName(LOG_TYPE type) const +const char* LogManager::GetFullName(LogType type) const { return m_log[type].m_full_name; } diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 4481568de2..be80835552 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -9,6 +9,7 @@ #include #include "Common/BitSet.h" +#include "Common/EnumMap.h" #include "Common/Logging/Log.h" namespace Common::Log @@ -18,7 +19,7 @@ class LogListener { public: virtual ~LogListener() = default; - virtual void Log(LOG_LEVELS level, const char* msg) = 0; + virtual void Log(LogLevel level, const char* msg) = 0; enum LISTENER { @@ -37,18 +38,18 @@ public: static void Init(); static void Shutdown(); - void Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* message); + void Log(LogLevel level, LogType type, const char* file, int line, const char* message); - LOG_LEVELS GetLogLevel() const; - void SetLogLevel(LOG_LEVELS level); + LogLevel GetLogLevel() const; + void SetLogLevel(LogLevel level); - void SetEnable(LOG_TYPE type, bool enable); - bool IsEnabled(LOG_TYPE type, LOG_LEVELS level = LNOTICE) const; + void SetEnable(LogType type, bool enable); + bool IsEnabled(LogType type, LogLevel level = LogLevel::LNOTICE) const; std::map GetLogTypes(); - const char* GetShortName(LOG_TYPE type) const; - const char* GetFullName(LOG_TYPE type) const; + const char* GetShortName(LogType type) const; + const char* GetFullName(LogType type) const; void RegisterListener(LogListener::LISTENER id, LogListener* listener); void EnableListener(LogListener::LISTENER id, bool enable); @@ -72,11 +73,11 @@ private: LogManager(LogManager&&) = delete; LogManager& operator=(LogManager&&) = delete; - void LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, + void LogWithFullPath(LogLevel level, LogType type, const char* file, int line, const char* message); - LOG_LEVELS m_level; - std::array m_log{}; + LogLevel m_level; + EnumMap m_log{}; std::array m_listeners{}; BitSet32 m_listener_ids; size_t m_path_cutoff_point = 0; diff --git a/Source/Core/Core/ActionReplay.cpp b/Source/Core/Core/ActionReplay.cpp index e8cd111e66..31e0c6766e 100644 --- a/Source/Core/Core/ActionReplay.cpp +++ b/Source/Core/Core/ActionReplay.cpp @@ -315,7 +315,7 @@ static void VLogInfo(std::string_view format, fmt::format_args args) return; const bool use_internal_log = s_use_internal_log.load(std::memory_order_relaxed); - if (Common::Log::MAX_LOGLEVEL < Common::Log::LINFO && !use_internal_log) + if (Common::Log::MAX_LOGLEVEL < Common::Log::LogLevel::LINFO && !use_internal_log) return; std::string text = fmt::vformat(format, args); diff --git a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp index 725bc23985..fd60a4e58b 100644 --- a/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp +++ b/Source/Core/Core/Debugger/Debugger_SymbolMap.cpp @@ -97,7 +97,7 @@ bool GetCallstack(std::vector& output) return true; } -void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level) +void PrintCallstack(Common::Log::LogType type, Common::Log::LogLevel level) { GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", PowerPC::ppcState.gpr[1]); @@ -119,10 +119,9 @@ void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level) }); } -void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size, - std::string_view title) +void PrintDataBuffer(Common::Log::LogType type, const u8* data, size_t size, std::string_view title) { - GENERIC_LOG_FMT(type, Common::Log::LDEBUG, "{}", title); + GENERIC_LOG_FMT(type, Common::Log::LogLevel::LDEBUG, "{}", title); for (u32 j = 0; j < size;) { std::string hex_line; @@ -133,7 +132,7 @@ void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size, if (j >= size) break; } - GENERIC_LOG_FMT(type, Common::Log::LDEBUG, " Data: {}", hex_line); + GENERIC_LOG_FMT(type, Common::Log::LogLevel::LDEBUG, " Data: {}", hex_line); } } diff --git a/Source/Core/Core/Debugger/Debugger_SymbolMap.h b/Source/Core/Core/Debugger/Debugger_SymbolMap.h index 38bac8f7fa..13107c2482 100644 --- a/Source/Core/Core/Debugger/Debugger_SymbolMap.h +++ b/Source/Core/Core/Debugger/Debugger_SymbolMap.h @@ -19,8 +19,8 @@ struct CallstackEntry }; bool GetCallstack(std::vector& output); -void PrintCallstack(Common::Log::LOG_TYPE type, Common::Log::LOG_LEVELS level); -void PrintDataBuffer(Common::Log::LOG_TYPE type, const u8* data, size_t size, +void PrintCallstack(Common::Log::LogType type, Common::Log::LogLevel level); +void PrintDataBuffer(Common::Log::LogType type, const u8* data, size_t size, std::string_view title); void AddAutoBreakpoints(); diff --git a/Source/Core/Core/HW/DVD/FileMonitor.cpp b/Source/Core/Core/HW/DVD/FileMonitor.cpp index cffe1a0027..5600f980f0 100644 --- a/Source/Core/Core/HW/DVD/FileMonitor.cpp +++ b/Source/Core/Core/HW/DVD/FileMonitor.cpp @@ -53,8 +53,8 @@ static bool IsSoundFile(const std::string& filename) void Log(const DiscIO::Volume& volume, const DiscIO::Partition& partition, u64 offset) { // Do nothing if the log isn't selected - if (!Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::FILEMON, - Common::Log::LWARNING)) + if (!Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::LogType::FILEMON, + Common::Log::LogLevel::LWARNING)) { return; } diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp index 95ab599a8f..cf9ba57db1 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBA.cpp @@ -321,11 +321,11 @@ int CSIDevice_GBA::RunBuffer(u8* buffer, int request_length) if (num_data_received == 0) return -1; #ifdef _DEBUG - const Common::Log::LOG_LEVELS log_level = + const Common::Log::LogLevel log_level = (m_last_cmd == EBufferCommands::CMD_STATUS || m_last_cmd == EBufferCommands::CMD_RESET) ? - Common::Log::LERROR : - Common::Log::LWARNING; - GENERIC_LOG_FMT(Common::Log::SERIALINTERFACE, log_level, + Common::Log::LogLevel::LERROR : + Common::Log::LogLevel::LWARNING; + GENERIC_LOG_FMT(Common::Log::LogType::SERIALINTERFACE, log_level, "{} [< {:02x}{:02x}{:02x}{:02x}{:02x}] ({})", m_device_number, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], num_data_received); diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index aaf971b45e..1d672a457c 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -91,11 +91,11 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length) std::copy(response.begin(), response.end(), buffer); #ifdef _DEBUG - const Common::Log::LOG_LEVELS log_level = + const Common::Log::LogLevel log_level = (m_last_cmd == EBufferCommands::CMD_STATUS || m_last_cmd == EBufferCommands::CMD_RESET) ? - Common::Log::LERROR : - Common::Log::LWARNING; - GENERIC_LOG_FMT(Common::Log::SERIALINTERFACE, log_level, + Common::Log::LogLevel::LERROR : + Common::Log::LogLevel::LWARNING; + GENERIC_LOG_FMT(Common::Log::LogType::SERIALINTERFACE, log_level, "{} [< {:02x}{:02x}{:02x}{:02x}{:02x}] ({})", m_device_number, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], response.size()); diff --git a/Source/Core/Core/IOS/DI/DI.cpp b/Source/Core/Core/IOS/DI/DI.cpp index 567e1ecc3a..a04d18726a 100644 --- a/Source/Core/Core/IOS/DI/DI.cpp +++ b/Source/Core/Core/IOS/DI/DI.cpp @@ -705,17 +705,17 @@ std::optional DIDevice::IOCtlV(const IOCtlVRequest& request) case DIIoctl::DVDLowGetNoDiscOpenPartitionParams: ERROR_LOG_FMT(IOS_DI, "DVDLowGetNoDiscOpenPartitionParams - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_DI); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowNoDiscOpenPartition: ERROR_LOG_FMT(IOS_DI, "DVDLowNoDiscOpenPartition - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_DI); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowGetNoDiscBufferSizes: ERROR_LOG_FMT(IOS_DI, "DVDLowGetNoDiscBufferSizes - dummied out"); DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_DIFFERENT_PARTITION_COMMAND); - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_DI); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); break; case DIIoctl::DVDLowOpenPartitionWithTmdAndTicket: ERROR_LOG_FMT(IOS_DI, "DVDLowOpenPartitionWithTmdAndTicket - not implemented"); @@ -727,7 +727,7 @@ std::optional DIDevice::IOCtlV(const IOCtlVRequest& request) break; default: ERROR_LOG_FMT(IOS_DI, "Unknown ioctlv {:#04x}", request.request); - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_DI); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_DI); } return IPCReply{static_cast(return_value)}; } diff --git a/Source/Core/Core/IOS/Device.cpp b/Source/Core/Core/IOS/Device.cpp index bfc9593f1f..8754a3baa0 100644 --- a/Source/Core/Core/IOS/Device.cpp +++ b/Source/Core/Core/IOS/Device.cpp @@ -94,15 +94,15 @@ bool IOCtlVRequest::HasNumberOfValidVectors(const size_t in_count, const size_t std::all_of(io_vectors.begin(), io_vectors.end(), IsValidVector); } -void IOCtlRequest::Log(std::string_view device_name, Common::Log::LOG_TYPE type, - Common::Log::LOG_LEVELS verbosity) const +void IOCtlRequest::Log(std::string_view device_name, Common::Log::LogType type, + Common::Log::LogLevel verbosity) const { GENERIC_LOG_FMT(type, verbosity, "{} (fd {}) - IOCtl {:#x} (in_size={:#x}, out_size={:#x})", device_name, fd, request, buffer_in_size, buffer_out_size); } -void IOCtlRequest::Dump(const std::string& description, Common::Log::LOG_TYPE type, - Common::Log::LOG_LEVELS level) const +void IOCtlRequest::Dump(const std::string& description, Common::Log::LogType type, + Common::Log::LogLevel level) const { Log("===== " + description, type, level); GENERIC_LOG_FMT(type, level, "In buffer\n{}", @@ -111,14 +111,14 @@ void IOCtlRequest::Dump(const std::string& description, Common::Log::LOG_TYPE ty HexDump(Memory::GetPointer(buffer_out), buffer_out_size)); } -void IOCtlRequest::DumpUnknown(const std::string& description, Common::Log::LOG_TYPE type, - Common::Log::LOG_LEVELS level) const +void IOCtlRequest::DumpUnknown(const std::string& description, Common::Log::LogType type, + Common::Log::LogLevel level) const { Dump("Unknown IOCtl - " + description, type, level); } -void IOCtlVRequest::Dump(std::string_view description, Common::Log::LOG_TYPE type, - Common::Log::LOG_LEVELS level) const +void IOCtlVRequest::Dump(std::string_view description, Common::Log::LogType type, + Common::Log::LogLevel level) const { GENERIC_LOG_FMT(type, level, "===== {} (fd {}) - IOCtlV {:#x} ({} in, {} io)", description, fd, request, in_vectors.size(), io_vectors.size()); @@ -135,8 +135,8 @@ void IOCtlVRequest::Dump(std::string_view description, Common::Log::LOG_TYPE typ GENERIC_LOG_FMT(type, level, "io[{}] (size={:#x})", i++, vector.size); } -void IOCtlVRequest::DumpUnknown(const std::string& description, Common::Log::LOG_TYPE type, - Common::Log::LOG_LEVELS level) const +void IOCtlVRequest::DumpUnknown(const std::string& description, Common::Log::LogType type, + Common::Log::LogLevel level) const { Dump("Unknown IOCtlV - " + description, type, level); } diff --git a/Source/Core/Core/IOS/Device.h b/Source/Core/Core/IOS/Device.h index e1282eadb0..2fe1abf37e 100644 --- a/Source/Core/Core/IOS/Device.h +++ b/Source/Core/Core/IOS/Device.h @@ -130,12 +130,13 @@ struct IOCtlRequest final : Request u32 buffer_out = 0; u32 buffer_out_size = 0; explicit IOCtlRequest(u32 address); - void Log(std::string_view description, Common::Log::LOG_TYPE type = Common::Log::IOS, - Common::Log::LOG_LEVELS level = Common::Log::LINFO) const; - void Dump(const std::string& description, Common::Log::LOG_TYPE type = Common::Log::IOS, - Common::Log::LOG_LEVELS level = Common::Log::LINFO) const; - void DumpUnknown(const std::string& description, Common::Log::LOG_TYPE type = Common::Log::IOS, - Common::Log::LOG_LEVELS level = Common::Log::LERROR) const; + void Log(std::string_view description, Common::Log::LogType type = Common::Log::LogType::IOS, + Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; + void Dump(const std::string& description, Common::Log::LogType type = Common::Log::LogType::IOS, + Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; + void DumpUnknown(const std::string& description, + Common::Log::LogType type = Common::Log::LogType::IOS, + Common::Log::LogLevel level = Common::Log::LogLevel::LERROR) const; }; struct IOCtlVRequest final : Request @@ -160,10 +161,11 @@ struct IOCtlVRequest final : Request explicit IOCtlVRequest(u32 address); bool HasNumberOfValidVectors(size_t in_count, size_t io_count) const; - void Dump(std::string_view description, Common::Log::LOG_TYPE type = Common::Log::IOS, - Common::Log::LOG_LEVELS level = Common::Log::LINFO) const; - void DumpUnknown(const std::string& description, Common::Log::LOG_TYPE type = Common::Log::IOS, - Common::Log::LOG_LEVELS level = Common::Log::LERROR) const; + void Dump(std::string_view description, Common::Log::LogType type = Common::Log::LogType::IOS, + Common::Log::LogLevel level = Common::Log::LogLevel::LINFO) const; + void DumpUnknown(const std::string& description, + Common::Log::LogType type = Common::Log::LogType::IOS, + Common::Log::LogLevel level = Common::Log::LogLevel::LERROR) const; }; class Device diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 2191c2ebd2..ce5b7bc56b 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -680,7 +680,8 @@ std::optional ESDevice::IOCtlV(const IOCtlVRequest& request) case IOCTL_ES_UNKNOWN_42: PanicAlertFmt("IOS-ES: Unimplemented ioctlv {:#x} ({} in vectors, {} io vectors)", request.request, request.in_vectors.size(), request.io_vectors.size()); - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_ES, Common::Log::LERROR); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_ES, + Common::Log::LogLevel::LERROR); return IPCReply(IPC_EINVAL); case IOCTL_ES_INVALID_3F: diff --git a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp index 14f45d5c38..7113b169e6 100644 --- a/Source/Core/Core/IOS/FS/FileSystemProxy.cpp +++ b/Source/Core/Core/IOS/FS/FileSystemProxy.cpp @@ -104,9 +104,10 @@ template static void LogResult(ResultCode code, std::string_view format, Args&&... args) { const std::string command = fmt::format(format, std::forward(args)...); - const auto type = code == ResultCode::Success ? Common::Log::LINFO : Common::Log::LERROR; + const auto type = + code == ResultCode::Success ? Common::Log::LogLevel::LINFO : Common::Log::LogLevel::LERROR; - GENERIC_LOG_FMT(Common::Log::IOS_FS, type, "Command: {}: Result {}", command, + GENERIC_LOG_FMT(Common::Log::LogType::IOS_FS, type, "Command: {}: Result {}", command, ConvertResult(code)); } diff --git a/Source/Core/Core/IOS/Network/IP/Top.cpp b/Source/Core/Core/IOS/Network/IP/Top.cpp index 4eb2455c19..3f94fe737c 100644 --- a/Source/Core/Core/IOS/Network/IP/Top.cpp +++ b/Source/Core/Core/IOS/Network/IP/Top.cpp @@ -330,7 +330,7 @@ std::optional NetIPTopDevice::IOCtl(const IOCtlRequest& request) case IOCTL_SO_ICMPCANCEL: return HandleICMPCancelRequest(request); default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_NET); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_NET); break; } @@ -352,7 +352,7 @@ std::optional NetIPTopDevice::IOCtlV(const IOCtlVRequest& request) case IOCTLV_SO_ICMPPING: return HandleICMPPingRequest(request); default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_NET); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_NET); break; } @@ -375,7 +375,7 @@ void NetIPTopDevice::Update() IPCReply NetIPTopDevice::HandleInitInterfaceRequest(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_WC24); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); return IPCReply(IPC_SUCCESS); } @@ -451,7 +451,7 @@ IPCReply NetIPTopDevice::HandleListenRequest(const IOCtlRequest& request) u32 BACKLOG = Memory::Read_U32(request.buffer_in + 0x04); u32 ret = listen(WiiSockMan::GetInstance().GetHostSocket(fd), BACKLOG); - request.Log(GetDeviceName(), Common::Log::IOS_WC24); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); return IPCReply(WiiSockMan::GetNetErrorCode(ret, "SO_LISTEN", false)); } @@ -461,7 +461,7 @@ IPCReply NetIPTopDevice::HandleGetSockOptRequest(const IOCtlRequest& request) u32 level = Memory::Read_U32(request.buffer_out + 4); u32 optname = Memory::Read_U32(request.buffer_out + 8); - request.Log(GetDeviceName(), Common::Log::IOS_WC24); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); // Do the level/optname translation int nat_level = MapWiiSockOptLevelToNative(level); @@ -527,7 +527,7 @@ IPCReply NetIPTopDevice::HandleGetSockNameRequest(const IOCtlRequest& request) { u32 fd = Memory::Read_U32(request.buffer_in); - request.Log(GetDeviceName(), Common::Log::IOS_WC24); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); sockaddr sa; socklen_t sa_len = sizeof(sa); @@ -1047,7 +1047,7 @@ IPCReply NetIPTopDevice::HandleGetAddressInfoRequest(const IOCtlVRequest& reques ret = SO_ERROR_HOST_NOT_FOUND; } - request.Dump(GetDeviceName(), Common::Log::IOS_NET, Common::Log::LINFO); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_NET, Common::Log::LogLevel::LINFO); return IPCReply(ret); } diff --git a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp index 986633ed76..d5207141f5 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDRequest.cpp @@ -314,7 +314,7 @@ std::optional NetKDRequestDevice::IOCtl(const IOCtlRequest& request) } default: - request.Log(GetDeviceName(), Common::Log::IOS_WC24); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_WC24); } return IPCReply(return_value); diff --git a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp index 5011647e6e..ddc4234d85 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp @@ -74,7 +74,7 @@ std::optional NetKDTimeDevice::IOCtl(const IOCtlRequest& request) break; default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_WC24); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WC24); break; } diff --git a/Source/Core/Core/IOS/Network/SSL.cpp b/Source/Core/Core/IOS/Network/SSL.cpp index adb3a31e95..68ca8bc724 100644 --- a/Source/Core/Core/IOS/Network/SSL.cpp +++ b/Source/Core/Core/IOS/Network/SSL.cpp @@ -128,7 +128,7 @@ int NetSSLDevice::GetSSLFreeID() const std::optional NetSSLDevice::IOCtl(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_SSL, Common::Log::LINFO); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_SSL, Common::Log::LogLevel::LINFO); return IPCReply(IPC_SUCCESS); } @@ -609,7 +609,7 @@ std::optional NetSSLDevice::IOCtlV(const IOCtlVRequest& request) break; } default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_SSL); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_SSL); } // SSL return codes are written to BufferIn diff --git a/Source/Core/Core/IOS/Network/Socket.cpp b/Source/Core/Core/IOS/Network/Socket.cpp index 806d3fb45f..ae5f882e90 100644 --- a/Source/Core/Core/IOS/Network/Socket.cpp +++ b/Source/Core/Core/IOS/Network/Socket.cpp @@ -322,7 +322,7 @@ void WiiSocket::Update(bool read, bool write, bool except) ReturnValue = WiiSockMan::GetInstance().AddSocket(ret, true); - ioctl.Log("IOCTL_SO_ACCEPT", Common::Log::IOS_NET); + ioctl.Log("IOCTL_SO_ACCEPT", Common::Log::LogType::IOS_NET); break; } default: diff --git a/Source/Core/Core/IOS/Network/WD/Command.cpp b/Source/Core/Core/IOS/Network/WD/Command.cpp index 70c1f079b8..b57dad4aa2 100644 --- a/Source/Core/Core/IOS/Network/WD/Command.cpp +++ b/Source/Core/Core/IOS/Network/WD/Command.cpp @@ -378,7 +378,7 @@ std::optional NetWDCommandDevice::IOCtlV(const IOCtlVRequest& request) case IOCTLV_WD_CHANGE_VTSF: default: DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_WD_UNIMPLEMENTED_IOCTL); - request.Dump(GetDeviceName(), Common::Log::IOS_NET, Common::Log::LWARNING); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_NET, Common::Log::LogLevel::LWARNING); } return IPCReply(IPC_SUCCESS); diff --git a/Source/Core/Core/IOS/STM/STM.cpp b/Source/Core/Core/IOS/STM/STM.cpp index af65cacfca..32635bfe0b 100644 --- a/Source/Core/Core/IOS/STM/STM.cpp +++ b/Source/Core/Core/IOS/STM/STM.cpp @@ -55,7 +55,7 @@ std::optional STMImmediateDevice::IOCtl(const IOCtlRequest& request) break; default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_STM); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_STM); } return IPCReply(return_value); diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index f9fdac1509..341ef54d3e 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -200,7 +200,7 @@ std::optional BluetoothEmuDevice::IOCtlV(const IOCtlVRequest& request) } default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_WIIMOTE); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WIIMOTE); } if (!send_reply) @@ -1710,7 +1710,7 @@ void BluetoothEmuDevice::CommandVendorSpecific_FC4F(const u8* input, u32 size) INFO_LOG_FMT(IOS_WIIMOTE, "Command: CommandVendorSpecific_FC4F: (callstack WUDiRemovePatch)"); DEBUG_LOG_FMT(IOS_WIIMOTE, "Input (size {:#x}):", size); - Dolphin_Debugger::PrintDataBuffer(Common::Log::IOS_WIIMOTE, input, size, "Data: "); + Dolphin_Debugger::PrintDataBuffer(Common::Log::LogType::IOS_WIIMOTE, input, size, "Data: "); SendEventCommandComplete(0xFC4F, &reply, sizeof(hci_status_rp)); } @@ -1722,7 +1722,7 @@ void BluetoothEmuDevice::CommandVendorSpecific_FC4C(const u8* input, u32 size) DEBUG_LOG_FMT(IOS_WIIMOTE, "Command: CommandVendorSpecific_FC4C:"); DEBUG_LOG_FMT(IOS_WIIMOTE, "Input (size {:#x}):", size); - Dolphin_Debugger::PrintDataBuffer(Common::Log::IOS_WIIMOTE, input, size, "Data: "); + Dolphin_Debugger::PrintDataBuffer(Common::Log::LogType::IOS_WIIMOTE, input, size, "Data: "); SendEventCommandComplete(0xFC4C, &reply, sizeof(hci_status_rp)); } diff --git a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp index d063259975..762f576621 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/WiimoteDevice.cpp @@ -799,16 +799,12 @@ static int ParseAttribList(u8* attrib_id_list, u16& start_id, u16& end_id) const u8 sequence = attrib_list.Read8(attrib_offset); attrib_offset++; - const u8 seq_size = attrib_list.Read8(attrib_offset); + [[maybe_unused]] const u8 seq_size = attrib_list.Read8(attrib_offset); attrib_offset++; const u8 type_id = attrib_list.Read8(attrib_offset); attrib_offset++; - if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LOG_LEVELS::LDEBUG) - { - DEBUG_ASSERT(sequence == SDP_SEQ8); - (void)seq_size; - } + DEBUG_ASSERT(sequence == SDP_SEQ8); if (type_id == SDP_UINT32) { diff --git a/Source/Core/Core/IOS/USB/OH0/OH0.cpp b/Source/Core/Core/IOS/USB/OH0/OH0.cpp index a4b22ed676..7fc3702e96 100644 --- a/Source/Core/Core/IOS/USB/OH0/OH0.cpp +++ b/Source/Core/Core/IOS/USB/OH0/OH0.cpp @@ -39,7 +39,7 @@ std::optional OH0::Open(const OpenRequest& request) std::optional OH0::IOCtl(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_USB); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { case USB::IOCTL_USBV0_GETRHDESCA: @@ -135,7 +135,7 @@ IPCReply OH0::GetRhDesca(const IOCtlRequest& request) const // Based on a hardware test, this ioctl seems to return a constant value Memory::Write_U32(0x02000302, request.buffer_out); - request.Dump(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LWARNING); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LWARNING); return IPCReply(IPC_SUCCESS); } @@ -145,7 +145,7 @@ IPCReply OH0::GetRhPortStatus(const IOCtlVRequest& request) const return IPCReply(IPC_EINVAL); ERROR_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: IOCTLV_USBV0_GETRHPORTSTATUS"); - request.Dump(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LERROR); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -155,7 +155,7 @@ IPCReply OH0::SetRhPortStatus(const IOCtlVRequest& request) return IPCReply(IPC_EINVAL); ERROR_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: IOCTLV_USBV0_SETRHPORTSTATUS"); - request.Dump(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LERROR); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } @@ -208,7 +208,7 @@ std::optional OH0::RegisterClassChangeHook(const IOCtlVRequest& reques if (!request.HasNumberOfValidVectors(1, 0)) return IPCReply(IPC_EINVAL); WARN_LOG_FMT(IOS_USB, "Unimplemented IOCtlV: USB::IOCTLV_USBV0_DEVICECLASSCHANGE (no reply)"); - request.Dump(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LWARNING); + request.Dump(GetDeviceName(), Common::Log::LogType::IOS_USB, Common::Log::LogLevel::LWARNING); return std::nullopt; } @@ -307,7 +307,7 @@ std::optional OH0::DeviceIOCtlV(const u64 device_id, const IOCtlVReque return HandleTransfer(device, request.request, [&, this]() { return SubmitTransfer(*device, request); }); case USB::IOCTLV_USBV0_UNKNOWN_32: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_USB); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); return IPCReply(IPC_SUCCESS); default: return IPCReply(IPC_EINVAL); diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp index 3308e4cfa3..e6006edba0 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp @@ -32,7 +32,7 @@ USB_HIDv4::~USB_HIDv4() std::optional USB_HIDv4::IOCtl(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_USB); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { case USB::IOCTL_USBV4_GETVERSION: @@ -60,7 +60,7 @@ std::optional USB_HIDv4::IOCtl(const IOCtlRequest& request) [&, this]() { return SubmitTransfer(*device, request); }); } default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_USB); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); return IPCReply(IPC_SUCCESS); } } diff --git a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp index 3c7ee291d5..df38026666 100644 --- a/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp +++ b/Source/Core/Core/IOS/USB/USB_HID/HIDv5.cpp @@ -24,7 +24,7 @@ USB_HIDv5::~USB_HIDv5() std::optional USB_HIDv5::IOCtl(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_USB); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { case USB::IOCTL_USBV5_GETVERSION: @@ -46,14 +46,15 @@ std::optional USB_HIDv5::IOCtl(const IOCtlRequest& request) return HandleDeviceIOCtl(request, [&](USBV5Device& device) { return CancelEndpoint(device, request); }); default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LERROR); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } } std::optional USB_HIDv5::IOCtlV(const IOCtlVRequest& request) { - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_USB); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { // TODO: HIDv5 seems to be able to queue transfers depending on the transfer length (unlike VEN). diff --git a/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp b/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp index ca4b2b1f03..eb4f3cda8a 100644 --- a/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp +++ b/Source/Core/Core/IOS/USB/USB_VEN/VEN.cpp @@ -24,7 +24,7 @@ USB_VEN::~USB_VEN() std::optional USB_VEN::IOCtl(const IOCtlRequest& request) { - request.Log(GetDeviceName(), Common::Log::IOS_USB); + request.Log(GetDeviceName(), Common::Log::LogType::IOS_USB); switch (request.request) { case USB::IOCTL_USBV5_GETVERSION: @@ -49,7 +49,8 @@ std::optional USB_VEN::IOCtl(const IOCtlRequest& request) return HandleDeviceIOCtl(request, [&](USBV5Device& device) { return CancelEndpoint(device, request); }); default: - request.DumpUnknown(GetDeviceName(), Common::Log::IOS_USB, Common::Log::LERROR); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_USB, + Common::Log::LogLevel::LERROR); return IPCReply(IPC_SUCCESS); } } diff --git a/Source/Core/Core/IOS/WFS/WFSI.cpp b/Source/Core/Core/IOS/WFS/WFSI.cpp index d3223f89ab..9f9c3b291b 100644 --- a/Source/Core/Core/IOS/WFS/WFSI.cpp +++ b/Source/Core/Core/IOS/WFS/WFSI.cpp @@ -540,7 +540,8 @@ std::optional WFSIDevice::IOCtl(const IOCtlRequest& request) // TODO(wfs): Should be returning an error. However until we have // everything properly stubbed it's easier to simulate the methods // succeeding. - request.DumpUnknown(GetDeviceName(), Common::Log::IOS, Common::Log::LWARNING); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS, + Common::Log::LogLevel::LWARNING); Memory::Memset(request.buffer_out, 0, request.buffer_out_size); break; } diff --git a/Source/Core/Core/IOS/WFS/WFSSRV.cpp b/Source/Core/Core/IOS/WFS/WFSSRV.cpp index ae70d1e31d..e6130798fb 100644 --- a/Source/Core/Core/IOS/WFS/WFSSRV.cpp +++ b/Source/Core/Core/IOS/WFS/WFSSRV.cpp @@ -353,7 +353,8 @@ std::optional WFSSRVDevice::IOCtl(const IOCtlRequest& request) default: // TODO(wfs): Should be returning -3. However until we have everything // properly stubbed it's easier to simulate the methods succeeding. - request.DumpUnknown(GetDeviceName(), Common::Log::IOS, Common::Log::LWARNING); + request.DumpUnknown(GetDeviceName(), Common::Log::LogType::IOS_WFS, + Common::Log::LogLevel::LWARNING); Memory::Memset(request.buffer_out, 0, request.buffer_out_size); break; } diff --git a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp index 460d024186..1582291f04 100644 --- a/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp +++ b/Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp @@ -329,7 +329,7 @@ void Interpreter::unknown_instruction(UGeckoInstruction inst) const u32 opcode = PowerPC::HostRead_U32(last_pc); const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc); NOTICE_LOG_FMT(POWERPC, "Last PC = {:08x} : {}", last_pc, disasm); - Dolphin_Debugger::PrintCallstack(Common::Log::POWERPC, Common::Log::LNOTICE); + Dolphin_Debugger::PrintCallstack(Common::Log::LogType::POWERPC, Common::Log::LogLevel::LNOTICE); NOTICE_LOG_FMT( POWERPC, "\nIntCPU: Unknown instruction {:08x} at PC = {:08x} last_PC = {:08x} LR = {:08x}\n", diff --git a/Source/Core/DolphinQt/Config/LogConfigWidget.cpp b/Source/Core/DolphinQt/Config/LogConfigWidget.cpp index 3a7df3fb66..dab59e63d9 100644 --- a/Source/Core/DolphinQt/Config/LogConfigWidget.cpp +++ b/Source/Core/DolphinQt/Config/LogConfigWidget.cpp @@ -62,9 +62,9 @@ void LogConfigWidget::CreateWidgets() m_types_list = new QListWidget; const auto* const log_manager = Common::Log::LogManager::GetInstance(); - for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; i++) + for (int i = 0; i < static_cast(Common::Log::LogType::NUMBER_OF_LOGS); i++) { - const auto log_type = static_cast(i); + const auto log_type = static_cast(i); const QString full_name = QString::fromUtf8(log_manager->GetFullName(log_type)); const QString short_name = QString::fromUtf8(log_manager->GetShortName(log_type)); auto* widget = new QListWidgetItem(QStringLiteral("%1 (%2)").arg(full_name, short_name)); @@ -77,7 +77,7 @@ void LogConfigWidget::CreateWidgets() verbosity_layout->addWidget(m_verbosity_error); verbosity_layout->addWidget(m_verbosity_warning); verbosity_layout->addWidget(m_verbosity_info); - if constexpr (Common::Log::MAX_LOGLEVEL == Common::Log::LOG_LEVELS::LDEBUG) + if constexpr (Common::Log::MAX_LOGLEVEL == Common::Log::LogLevel::LDEBUG) { verbosity_layout->addWidget(m_verbosity_debug); } @@ -139,12 +139,12 @@ void LogConfigWidget::LoadSettings() setFloating(settings.value(QStringLiteral("logconfigwidget/floating")).toBool()); // Config - Verbosity - const Common::Log::LOG_LEVELS verbosity = log_manager->GetLogLevel(); - m_verbosity_notice->setChecked(verbosity == Common::Log::LOG_LEVELS::LNOTICE); - m_verbosity_error->setChecked(verbosity == Common::Log::LOG_LEVELS::LERROR); - m_verbosity_warning->setChecked(verbosity == Common::Log::LOG_LEVELS::LWARNING); - m_verbosity_info->setChecked(verbosity == Common::Log::LOG_LEVELS::LINFO); - m_verbosity_debug->setChecked(verbosity == Common::Log::LOG_LEVELS::LDEBUG); + const Common::Log::LogLevel verbosity = log_manager->GetLogLevel(); + m_verbosity_notice->setChecked(verbosity == Common::Log::LogLevel::LNOTICE); + m_verbosity_error->setChecked(verbosity == Common::Log::LogLevel::LERROR); + m_verbosity_warning->setChecked(verbosity == Common::Log::LogLevel::LWARNING); + m_verbosity_info->setChecked(verbosity == Common::Log::LogLevel::LINFO); + m_verbosity_debug->setChecked(verbosity == Common::Log::LogLevel::LDEBUG); // Config - Outputs m_out_file->setChecked(log_manager->IsListenerEnabled(Common::Log::LogListener::FILE_LISTENER)); @@ -154,9 +154,9 @@ void LogConfigWidget::LoadSettings() log_manager->IsListenerEnabled(Common::Log::LogListener::LOG_WINDOW_LISTENER)); // Config - Log Types - for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; ++i) + for (int i = 0; i < static_cast(Common::Log::LogType::NUMBER_OF_LOGS); ++i) { - const auto log_type = static_cast(i); + const auto log_type = static_cast(i); const bool log_enabled = log_manager->IsEnabled(log_type); if (!log_enabled) @@ -177,22 +177,22 @@ void LogConfigWidget::SaveSettings() settings.setValue(QStringLiteral("logconfigwidget/floating"), isFloating()); // Config - Verbosity - auto verbosity = Common::Log::LOG_LEVELS::LNOTICE; + auto verbosity = Common::Log::LogLevel::LNOTICE; if (m_verbosity_notice->isChecked()) - verbosity = Common::Log::LOG_LEVELS::LNOTICE; + verbosity = Common::Log::LogLevel::LNOTICE; if (m_verbosity_error->isChecked()) - verbosity = Common::Log::LOG_LEVELS::LERROR; + verbosity = Common::Log::LogLevel::LERROR; if (m_verbosity_warning->isChecked()) - verbosity = Common::Log::LOG_LEVELS::LWARNING; + verbosity = Common::Log::LogLevel::LWARNING; if (m_verbosity_info->isChecked()) - verbosity = Common::Log::LOG_LEVELS::LINFO; + verbosity = Common::Log::LogLevel::LINFO; if (m_verbosity_debug->isChecked()) - verbosity = Common::Log::LOG_LEVELS::LDEBUG; + verbosity = Common::Log::LogLevel::LDEBUG; auto* const log_manager = Common::Log::LogManager::GetInstance(); @@ -206,9 +206,9 @@ void LogConfigWidget::SaveSettings() log_manager->EnableListener(Common::Log::LogListener::LOG_WINDOW_LISTENER, m_out_window->isChecked()); // Config - Log Types - for (int i = 0; i < Common::Log::NUMBER_OF_LOGS; ++i) + for (int i = 0; i < static_cast(Common::Log::LogType::NUMBER_OF_LOGS); ++i) { - const auto type = static_cast(i); + const auto type = static_cast(i); const bool enabled = m_types_list->item(i)->checkState() == Qt::Checked; const bool was_enabled = log_manager->IsEnabled(type); diff --git a/Source/Core/DolphinQt/Config/LogWidget.cpp b/Source/Core/DolphinQt/Config/LogWidget.cpp index f5cab045a3..bcb0db6d2c 100644 --- a/Source/Core/DolphinQt/Config/LogWidget.cpp +++ b/Source/Core/DolphinQt/Config/LogWidget.cpp @@ -80,21 +80,21 @@ void LogWidget::UpdateLog() for (auto& line : elements_to_push) { const char* color = "white"; - switch (std::get(line)) + switch (std::get(line)) { - case Common::Log::LOG_LEVELS::LERROR: + case Common::Log::LogLevel::LERROR: color = "red"; break; - case Common::Log::LOG_LEVELS::LWARNING: + case Common::Log::LogLevel::LWARNING: color = "yellow"; break; - case Common::Log::LOG_LEVELS::LNOTICE: + case Common::Log::LogLevel::LNOTICE: color = "lime"; break; - case Common::Log::LOG_LEVELS::LINFO: + case Common::Log::LogLevel::LINFO: color = "cyan"; break; - case Common::Log::LOG_LEVELS::LDEBUG: + case Common::Log::LogLevel::LDEBUG: color = "lightgrey"; break; } @@ -210,7 +210,7 @@ void LogWidget::SaveSettings() UpdateFont(); } -void LogWidget::Log(Common::Log::LOG_LEVELS level, const char* text) +void LogWidget::Log(Common::Log::LogLevel level, const char* text) { size_t text_length = strlen(text); while (text_length > 0 && text[text_length - 1] == '\n') diff --git a/Source/Core/DolphinQt/Config/LogWidget.h b/Source/Core/DolphinQt/Config/LogWidget.h index 88cb2888cc..44f36c8834 100644 --- a/Source/Core/DolphinQt/Config/LogWidget.h +++ b/Source/Core/DolphinQt/Config/LogWidget.h @@ -36,7 +36,7 @@ private: void LoadSettings(); void SaveSettings(); - void Log(Common::Log::LOG_LEVELS level, const char* text) override; + void Log(Common::Log::LogLevel level, const char* text) override; // Log QCheckBox* m_log_wrap; @@ -46,7 +46,7 @@ private: QTimer* m_timer; - using LogEntry = std::pair; + using LogEntry = std::pair; // Maximum number of lines to show in log viewer static constexpr int MAX_LOG_LINES = 5000; diff --git a/Source/Core/VideoBackends/OGL/OGLRender.cpp b/Source/Core/VideoBackends/OGL/OGLRender.cpp index a7359358b5..782d5e1747 100644 --- a/Source/Core/VideoBackends/OGL/OGLRender.cpp +++ b/Source/Core/VideoBackends/OGL/OGLRender.cpp @@ -695,8 +695,8 @@ Renderer::Renderer(std::unique_ptr main_gl_context, float backbuffer_ glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, true); glDebugMessageCallbackARB(ErrorCallback, nullptr); } - if (Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::HOST_GPU, - Common::Log::LERROR)) + if (Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::LogType::HOST_GPU, + Common::Log::LogLevel::LERROR)) { glEnable(GL_DEBUG_OUTPUT); } @@ -1026,8 +1026,8 @@ void Renderer::PresentBackbuffer() { if (g_ogl_config.bSupportsDebug) { - if (Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::HOST_GPU, - Common::Log::LERROR)) + if (Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::LogType::HOST_GPU, + Common::Log::LogLevel::LERROR)) { glEnable(GL_DEBUG_OUTPUT); } diff --git a/Source/Core/VideoBackends/Vulkan/VKMain.cpp b/Source/Core/VideoBackends/Vulkan/VKMain.cpp index d623069446..abe531aac3 100644 --- a/Source/Core/VideoBackends/Vulkan/VKMain.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKMain.cpp @@ -78,8 +78,8 @@ void VideoBackend::InitBackendInfo() // Helper method to check whether the Host GPU logging category is enabled. static bool IsHostGPULoggingEnabled() { - return Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::HOST_GPU, - Common::Log::LERROR); + return Common::Log::LogManager::GetInstance()->IsEnabled(Common::Log::LogType::HOST_GPU, + Common::Log::LogLevel::LERROR); } // Helper method to determine whether to enable the debug report extension. diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 1e72217843..6c58369204 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -671,13 +671,13 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(VkDebugReportFlagsEXT const std::string log_message = fmt::format("Vulkan debug report: ({}) {}", pLayerPrefix ? pLayerPrefix : "", pMessage); if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) - GENERIC_LOG_FMT(Common::Log::HOST_GPU, Common::Log::LERROR, "{}", log_message); + ERROR_LOG_FMT(HOST_GPU, "{}", log_message); else if (flags & (VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT)) - GENERIC_LOG_FMT(Common::Log::HOST_GPU, Common::Log::LWARNING, "{}", log_message); + WARN_LOG_FMT(HOST_GPU, "{}", log_message); else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) - GENERIC_LOG_FMT(Common::Log::HOST_GPU, Common::Log::LINFO, "{}", log_message); + INFO_LOG_FMT(HOST_GPU, "{}", log_message); else - GENERIC_LOG_FMT(Common::Log::HOST_GPU, Common::Log::LDEBUG, "{}", log_message); + DEBUG_LOG_FMT(HOST_GPU, "{}", log_message); return VK_FALSE; } diff --git a/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp b/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp index 2884b362a6..e36ef7af28 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp @@ -8,7 +8,6 @@ #include "Common/CommonFuncs.h" #include "Common/DynamicLibrary.h" #include "Common/FileUtil.h" -#include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "VideoBackends/Vulkan/VulkanLoader.h" @@ -205,7 +204,8 @@ const char* VkResultToString(VkResult res) } } -void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...) +void LogVulkanResult(Common::Log::LogLevel level, const char* func_name, VkResult res, + const char* msg, ...) { std::va_list ap; va_start(ap, msg); @@ -215,7 +215,7 @@ void LogVulkanResult(int level, const char* func_name, VkResult res, const char* real_msg = fmt::format("({}) {} ({}: {})", func_name, real_msg, static_cast(res), VkResultToString(res)); - GENERIC_LOG_FMT(Common::Log::VIDEO, static_cast(level), "{}", real_msg); + GENERIC_LOG_FMT(Common::Log::LogType::VIDEO, level, "{}", real_msg); } } // namespace Vulkan diff --git a/Source/Core/VideoBackends/Vulkan/VulkanLoader.h b/Source/Core/VideoBackends/Vulkan/VulkanLoader.h index bc32434448..8ac86668b8 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanLoader.h +++ b/Source/Core/VideoBackends/Vulkan/VulkanLoader.h @@ -37,6 +37,8 @@ #undef VULKAN_INSTANCE_ENTRY_POINT #undef VULKAN_MODULE_ENTRY_POINT +#include "Common/Logging/Log.h" + namespace Vulkan { bool LoadVulkanLibrary(); @@ -45,8 +47,10 @@ bool LoadVulkanDeviceFunctions(VkDevice device); void UnloadVulkanLibrary(); const char* VkResultToString(VkResult res); -void LogVulkanResult(int level, const char* func_name, VkResult res, const char* msg, ...); +void LogVulkanResult(Common::Log::LogLevel level, const char* func_name, VkResult res, + const char* msg, ...); -#define LOG_VULKAN_ERROR(res, ...) LogVulkanResult(2, __func__, res, __VA_ARGS__) +#define LOG_VULKAN_ERROR(res, ...) \ + LogVulkanResult(Common::Log::LogLevel::LERROR, __func__, res, __VA_ARGS__) } // namespace Vulkan