mirror of
https://github.com/tuxbox-neutrino/libstb-hal.git
synced 2025-08-27 07:23:11 +02:00
libtriple: improve debug architecture
every libtriple module can have its debug output enabled separately by exporting the TRIPLE_DEBUG variable
This commit is contained in:
@@ -2,17 +2,74 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int cnxt_debug = 0;
|
||||
int cnxt_debug = 0; /* compat, unused */
|
||||
|
||||
void lt_debug(const char *fmt, ...)
|
||||
int debuglevel = -1;
|
||||
|
||||
static const char* lt_facility[] = {
|
||||
"audio ",
|
||||
"video ",
|
||||
"demux ",
|
||||
"record",
|
||||
"play ",
|
||||
"power ",
|
||||
"init ",
|
||||
"ca ",
|
||||
NULL
|
||||
};
|
||||
|
||||
void _lt_info(int facility, const char *fmt, ...)
|
||||
{
|
||||
if (! cnxt_debug)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "[libtriple:%s] ", lt_facility[facility]);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
void _lt_debug(int facility, const char *fmt, ...)
|
||||
{
|
||||
if (debuglevel < 0)
|
||||
fprintf(stderr, "lt_debug: debuglevel not initialized!\n");
|
||||
|
||||
if (! ((1 << facility) & debuglevel))
|
||||
return;
|
||||
|
||||
fprintf(stderr, "[libtriple:%s] ", lt_facility[facility]);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void lt_debug_init(void)
|
||||
{
|
||||
int i = 0;
|
||||
char *tmp = getenv("TRIPLE_DEBUG");
|
||||
if (! tmp)
|
||||
debuglevel = 0;
|
||||
else
|
||||
debuglevel = (int) strtol(tmp, NULL, 0);
|
||||
|
||||
if (debuglevel == 0)
|
||||
{
|
||||
fprintf(stderr, "libtriple debug options can be set by exporting TRIPLE_DEBUG.\n");
|
||||
fprintf(stderr, "The following values (or bitwise OR combinations) are valid:\n");
|
||||
while (lt_facility[i]) {
|
||||
fprintf(stderr, "\tcomponent: %s 0x%02x\n", lt_facility[i], 1 << i);
|
||||
i++;
|
||||
}
|
||||
fprintf(stderr, "\tall components: 0x%02x\n", (1 << i) - 1);
|
||||
} else {
|
||||
fprintf(stderr, "libtriple debug is active for the following components:\n");
|
||||
while (lt_facility[i]) {
|
||||
if (debuglevel & (1 << i))
|
||||
fprintf(stderr, "%s ", lt_facility[i]);
|
||||
i++;
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user