diff --git a/src/Common/Logging.cpp b/src/Common/Logging.cpp index c99e88199..4e42c108f 100644 --- a/src/Common/Logging.cpp +++ b/src/Common/Logging.cpp @@ -36,7 +36,9 @@ #include // for PULONG -#include "Logging.h" +#include "Logging.h" +#include "Common/Settings.hpp" +#include "CxbxKrnl/EmuShared.h" // For thread_local, see : http://en.cppreference.com/w/cpp/language/storage_duration // TODO : Use Boost.Format http://www.boost.org/doc/libs/1_53_0/libs/format/index.html @@ -102,7 +104,35 @@ const char* g_EnumModules2String[to_underlying(CXBXR_MODULE::MAX)] = { "XC ", "XE ", }; -std::atomic_int g_CurrentLogLevel = to_underlying(LOG_LEVEL::INFO); +std::atomic_int g_CurrentLogLevel = to_underlying(LOG_LEVEL::INFO); + +// Set up the logging variables for the GUI process +inline void get_log_settings() +{ + set_log_config(g_Settings->m_core.LogLevel, g_Settings->m_core.LoggedModules); +} + +inline void sync_log_config() +{ + int LogLevel; + uint LoggedModules[NUM_INTEGERS_LOG]; + g_EmuShared->GetLogLv(&LogLevel); + g_EmuShared->GetLogModules(LoggedModules); + set_log_config(LogLevel, LoggedModules); +} + +void set_log_config(int LogLevel, uint* LoggedModules) +{ + g_CurrentLogLevel = LogLevel; + for (int index = to_underlying(CXBXR_MODULE::CXBXR); index < to_underlying(CXBXR_MODULE::MAX); index++) { + if (LoggedModules[index / 32] & (1 << (index % 32))) { + g_EnabledModules[index] = true; + } + else { + g_EnabledModules[index] = false; + } + } +} const bool needs_escape(const wint_t _char) { diff --git a/src/Common/Logging.h b/src/Common/Logging.h index b6cbb60da..012693d4f 100644 --- a/src/Common/Logging.h +++ b/src/Common/Logging.h @@ -118,6 +118,12 @@ typedef enum class _CXBXR_MODULE { extern std::atomic_bool g_EnabledModules[to_underlying(CXBXR_MODULE::MAX)]; extern const char* g_EnumModules2String[to_underlying(CXBXR_MODULE::MAX)]; extern std::atomic_int g_CurrentLogLevel; + +extern inline void get_log_settings(); + +extern inline void sync_log_config(); + +void set_log_config(int LogLevel, uint* LoggedModules); // // __FILENAME__ diff --git a/src/Cxbx/DlgLoggingConfig.cpp b/src/Cxbx/DlgLoggingConfig.cpp index 77ebd3aa5..fb5ee0360 100644 --- a/src/Cxbx/DlgLoggingConfig.cpp +++ b/src/Cxbx/DlgLoggingConfig.cpp @@ -239,33 +239,15 @@ INT_PTR CALLBACK DlgLogConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM g_Settings->m_core.LoggedModules[1] = LoggedModules[1]; g_Settings->m_core.LogLevel = LogLevel; - // This is necessary because otherwise relaunched xbe's in multi-xbe titles will still use the old settings - g_EmuShared->SetLogLv(&LogLevel); - g_EmuShared->SetLogModules(LoggedModules); - // Update the logging variables for the GUI process - g_CurrentLogLevel = LogLevel; - for (int index = to_underlying(CXBXR_MODULE::CXBXR); index < to_underlying(CXBXR_MODULE::MAX); index++) { - if (LoggedModules[index / 32] & (1 << (index % 32))) { - g_EnabledModules[index] = true; - } - else { - g_EnabledModules[index] = false; - } - } + set_log_config(LogLevel, LoggedModules); // Also inform the kernel process if it exists if (g_ChildWnd) { - COPYDATASTRUCT CopyData; - LogData Data; - Data.Level = LogLevel; - for (int i = 0; i < NUM_INTEGERS_LOG; i++) { - Data.LoggedModules[i] = LoggedModules[i]; - } - CopyData.dwData = LOG_ID; - CopyData.cbData = sizeof(LogData); - CopyData.lpData = &Data; - SendMessage(g_ChildWnd, WM_COPYDATA, reinterpret_cast(hWndDlg), reinterpret_cast(&CopyData)); + // Sync updated log to kernel process to use run-time settings. + g_EmuShared->SetLogLv(&LogLevel); + g_EmuShared->SetLogModules(LoggedModules); + SendMessage(g_ChildWnd, WM_COMMAND, MAKEWPARAM(ID_SYNC_CONFIG_LOGGING, 0), 0); } } PostMessage(hWndDlg, WM_COMMAND, IDC_LOG_CANCEL, 0); diff --git a/src/Cxbx/ResCxbx.h b/src/Cxbx/ResCxbx.h index a10cb47ca..510be5240 100644 --- a/src/Cxbx/ResCxbx.h +++ b/src/Cxbx/ResCxbx.h @@ -351,6 +351,7 @@ #define ID_SETTINGS_CONFIG_DLOCCURDIR 40106 #define ID_SETTINGS_ALLOWADMINPRIVILEGE 40107 #define ID_SETTINGS_CONFIG_LOGGING 40108 +#define ID_SYNC_CONFIG_LOGGING 40109 #define IDC_STATIC -1 // Next default values for new objects @@ -358,7 +359,7 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 135 -#define _APS_NEXT_COMMAND_VALUE 40108 +#define _APS_NEXT_COMMAND_VALUE 40110 #define _APS_NEXT_CONTROL_VALUE 1256 #define _APS_NEXT_SYMED_VALUE 104 #endif diff --git a/src/Cxbx/WinMain.cpp b/src/Cxbx/WinMain.cpp index 8b0532060..31c53e85a 100644 --- a/src/Cxbx/WinMain.cpp +++ b/src/Cxbx/WinMain.cpp @@ -122,18 +122,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine return EXIT_FAILURE; } - if (!bKernel) { - // Set up the logging variables for the GUI process - g_CurrentLogLevel = g_Settings->m_core.LogLevel; - for (int index = to_underlying(CXBXR_MODULE::CXBXR); index < to_underlying(CXBXR_MODULE::MAX); index++) { - if (g_Settings->m_core.LoggedModules[index / 32] & (1 << (index % 32))) { - g_EnabledModules[index] = true; - } - else { - g_EnabledModules[index] = false; - } - } - } + get_log_settings(); bool bElevated = CxbxIsElevated(); @@ -194,6 +183,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine EmuShared::Cleanup(); return EXIT_FAILURE; } + + get_log_settings(); } INITCOMMONCONTROLSEX icc; diff --git a/src/CxbxKrnl/CxbxKrnl.cpp b/src/CxbxKrnl/CxbxKrnl.cpp index b02784f88..fadce290f 100644 --- a/src/CxbxKrnl/CxbxKrnl.cpp +++ b/src/CxbxKrnl/CxbxKrnl.cpp @@ -927,17 +927,8 @@ void CxbxKrnlMain(int argc, char* argv[]) g_EmuShared->GetLogLv(&LogLevel); g_EmuShared->GetLogModules(LoggedModules); - // Set up the logging variables for the kernel process during initialization. Note that we cannot use WM_COPYDATA here - // because the child window doesn't exist yet at this point - g_CurrentLogLevel = LogLevel; - for (int index = to_underlying(CXBXR_MODULE::CXBXR); index < to_underlying(CXBXR_MODULE::MAX); index++) { - if (LoggedModules[index / 32] & (1 << (index % 32))) { - g_EnabledModules[index] = true; - } - else { - g_EnabledModules[index] = false; - } - } + // Set up the logging variables for the kernel process during initialization. + set_log_config(LogLevel, LoggedModules); } if (CxbxKrnl_hEmuParent != NULL) { diff --git a/src/CxbxKrnl/EmuD3D8.cpp b/src/CxbxKrnl/EmuD3D8.cpp index ab47e2229..633bbc038 100644 --- a/src/CxbxKrnl/EmuD3D8.cpp +++ b/src/CxbxKrnl/EmuD3D8.cpp @@ -1587,28 +1587,14 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar } break; - case WM_COPYDATA: + case WM_COMMAND: { - COPYDATASTRUCT* pCopyData = reinterpret_cast(lParam); - switch (pCopyData->dwData) + switch (LOWORD(wParam)) { - case LOG_ID: + case ID_SYNC_CONFIG_LOGGING: { - if (pCopyData->cbData == sizeof(LogData)) { - LogData Data = *reinterpret_cast(pCopyData->lpData); - g_CurrentLogLevel = Data.Level; - for (int index = to_underlying(CXBXR_MODULE::CXBXR); index < to_underlying(CXBXR_MODULE::MAX); index++) { - if (Data.LoggedModules[index / 32] & (1 << (index % 32))) { - g_EnabledModules[index] = true; - } - else { - g_EnabledModules[index] = false; - } - } - } - else { - EmuLog(CXBXR_MODULE::GUI, LOG_LEVEL::WARNING, "COPYDATASTRUCT with id LOG_ID with abnormal size %zu", pCopyData->cbData); - } + // Sync run-time config log settings from GUI process. + sync_log_config(); } break; diff --git a/src/CxbxKrnl/EmuShared.h b/src/CxbxKrnl/EmuShared.h index 8455fc64d..6a9930eb5 100644 --- a/src/CxbxKrnl/EmuShared.h +++ b/src/CxbxKrnl/EmuShared.h @@ -55,13 +55,6 @@ enum { BOOT_SKIP_ANIMATION = 1 << 2, BOOT_RUN_DASHBOARD = 1 << 3, BOOT_QUICK_REBOOT = 1 << 4, -}; - -// Log variables used by WM_COPYDATA -#define LOG_ID 1 -struct LogData { - int Level; - uint LoggedModules[NUM_INTEGERS_LOG]; }; // ******************************************************************