Convert ddio to use new logging facility

This commit is contained in:
Azamat H. Hackimov 2024-08-20 01:27:03 +03:00
parent 76d0711aa3
commit a16420789d
6 changed files with 41 additions and 37 deletions

View File

@ -25,6 +25,7 @@ set(CPPS
add_library(ddio STATIC ${HEADERS} ${CPPS})
target_link_libraries(ddio PRIVATE
SDL2::SDL2
plog::plog
ddebug
mem
misc

View File

@ -87,10 +87,14 @@
*
* $NoKeywords: $
*/
#include <cstdlib>
#include "ddio.h"
#include "joystick.h"
#include "log.h"
#include "pserror.h"
#include <stdlib.h>
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;
}
}

View File

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

View File

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

View File

@ -70,11 +70,10 @@
#include <cstring>
#include <SDL.h>
#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;
}

View File

@ -142,15 +142,16 @@
* $NoKeywords: $
*/
#include "ddio.h"
#include "pserror.h"
#include "mem.h"
#include <stdarg.h>
#include <cstdarg>
#include <cstdio>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#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;
}