From cd793c5ab7689cc8cbc18277375b368060e5acfe Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Fri, 10 Jan 2014 16:25:15 +0100 Subject: Remove log_cb, add ALPM_EVENT_LOG instead When ALPM emits a log message, it still goes through _alpm_log() but instead of calling a specific log callback, it goes as an event. Signed-off-by: Olivier Brunel Signed-off-by: Allan McRae --- lib/libalpm/alpm.h | 37 +++++++++++++++++++++---------------- lib/libalpm/handle.c | 13 ------------- lib/libalpm/handle.h | 1 - lib/libalpm/log.c | 14 +++++++++----- 4 files changed, 30 insertions(+), 35 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 8b0a20cb..4aa092d0 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -261,16 +261,6 @@ typedef struct _alpm_siglist_t { * Logging facilities */ -/** Logging Levels */ -typedef enum _alpm_loglevel_t { - ALPM_LOG_ERROR = 1, - ALPM_LOG_WARNING = (1 << 1), - ALPM_LOG_DEBUG = (1 << 2), - ALPM_LOG_FUNCTION = (1 << 3) -} alpm_loglevel_t; - -typedef void (*alpm_cb_log)(alpm_loglevel_t, const char *, va_list); - int alpm_logaction(alpm_handle_t *handle, const char *prefix, const char *fmt, ...) __attribute__((format(printf, 3, 4))); @@ -345,7 +335,9 @@ typedef enum _alpm_event_type_t { /** Downloading missing keys into keyring. */ ALPM_EVENT_KEY_DOWNLOAD_START, /** Key downloading is finished. */ - ALPM_EVENT_KEY_DOWNLOAD_DONE + ALPM_EVENT_KEY_DOWNLOAD_DONE, + /** A log message was emitted; See alpm_event_log_t for arguments. */ + ALPM_EVENT_LOG } alpm_event_type_t; /** Events. @@ -412,6 +404,24 @@ typedef struct _alpm_event_database_missing_t { const char *dbname; } alpm_event_database_missing_t; +/** Log levels. */ +typedef enum _alpm_loglevel_t { + ALPM_LOG_ERROR = 1, + ALPM_LOG_WARNING = (1 << 1), + ALPM_LOG_DEBUG = (1 << 2), + ALPM_LOG_FUNCTION = (1 << 3) +} alpm_loglevel_t; + +typedef struct _alpm_event_log_t { + /** Type of event. */ + alpm_event_type_t type; + /** Log level. */ + alpm_loglevel_t level; + /** Message. */ + const char *fmt; + va_list args; +} alpm_event_log_t; + /** Event callback. */ typedef void (*alpm_cb_event)(alpm_event_t *); @@ -487,11 +497,6 @@ char *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url); * @{ */ -/** Returns the callback used for logging. */ -alpm_cb_log alpm_option_get_logcb(alpm_handle_t *handle); -/** Sets the callback used for logging. */ -int alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb); - /** Returns the callback used to report download progress. */ alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle); /** Sets the callback used to report download progress. */ diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 1f41f043..0842d51b 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -132,12 +132,6 @@ int _alpm_handle_unlock(alpm_handle_t *handle) } -alpm_cb_log SYMEXPORT alpm_option_get_logcb(alpm_handle_t *handle) -{ - CHECK_HANDLE(handle, return NULL); - return handle->logcb; -} - alpm_cb_download SYMEXPORT alpm_option_get_dlcb(alpm_handle_t *handle) { CHECK_HANDLE(handle, return NULL); @@ -258,13 +252,6 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle) return handle->checkspace; } -int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb) -{ - CHECK_HANDLE(handle, return -1); - handle->logcb = cb; - return 0; -} - int SYMEXPORT alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb) { CHECK_HANDLE(handle, return -1); diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index db42e8ca..27241ea0 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -63,7 +63,6 @@ struct __alpm_handle_t { #endif /* callback functions */ - alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ alpm_cb_totaldl totaldlcb; /* Total download callback function */ alpm_cb_fetch fetchcb; /* Download file callback function */ diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index d232bcc3..aac55e70 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -81,15 +81,19 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix, void _alpm_log(alpm_handle_t *handle, alpm_loglevel_t flag, const char *fmt, ...) { - va_list args; + alpm_event_log_t event = { + .type = ALPM_EVENT_LOG, + .level = flag, + .fmt = fmt + }; - if(handle == NULL || handle->logcb == NULL) { + if(handle == NULL || handle->eventcb == NULL) { return; } - va_start(args, fmt); - handle->logcb(flag, fmt, args); - va_end(args); + va_start(event.args, fmt); + EVENT(handle, &event); + va_end(event.args); } /* vim: set noet: */ -- cgit v1.2.3-24-g4f1b