Skip to content

Commit

Permalink
Move logging logic into a seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jan 24, 2022
1 parent ffd4c4f commit 2db7bef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
36 changes: 36 additions & 0 deletions source/logger.c
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions source/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ extern "C" {

#endif

void initLogging();

void deinitLogging();

#ifdef __cplusplus
}
#endif
Expand Down
33 changes: 3 additions & 30 deletions source/main.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 2db7bef

Please sign in to comment.