From a16420789dcf353dc85458ac4643515780a3240d Mon Sep 17 00:00:00 2001 From: "Azamat H. Hackimov" Date: Tue, 20 Aug 2024 01:27:03 +0300 Subject: [PATCH] Convert ddio to use new logging facility --- ddio/CMakeLists.txt | 1 + ddio/ddio.cpp | 10 +++++++--- ddio/lnxfile.cpp | 9 ++++----- ddio/lnxio.cpp | 28 ++++++++++++++-------------- ddio/sdljoy.cpp | 11 +++++------ ddio/winfile.cpp | 19 ++++++++++--------- 6 files changed, 41 insertions(+), 37 deletions(-) diff --git a/ddio/CMakeLists.txt b/ddio/CMakeLists.txt index 1b960946..bb79eee2 100644 --- a/ddio/CMakeLists.txt +++ b/ddio/CMakeLists.txt @@ -25,6 +25,7 @@ set(CPPS add_library(ddio STATIC ${HEADERS} ${CPPS}) target_link_libraries(ddio PRIVATE SDL2::SDL2 + plog::plog ddebug mem misc diff --git a/ddio/ddio.cpp b/ddio/ddio.cpp index 50dd7625..67081568 100644 --- a/ddio/ddio.cpp +++ b/ddio/ddio.cpp @@ -87,10 +87,14 @@ * * $NoKeywords: $ */ + +#include + #include "ddio.h" #include "joystick.h" +#include "log.h" #include "pserror.h" -#include + static bool DDIO_initialized = false; // ---------------------------------------------------------------------------- // Common initialization @@ -103,7 +107,7 @@ bool ddio_Init(ddio_init_info *init_info) { if (first_time) { atexit(ddio_Close); } - mprintf(0, "DDIO system initializing...\n"); + LOG_DEBUG << "DDIO system initializing..."; res = ddio_InternalInit(init_info); if (res) { if (first_time) { // initialize once and only once. @@ -124,7 +128,7 @@ void ddio_Close() { ddio_MouseClose(); ddio_KeyClose(); ddio_InternalClose(); - mprintf(0, "DDIO system closed.\n"); + LOG_DEBUG << "DDIO system closed."; DDIO_initialized = false; } } diff --git a/ddio/lnxfile.cpp b/ddio/lnxfile.cpp index e936b490..7f07ec3d 100644 --- a/ddio/lnxfile.cpp +++ b/ddio/lnxfile.cpp @@ -73,6 +73,7 @@ #endif #include "ddio.h" +#include "log.h" #include "crossplat.h" #include "mem.h" #include "pserror.h" @@ -111,7 +112,7 @@ int ddio_GetFileLength(FILE *filePtr) { fstat(filedes, &info); size = info.st_size; } else { - mprintf(0, "Tried getting length of NULL fileptr!\n"); + LOG_FATAL << "Tried getting length of NULL fileptr!"; Int3(); } return size; @@ -477,10 +478,8 @@ bool ddio_GetTempFileName(const char *basedir, const char *prefix, char *filenam bool ddio_CheckProcess(int pid) { if (kill(pid, 0) == -1) { - if (errno != ESRCH) { - /* some other error, log it */ - mprintf(0, "Error sending signal to PID for lock check (%d)\n", pid); - } + /* some other error, log it */ + LOG_WARNING_IF(errno != ESRCH).printf("Error sending signal to PID for lock check (%d)", pid); return false; } else { /* process exists */ diff --git a/ddio/lnxio.cpp b/ddio/lnxio.cpp index 89e643f9..c96173b2 100644 --- a/ddio/lnxio.cpp +++ b/ddio/lnxio.cpp @@ -68,7 +68,7 @@ #include "application.h" #include "ddio.h" -#include "pserror.h" +#include "log.h" bool DDIO_init = false; oeLnxApplication *Lnx_app_obj = NULL; @@ -78,21 +78,21 @@ oeLnxApplication *Lnx_app_obj = NULL; // ---------------------------------------------------------------------------- bool ddio_InternalInit(ddio_init_info *init_info) { - mprintf(0, "DDIO: ddio_InternalInit() called."); + LOG_DEBUG << "DDIO: ddio_InternalInit() called."; Lnx_app_obj = (oeLnxApplication *)init_info->obj; DDIO_init = true; return true; } void ddio_InternalClose() { - mprintf(0, "DDIO: ddio_InternalClose() called."); + LOG_DEBUG << "DDIO: ddio_InternalClose() called."; if (DDIO_init) { DDIO_init = false; Lnx_app_obj = NULL; } // if - mprintf(0, "DDIO: ddio_InternalClose() returning."); + LOG_DEBUG << "DDIO: ddio_InternalClose() returning."; } void ddio_DebugMessage(unsigned err, char *fmt, ...) { @@ -103,20 +103,20 @@ void ddio_DebugMessage(unsigned err, char *fmt, ...) { std::vsnprintf(buf, sizeof(buf), fmt, arglist); va_end(arglist); - mprintf(0, "%s\n", buf); + LOG_DEBUG << buf; } bool ddio_GetBinaryPath(char *exec_path, size_t len) { #ifdef MACOSX if (exec_path == NULL || len == 0) { - fprintf(stderr, "Invalid arguments\n"); - return false; + LOG_ERROR << "Invalid arguments"; + return false; } uint32_t size = (uint32_t)len; if (_NSGetExecutablePath(exec_path, &size) != 0) { - fprintf(stderr, "Buffer too small; need size %u\n", size); - return false; + LOG_ERROR.printf("Buffer too small; need size %u", size); + return false; } #elif defined(__LINUX__) if (realpath("/proc/self/exe", exec_path) == NULL) { @@ -125,14 +125,14 @@ bool ddio_GetBinaryPath(char *exec_path, size_t len) { } #else if (GetModuleFileName(NULL, exec_path, len) == 0) { - DWORD error = GetLastError(); - Error("GetModuleFileName failed!"); - return false; + DWORD error = GetLastError(); + LOG_ERROR << "GetModuleFileName failed!"; + return false; } exec_path[len - 1] = '\0'; return true; #endif - exec_path[len - 1] = '\0'; - return true; + exec_path[len - 1] = '\0'; + return true; } diff --git a/ddio/sdljoy.cpp b/ddio/sdljoy.cpp index 9451a3e6..499163d8 100644 --- a/ddio/sdljoy.cpp +++ b/ddio/sdljoy.cpp @@ -70,11 +70,10 @@ #include #include -#include "joystick.h" -#include "pserror.h" - // rcg06182000 need this for specific joystick stuff. #include "args.h" +#include "joystick.h" +#include "log.h" // --------------------------------------------------------------------------- // globals @@ -199,8 +198,8 @@ static bool joy_InitStick(tJoystick joy, char *server_adr) { } Joysticks[joy].caps = caps; - mprintf(0, "JOYSTICK: Initialized stick named [%s].", caps.name); - mprintf(0, "JOYSTICK: (%d) axes, (%d) hats, and (%d) buttons.", axes, hats, caps.num_btns); + LOG_DEBUG.printf("JOYSTICK: Initialized stick named [%s].", caps.name); + LOG_DEBUG.printf("JOYSTICK: (%d) axes, (%d) hats, and (%d) buttons.", axes, hats, caps.num_btns); } return (Joysticks[joy].handle != NULL); @@ -333,7 +332,7 @@ static int joyGetNumDevs(void) { found = SDL_NumJoysticks(); } - mprintf(0, "Joystick: Found %d joysticks.", found); + LOG_INFO.printf("Joystick: Found %d joysticks.", found); return found; } diff --git a/ddio/winfile.cpp b/ddio/winfile.cpp index aee19d6f..397b9b96 100644 --- a/ddio/winfile.cpp +++ b/ddio/winfile.cpp @@ -142,15 +142,16 @@ * $NoKeywords: $ */ -#include "ddio.h" -#include "pserror.h" -#include "mem.h" -#include +#include +#include #include #include #include -#include -#include + +#include "ddio.h" +#include "log.h" +#include "mem.h" +#include "pserror.h" // --------------------------------------------------------------------------- // File operations @@ -191,7 +192,7 @@ void ddio_SplitPath(const char *srcPath, char *path, char *filename, char *ext) void ddio_CopyFileTime(const std::filesystem::path &dest, const std::filesystem::path &src) { HANDLE desthandle, srchandle; FILETIME a, b, c; - bool first_time = 1; + bool first_time = true; try_again:; @@ -199,7 +200,7 @@ try_again:; srchandle = CreateFile(src.u8string().c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (desthandle == INVALID_HANDLE_VALUE || srchandle == INVALID_HANDLE_VALUE) { - mprintf(0, "Couldn't copy file time for %s! Error=%d\n", dest.u8string().c_str(), GetLastError()); + LOG_WARNING.printf("Couldn't copy file time for %s! Error=%d", dest.u8string().c_str(), GetLastError()); if (desthandle != INVALID_HANDLE_VALUE) CloseHandle(desthandle); @@ -208,7 +209,7 @@ try_again:; CloseHandle(srchandle); if (first_time) { - first_time = 0; + first_time = false; Sleep(500); goto try_again; }