Move logging logic into a seperate file

This commit is contained in:
Maschell 2022-01-24 18:52:59 +01:00
parent ffd4c4f894
commit 2db7befb4b
3 changed files with 43 additions and 30 deletions

36
source/logger.c Normal file
View File

@ -0,0 +1,36 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
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
}

View File

@ -32,6 +32,10 @@ extern "C" {
#endif
void initLogging();
void deinitLogging();
#ifdef __cplusplus
}
#endif

View File

@ -1,46 +1,19 @@
#include <wums.h>
#ifdef DEBUG
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#endif // DEBUG
#include "logger.h"
#include "function_patcher.h"
WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher");
WUMS_MODULE_SKIP_INIT_FINI();
#ifdef DEBUG
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif
WUMS_APPLICATION_STARTS() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
initLogging();
FunctionPatcherResetLibHandles();
}
WUMS_APPLICATION_REQUESTS_EXIT() {
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
deinitLogging();
}
WUMS_EXPORT_FUNCTION(FunctionPatcherPatchFunction);