diff --git a/Makefile b/Makefile index 186a696..0846b45 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ INCLUDES := src #------------------------------------------------------------------------------- # options for code generation #------------------------------------------------------------------------------- -CFLAGS := -g -Wall -O2 -ffunction-sections \ +CFLAGS := -Wall -O2 -ffunction-sections \ $(MACHDEP) CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ @@ -41,6 +41,11 @@ CXXFLAGS := $(CFLAGS) -std=gnu++17 ASFLAGS := -g $(ARCH) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUPS_ROOT)/share/libwupsbackend.ld -T$(WUMS_ROOT)/share/librpxloader.ld $(WUPSSPECS) +ifeq ($(DEBUG),1) +CXXFLAGS += -DDEBUG -g +CFLAGS += -DDEBUG -g +endif + LIBS := -lwups -lwut -lwupsbackend -lz -lrpxloader #------------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index c2aa5e5..baf93a5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,6 @@ #include +#include "utils/logger.h" #include "utils/TcpReceiver.h" -#include -#include -#include WUPS_PLUGIN_NAME("Wiiload"); WUPS_PLUGIN_DESCRIPTION("Wiiload Server"); @@ -16,10 +14,7 @@ TcpReceiver *thread = nullptr; /* Entry point */ ON_APPLICATION_START() { - if (!WHBLogModuleInit()) { - WHBLogCafeInit(); - WHBLogUdpInit(); - } + initLogging(); DEBUG_FUNCTION_LINE("Start wiiload thread"); thread = new TcpReceiver(4299); } @@ -33,5 +28,8 @@ void stopThread() { ON_APPLICATION_REQUESTS_EXIT() { DEBUG_FUNCTION_LINE("Kill wiiload thread"); + stopThread(); + + deinitLogging(); } \ No newline at end of file diff --git a/src/utils/logger.c b/src/utils/logger.c new file mode 100644 index 0000000..0411db7 --- /dev/null +++ b/src/utils/logger.c @@ -0,0 +1,36 @@ +#ifdef DEBUG +#include +#include +#include +#include + +uint32_t moduleLogInit = false; +uint32_t cafeLogInit = false; +uint32_t udpLogInit = false; +#endif // DEBUG + +void initLogging() { +#ifdef DEBUG + if (!(moduleLogInit = WHBLogModuleInit())) { + cafeLogInit = WHBLogCafeInit(); + udpLogInit = WHBLogUdpInit(); + } +#endif // DEBUG +} + +void deinitLogging() { +#ifdef DEBUG + if (moduleLogInit) { + WHBLogModuleDeinit(); + moduleLogInit = false; + } + if (cafeLogInit) { + WHBLogCafeDeinit(); + cafeLogInit = false; + } + if (udpLogInit) { + WHBLogUdpDeinit(); + udpLogInit = false; + } +#endif // DEBUG +} \ No newline at end of file diff --git a/src/utils/logger.h b/src/utils/logger.h index b760684..6ff5ae2 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,18 +1,18 @@ #pragma once +#include +#include + #ifdef __cplusplus extern "C" { #endif -#include -#include +#ifdef DEBUG #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) -#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \ - OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ - } while (0) +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ @@ -22,6 +22,21 @@ extern "C" { WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ } while (0) +#else + +#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) + +#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0) + +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0) + +#endif + +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } #endif +