Fixes and tuneup

* Reduce duplicate methods perform same task into one simple function.
* Use EmuShared to obtain updated log settings instead of WM_COPYDATA message.
* FIXED: Set log config for second GUI process
* FIXED: Proper update logging config to EmuShared instead of repeatly send when it is indeed in use.
  * Without this fix, it will affect other GUI process emulating a title.
This commit is contained in:
RadWolfie 2018-08-15 18:49:42 -05:00
parent 54f95fc33b
commit 8c31d5e24e
8 changed files with 55 additions and 75 deletions

View File

@ -36,7 +36,9 @@
#include <windows.h> // 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)
{

View File

@ -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__

View File

@ -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<WPARAM>(hWndDlg), reinterpret_cast<LPARAM>(&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);

View File

@ -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

View File

@ -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;

View File

@ -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) {

View File

@ -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<COPYDATASTRUCT*>(lParam);
switch (pCopyData->dwData)
switch (LOWORD(wParam))
{
case LOG_ID:
case ID_SYNC_CONFIG_LOGGING:
{
if (pCopyData->cbData == sizeof(LogData)) {
LogData Data = *reinterpret_cast<LogData*>(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;

View File

@ -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];
};
// ******************************************************************