tsm: add tsm_log_t llog-compatible log object

We need to avoid logging to stderr directly in TSM so introduce the
tsm_log_t object similar to eloop.h.

Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
David Herrmann 2012-09-18 15:01:45 +02:00
parent 613e7e7000
commit e638e6f039
3 changed files with 28 additions and 4 deletions

View File

@ -421,7 +421,7 @@ int kmscon_terminal_new(struct kmscon_terminal **out,
term->fps = 1000000000ULL / fps;
log_debug("FPS: %lu TIMER: %lu", term->fps, fps);
ret = tsm_screen_new(&term->console);
ret = tsm_screen_new(&term->console, log_llog);
if (ret)
goto err_free;
tsm_screen_set_max_sb(term->console, kmscon_conf.sb_size);

View File

@ -37,6 +37,7 @@
#include <string.h>
#include "log.h"
#include "main.h"
#include "shl_llog.h"
#include "shl_timer.h"
#include "tsm_screen.h"
#include "tsm_unicode.h"
@ -58,6 +59,7 @@ struct line {
struct tsm_screen {
size_t ref;
llog_submit_t llog;
unsigned int flags;
struct shl_timer *timer;
@ -385,7 +387,7 @@ static inline unsigned int to_abs_y(struct tsm_screen *con, unsigned int y)
return con->margin_top + y;
}
int tsm_screen_new(struct tsm_screen **out)
int tsm_screen_new(struct tsm_screen **out, tsm_log_t log)
{
struct tsm_screen *con;
int ret;
@ -400,6 +402,7 @@ int tsm_screen_new(struct tsm_screen **out)
memset(con, 0, sizeof(*con));
con->ref = 1;
con->llog = log;
con->def_attr.fr = 255;
con->def_attr.fg = 255;
con->def_attr.fb = 255;

View File

@ -39,9 +39,30 @@
#include <stdlib.h>
#include "tsm_unicode.h"
/* screen objects */
struct tsm_screen;
/* screen objects */
/**
* tsm_log_t:
* @file: Source code file where the log message originated or NULL
* @line: Line number in source code or 0
* @func: C function name or NULL
* @subs: Subsystem where the message came from or NULL
* @sev: Kernel-style severity between 0=FATAL and 7=DEBUG
* @format: printf-formatted message
* @args: arguments for printf-style @format
*
* This is the type of a logging callback function. You can always pass NULL
* instead of such a function to disable logging.
*/
typedef void (*tsm_log_t) (const char *file,
int line,
const char *func,
const char *subs,
unsigned int sev,
const char *format,
va_list args);
#define TSM_SCREEN_INSERT_MODE 0x01
#define TSM_SCREEN_AUTO_WRAP 0x02
@ -78,7 +99,7 @@ typedef int (*tsm_screen_draw_cb) (struct tsm_screen *con,
typedef int (*tsm_screen_render_cb) (struct tsm_screen *con,
void *data);
int tsm_screen_new(struct tsm_screen **out);
int tsm_screen_new(struct tsm_screen **out, tsm_log_t log);
void tsm_screen_ref(struct tsm_screen *con);
void tsm_screen_unref(struct tsm_screen *con);