From: Juho Vähä-Herttua Date: Thu, 31 May 2012 17:54:42 +0000 (+0300) Subject: Add cls pointer to the logger X-Git-Tag: upstream/0.9.0~4^2~58 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2975b4b88d0103dcc1ac84202bcfc221671e6743;p=deb_shairplay.git Add cls pointer to the logger --- diff --git a/src/include/raop.h b/src/include/raop.h index 5d5dc08..7328348 100644 --- a/src/include/raop.h +++ b/src/include/raop.h @@ -25,7 +25,7 @@ extern "C" { typedef struct raop_s raop_t; -typedef void (*raop_log_callback_t)(int level, const char *msg); +typedef void (*raop_log_callback_t)(void *cls, int level, const char *msg); struct raop_callbacks_s { void* cls; @@ -47,7 +47,7 @@ RAOP_API raop_t *raop_init(int max_clients, raop_callbacks_t *callbacks, const c RAOP_API raop_t *raop_init_from_keyfile(int max_clients, raop_callbacks_t *callbacks, const char *keyfile); RAOP_API void raop_set_log_level(raop_t *raop, int level); -RAOP_API void raop_set_log_callback(raop_t *raop, raop_log_callback_t callback); +RAOP_API void raop_set_log_callback(raop_t *raop, raop_log_callback_t callback, void *cls); RAOP_API int raop_start(raop_t *raop, unsigned short *port, const char *hwaddr, int hwaddrlen, const char *password); RAOP_API int raop_is_running(raop_t *raop); diff --git a/src/lib/logger.c b/src/lib/logger.c index dcda600..f3fe354 100644 --- a/src/lib/logger.c +++ b/src/lib/logger.c @@ -25,6 +25,7 @@ struct logger_s { mutex_handle_t cb_mutex; int level; + void *cls; logger_callback_t callback; }; @@ -61,11 +62,12 @@ logger_set_level(logger_t *logger, int level) } void -logger_set_callback(logger_t *logger, logger_callback_t callback) +logger_set_callback(logger_t *logger, logger_callback_t callback, void *cls) { assert(logger); MUTEX_LOCK(logger->cb_mutex); + logger->cls = cls; logger->callback = callback; MUTEX_UNLOCK(logger->cb_mutex); } @@ -120,7 +122,7 @@ logger_log(logger_t *logger, int level, const char *fmt, ...) MUTEX_LOCK(logger->cb_mutex); if (logger->callback) { - logger->callback(level, buffer); + logger->callback(logger->cls, level, buffer); MUTEX_UNLOCK(logger->cb_mutex); } else { char *local; diff --git a/src/lib/logger.h b/src/lib/logger.h index 45e8b59..9a81358 100644 --- a/src/lib/logger.h +++ b/src/lib/logger.h @@ -25,7 +25,7 @@ #define LOGGER_INFO 6 /* informational */ #define LOGGER_DEBUG 7 /* debug-level messages */ -typedef void (*logger_callback_t)(int level, const char *msg); +typedef void (*logger_callback_t)(void *cls, int level, const char *msg); typedef struct logger_s logger_t; @@ -33,7 +33,7 @@ logger_t *logger_init(); void logger_destroy(logger_t *logger); void logger_set_level(logger_t *logger, int level); -void logger_set_callback(logger_t *logger, logger_callback_t callback); +void logger_set_callback(logger_t *logger, logger_callback_t callback, void *cls); void logger_log(logger_t *logger, int level, const char *fmt, ...); diff --git a/src/lib/raop.c b/src/lib/raop.c index fd02edf..4f4f518 100644 --- a/src/lib/raop.c +++ b/src/lib/raop.c @@ -460,11 +460,11 @@ raop_set_log_level(raop_t *raop, int level) } void -raop_set_log_callback(raop_t *raop, raop_log_callback_t callback) +raop_set_log_callback(raop_t *raop, raop_log_callback_t callback, void *cls) { assert(raop); - logger_set_callback(raop->logger, callback); + logger_set_callback(raop->logger, callback, cls); } int diff --git a/src/test/example.c b/src/test/example.c index fdd9704..e857642 100644 --- a/src/test/example.c +++ b/src/test/example.c @@ -67,7 +67,7 @@ audio_destroy(void *cls, void *session) } static void -raop_log_callback(int level, const char *msg) +raop_log_callback(void *cls, int level, const char *msg) { printf("RAOP LOG(%d): %s\n", level, msg); } @@ -94,7 +94,7 @@ main(int argc, char *argv[]) raop = raop_init_from_keyfile(10, &raop_cbs, "airport.key"); raop_set_log_level(raop, RAOP_LOG_DEBUG); - raop_set_log_callback(raop, &raop_log_callback); + raop_set_log_callback(raop, &raop_log_callback, NULL); raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr), "test"); dnssd = dnssd_init(NULL);