whb: Separate log dispatching into a separate inline function

This commit is contained in:
CreeperMario 2017-10-10 09:43:59 +10:30
parent 758e91f65f
commit 240514eff2

View File

@ -10,6 +10,17 @@
static LogHandlerFn static LogHandlerFn
sHandlers[MAX_HANDLERS] = { 0 }; sHandlers[MAX_HANDLERS] = { 0 };
static inline void
dispatchMessage(const char * str)
{
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](str);
}
}
}
BOOL BOOL
WHBAddLogHandler(LogHandlerFn fn) WHBAddLogHandler(LogHandlerFn fn)
{ {
@ -43,14 +54,7 @@ WHBRemoveLogHandler(LogHandlerFn fn)
BOOL BOOL
WHBLogWrite(const char *str) WHBLogWrite(const char *str)
{ {
int i; dispatchMessage(str);
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](str);
}
}
return TRUE; return TRUE;
} }
@ -63,13 +67,7 @@ WHBLogPrint(const char *str)
} }
snprintf(buf, PRINTF_BUFFER_LENGTH, "%s\n", str); snprintf(buf, PRINTF_BUFFER_LENGTH, "%s\n", str);
dispatchMessage(buf);
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](buf);
}
}
MEMFreeToDefaultHeap(buf); MEMFreeToDefaultHeap(buf);
return TRUE; return TRUE;
@ -87,13 +85,7 @@ WHBLogWritef(const char *fmt, ...)
va_start(va, fmt); va_start(va, fmt);
vsnprintf(buf, PRINTF_BUFFER_LENGTH, fmt, va); vsnprintf(buf, PRINTF_BUFFER_LENGTH, fmt, va);
dispatchMessage(buf);
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](buf);
}
}
MEMFreeToDefaultHeap(buf); MEMFreeToDefaultHeap(buf);
va_end(va); va_end(va);
@ -120,13 +112,7 @@ WHBLogPrintf(const char *fmt, ...)
vsnprintf(buf1, PRINTF_BUFFER_LENGTH, fmt, va); vsnprintf(buf1, PRINTF_BUFFER_LENGTH, fmt, va);
snprintf(buf2, PRINTF_BUFFER_LENGTH, "%s\n", buf1); snprintf(buf2, PRINTF_BUFFER_LENGTH, "%s\n", buf1);
dispatchMessage(buf2);
int i;
for (i = 0; i < MAX_HANDLERS; ++i) {
if (sHandlers[i]) {
sHandlers[i](buf2);
}
}
MEMFreeToDefaultHeap(buf1); MEMFreeToDefaultHeap(buf1);
MEMFreeToDefaultHeap(buf2); MEMFreeToDefaultHeap(buf2);