whb: Add ability to remove logging functions

* WHBRemoveLogHandler will look through the "registry" of logging
functions, and will set the entry to NULL if it matches what the user
passes.
* WHBLogUdpDeinit will correctly close the socket and shut down the
socket library in addition to removing its entry in the registry.
This commit is contained in:
CreeperMario 2017-08-20 18:17:07 +09:30
parent ac4ce95f84
commit 20c7dbf2fb
7 changed files with 44 additions and 4 deletions

View File

@ -116,5 +116,6 @@ exit:
WHBUnmountSdCard();
WHBGfxShutdown();
WHBProcShutdown();
WHBLogUdpDeinit();
return result;
}

View File

@ -16,6 +16,9 @@ typedef void (*LogHandlerFn)(const char *msg);
BOOL
WHBAddLogHandler(LogHandlerFn fn);
BOOL
WHBRemoveLogHandler(LogHandlerFn fn);
BOOL
WHBLogWrite(const char *str);

View File

@ -14,6 +14,9 @@ extern "C" {
BOOL
WHBLogCafeInit();
BOOL
WHBLogCafeDeinit();
#ifdef __cplusplus
}
#endif

View File

@ -14,6 +14,9 @@ extern "C" {
BOOL
WHBLogUdpInit();
BOOL
WHBLogUdpDeinit();
#ifdef __cplusplus
}
#endif

View File

@ -25,6 +25,21 @@ WHBAddLogHandler(LogHandlerFn fn)
return FALSE;
}
BOOL
WHBRemoveLogHandler(LogHandlerFn fn)
{
int i;
for(i = 0; i < MAX_HANDLERS; ++i) {
if(sHandlers[i] == fn) {
sHandlers[i] = NULL;
return TRUE;
}
}
return FALSE;
}
BOOL
WHBLogWrite(const char *str)
{

View File

@ -19,6 +19,11 @@ cafeLogHandler(const char * msg)
BOOL
WHBLogCafeInit()
{
WHBAddLogHandler(cafeLogHandler);
return TRUE;
return WHBAddLogHandler(cafeLogHandler);
}
BOOL
WHBLogCafeDeinit()
{
return WHBRemoveLogHandler(cafeLogHandler);
}

View File

@ -42,6 +42,16 @@ WHBLogUdpInit()
sSendAddr.sin_port = htons(SERVER_PORT);
sSendAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST);
WHBAddLogHandler(udpLogHandler);
return TRUE;
return WHBAddLogHandler(udpLogHandler);
}
BOOL
WHBLogUdpDeinit()
{
if(shutdown(sSocket, SHUT_WR) != 0) {
return FALSE;
}
socket_lib_finish();
return WHBRemoveLogHandler(udpLogHandler);
}