From 8f3d0dc8cdf605351de41344641c76be095fad6d Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 26 Jan 2022 13:42:15 +0100 Subject: [PATCH] Move logging into a separate file --- source/logger.c | 36 ++++++++++++++++++++++++++++++++++++ source/logger.h | 4 ++++ source/main.cpp | 32 ++------------------------------ 3 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 source/logger.c diff --git a/source/logger.c b/source/logger.c new file mode 100644 index 0000000..0411db7 --- /dev/null +++ b/source/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/source/logger.h b/source/logger.h index 94c763b..6ff5ae2 100644 --- a/source/logger.h +++ b/source/logger.h @@ -32,6 +32,10 @@ extern "C" { #endif +void initLogging(); + +void deinitLogging(); + #ifdef __cplusplus } #endif diff --git a/source/main.cpp b/source/main.cpp index 30874fb..36472cf 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,11 +1,5 @@ #include -#ifdef DEBUG -#include -#include -#include -#endif // DEBUG - #include #include #include @@ -19,10 +13,6 @@ WUMS_MODULE_SKIP_INIT_FINI(); bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, RelocationType reloc_type); -uint32_t moduleLogInit = false; -uint32_t cafeLogInit = false; -uint32_t udpLogInit = false; - WUMS_RELOCATIONS_DONE(args) { module_information_t *gModuleData = args.module_information; if (args.module_information == nullptr) { @@ -32,12 +22,7 @@ WUMS_RELOCATIONS_DONE(args) { OSFatal("PatchMemoryRelocations: The module information struct version does not match."); } -#ifdef DEBUG - if (!(moduleLogInit = WHBLogModuleInit())) { - cafeLogInit = WHBLogCafeInit(); - udpLogInit = WHBLogUdpInit(); - } -#endif // DEBUG + initLogging(); for (int32_t i = 0; i < gModuleData->number_used_modules; i++) { if (strcmp("homebrew_memorymapping", gModuleData->module_data[i].module_export_name) == 0 || @@ -69,20 +54,7 @@ WUMS_RELOCATIONS_DONE(args) { } } } -#ifdef DEBUG - if (moduleLogInit) { - WHBLogModuleDeinit(); - moduleLogInit = false; - } - if (cafeLogInit) { - WHBLogCafeDeinit(); - cafeLogInit = false; - } - if (udpLogInit) { - WHBLogUdpDeinit(); - udpLogInit = false; - } -#endif // DEBUG + deinitLogging(); } #define R_PPC_NONE 0