Log via WHB

This commit is contained in:
Maschell 2020-07-05 13:49:31 +02:00
parent d3097d15de
commit 04d775fbdb
4 changed files with 32 additions and 133 deletions

View File

@ -52,22 +52,22 @@ Application::Application()
}
Application::~Application() {
log_printf("Destroy music\n");
DEBUG_FUNCTION_LINE("Destroy music");
delete bgMusic;
log_printf("Destroy controller\n");
DEBUG_FUNCTION_LINE("Destroy controller");
for (int i = 0; i < 5; i++)
delete controller[i];
log_printf("Destroy async deleter\n");
AsyncDeleter::destroyInstance();
DEBUG_FUNCTION_LINE("Destroy async deleter");
log_printf("Clear resources\n");
DEBUG_FUNCTION_LINE("Clear resources");
Resources::Clear();
log_printf("Stop sound handler\n");
DEBUG_FUNCTION_LINE("Stop sound handler");
SoundHandler::DestroyInstance();
ProcUIShutdown();
@ -139,27 +139,27 @@ bool Application::procUI(void) {
switch (ProcUIProcessMessages(true)) {
case PROCUI_STATUS_EXITING: {
log_printf("PROCUI_STATUS_EXITING\n");
DEBUG_FUNCTION_LINE("PROCUI_STATUS_EXITING");
exitCode = EXIT_SUCCESS;
exitApplication = true;
break;
}
case PROCUI_STATUS_RELEASE_FOREGROUND: {
log_printf("PROCUI_STATUS_RELEASE_FOREGROUND\n");
DEBUG_FUNCTION_LINE("PROCUI_STATUS_RELEASE_FOREGROUND");
if (video != NULL) {
// we can turn of the screen but we don't need to and it will display the last image
video->tvEnable(true);
video->drcEnable(true);
log_printf("delete fontSystem\n");
DEBUG_FUNCTION_LINE("delete fontSystem");
delete fontSystem;
fontSystem = NULL;
log_printf("delete video\n");
DEBUG_FUNCTION_LINE("delete video");
delete video;
video = NULL;
log_printf("deinitialze memory\n");
DEBUG_FUNCTION_LINE("deinitialze memory");
memoryRelease();
ProcUIDrawDoneRelease();
} else {
@ -170,21 +170,21 @@ bool Application::procUI(void) {
case PROCUI_STATUS_IN_FOREGROUND: {
if (!quitRequest) {
if (video == NULL) {
log_printf("PROCUI_STATUS_IN_FOREGROUND\n");
log_printf("initialze memory\n");
DEBUG_FUNCTION_LINE("PROCUI_STATUS_IN_FOREGROUND");
DEBUG_FUNCTION_LINE("initialze memory");
memoryInitialize();
log_printf("Initialize video\n");
DEBUG_FUNCTION_LINE("Initialize video");
video = new CVideo(GX2_TV_SCAN_MODE_720P, GX2_DRC_RENDER_MODE_SINGLE);
log_printf("Video size %i x %i\n", video->getTvWidth(), video->getTvHeight());
DEBUG_FUNCTION_LINE("Video size %i x %i", video->getTvWidth(), video->getTvHeight());
//! setup default Font
log_printf("Initialize main font system\n");
DEBUG_FUNCTION_LINE("Initialize main font system");
FreeTypeGX *fontSystem = new FreeTypeGX(Resources::GetFile("font.ttf"), Resources::GetFileSize("font.ttf"), true);
GuiText::setPresetFont(fontSystem);
if (mainWindow == NULL) {
log_printf("Initialize main window\n");
DEBUG_FUNCTION_LINE("Initialize main window");
mainWindow = new MainWindow(video->getTvWidth(), video->getTvHeight());
}
@ -202,7 +202,7 @@ bool Application::procUI(void) {
}
void Application::executeThread(void) {
log_printf("Entering main loop\n");
DEBUG_FUNCTION_LINE("Entering main loop");
//! main GX2 loop (60 Hz cycle with max priority on core 1)
while (!exitApplication) {
@ -252,18 +252,18 @@ void Application::executeThread(void) {
fadeOut();
}
log_printf("delete mainWindow\n");
DEBUG_FUNCTION_LINE("delete mainWindow");
delete mainWindow;
mainWindow = NULL;
log_printf("delete fontSystem\n");
DEBUG_FUNCTION_LINE("delete fontSystem");
delete fontSystem;
fontSystem = NULL;
log_printf("delete video\n");
DEBUG_FUNCTION_LINE("delete video");
delete video;
video = NULL;
log_printf("deinitialze memory\n");
DEBUG_FUNCTION_LINE("deinitialze memory");
memoryRelease();
}

View File

@ -4,26 +4,21 @@
#include "system/memory.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include <whb/log_udp.h>
/* Entry point */
extern "C" int Menu_Main(void) {
//!*******************************************************************
//! Initialize function pointers *
//!*******************************************************************
socket_lib_init();
//! do OS (for acquire) and sockets first so we got logging
log_init();
WHBLogUdpInit();
log_print("Initialize memory management\n");
DEBUG_FUNCTION_LINE("Initialize memory management");
memoryInitialize();
//!*******************************************************************
//! Initialize heap memory *
//!*******************************************************************
log_printf("Start main application\n");
DEBUG_FUNCTION_LINE("Start main application");
Application::instance()->exec();
Application::destroyInstance();
return 0;

View File

@ -1,82 +0,0 @@
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <utils/logger.h>
#include <nsysnet/socket.h>
#include <coreinit/debug.h>
#include <coreinit/systeminfo.h>
#include <coreinit/thread.h>
static int log_socket __attribute__((section(".data"))) = -1;
static struct sockaddr_in connect_addr __attribute__((section(".data")));
static volatile int log_lock __attribute__((section(".data"))) = 0;
void log_init_() {
int broadcastEnable = 1;
log_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (log_socket < 0)
return;
setsockopt(log_socket, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
memset(&connect_addr, 0, sizeof(struct sockaddr_in));
connect_addr.sin_family = AF_INET;
connect_addr.sin_port = 4405;
connect_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
}
void log_print_(const char *str) {
// socket is always 0 initially as it is in the BSS
if (log_socket < 0) {
return;
}
while (log_lock)
OSSleepTicks(OSMicrosecondsToTicks(1000));
log_lock = 1;
int len = strlen(str);
int ret;
while (len > 0) {
int block = len < 1400 ? len : 1400; // take max 1400 bytes per UDP packet
ret = sendto(log_socket, str, block, 0, (struct sockaddr *) &connect_addr, sizeof(struct sockaddr_in));
if (ret < 0)
break;
len -= ret;
str += ret;
}
log_lock = 0;
}
void OSFatal_printf(const char *format, ...) {
char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) {
OSFatal(tmp);
}
va_end(va);
}
void log_printf_(const char *format, ...) {
if (log_socket < 0) {
return;
}
char tmp[512];
tmp[0] = 0;
va_list va;
va_start(va, format);
if ((vsprintf(tmp, format, va) >= 0)) {
log_print_(tmp);
}
va_end(va);
}

View File

@ -1,20 +1,11 @@
#ifndef __LOGGER_H_
#define __LOGGER_H_
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
void log_init_();
//void log_deinit_(void);
void log_print_(const char *str);
void log_printf_(const char *format, ...);
void OSFatal_printf(const char *format, ...);
#include <whb/log.h>
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
@ -23,19 +14,14 @@ void OSFatal_printf(const char *format, ...);
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#define log_init() log_init_()
//#define log_deinit() log_deinit_()
#define log_print(str) log_print_(str)
#define log_printf(FMT, ARGS...) log_printf_(FMT, ## ARGS);
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
#ifdef __cplusplus
}
#endif
#endif