mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
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 <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
28dbd5551e
commit
cd793c5ab7
@ -261,16 +261,6 @@ typedef struct _alpm_siglist_t {
|
|||||||
* Logging facilities
|
* 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,
|
int alpm_logaction(alpm_handle_t *handle, const char *prefix,
|
||||||
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
@ -345,7 +335,9 @@ typedef enum _alpm_event_type_t {
|
|||||||
/** Downloading missing keys into keyring. */
|
/** Downloading missing keys into keyring. */
|
||||||
ALPM_EVENT_KEY_DOWNLOAD_START,
|
ALPM_EVENT_KEY_DOWNLOAD_START,
|
||||||
/** Key downloading is finished. */
|
/** 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;
|
} alpm_event_type_t;
|
||||||
|
|
||||||
/** Events.
|
/** Events.
|
||||||
@ -412,6 +404,24 @@ typedef struct _alpm_event_database_missing_t {
|
|||||||
const char *dbname;
|
const char *dbname;
|
||||||
} alpm_event_database_missing_t;
|
} 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. */
|
/** Event callback. */
|
||||||
typedef void (*alpm_cb_event)(alpm_event_t *);
|
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. */
|
/** Returns the callback used to report download progress. */
|
||||||
alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
|
alpm_cb_download alpm_option_get_dlcb(alpm_handle_t *handle);
|
||||||
/** Sets the callback used to report download progress. */
|
/** Sets the callback used to report download progress. */
|
||||||
|
@ -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)
|
alpm_cb_download SYMEXPORT alpm_option_get_dlcb(alpm_handle_t *handle)
|
||||||
{
|
{
|
||||||
CHECK_HANDLE(handle, return NULL);
|
CHECK_HANDLE(handle, return NULL);
|
||||||
@ -258,13 +252,6 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle)
|
|||||||
return handle->checkspace;
|
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)
|
int SYMEXPORT alpm_option_set_dlcb(alpm_handle_t *handle, alpm_cb_download cb)
|
||||||
{
|
{
|
||||||
CHECK_HANDLE(handle, return -1);
|
CHECK_HANDLE(handle, return -1);
|
||||||
|
@ -63,7 +63,6 @@ struct __alpm_handle_t {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* callback functions */
|
/* callback functions */
|
||||||
alpm_cb_log logcb; /* Log callback function */
|
|
||||||
alpm_cb_download dlcb; /* Download callback function */
|
alpm_cb_download dlcb; /* Download callback function */
|
||||||
alpm_cb_totaldl totaldlcb; /* Total download callback function */
|
alpm_cb_totaldl totaldlcb; /* Total download callback function */
|
||||||
alpm_cb_fetch fetchcb; /* Download file callback function */
|
alpm_cb_fetch fetchcb; /* Download file callback function */
|
||||||
|
@ -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, ...)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(event.args, fmt);
|
||||||
handle->logcb(flag, fmt, args);
|
EVENT(handle, &event);
|
||||||
va_end(args);
|
va_end(event.args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim: set noet: */
|
/* vim: set noet: */
|
||||||
|
@ -270,6 +270,24 @@ void cb_event(alpm_event_t *event)
|
|||||||
((alpm_event_database_missing_t *) event)->dbname);
|
((alpm_event_database_missing_t *) event)->dbname);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ALPM_EVENT_LOG:
|
||||||
|
{
|
||||||
|
alpm_event_log_t *e = (alpm_event_log_t *) event;
|
||||||
|
if(!e->fmt || strlen(e->fmt) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(on_progress) {
|
||||||
|
char *string = NULL;
|
||||||
|
pm_vasprintf(&string, e->level, e->fmt, e->args);
|
||||||
|
if(string != NULL) {
|
||||||
|
output = alpm_list_add(output, string);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
pm_vfprintf(stderr, e->level, e->fmt, e->args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
/* all the simple done events, with fallthrough for each */
|
/* all the simple done events, with fallthrough for each */
|
||||||
case ALPM_EVENT_FILECONFLICTS_DONE:
|
case ALPM_EVENT_FILECONFLICTS_DONE:
|
||||||
case ALPM_EVENT_CHECKDEPS_DONE:
|
case ALPM_EVENT_CHECKDEPS_DONE:
|
||||||
@ -777,22 +795,4 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback to handle notifications from the library */
|
|
||||||
void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
if(!fmt || strlen(fmt) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(on_progress) {
|
|
||||||
char *string = NULL;
|
|
||||||
pm_vasprintf(&string, level, fmt, args);
|
|
||||||
if(string != NULL) {
|
|
||||||
output = alpm_list_add(output, string);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pm_vfprintf(stderr, level, fmt, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vim: set noet: */
|
/* vim: set noet: */
|
||||||
|
@ -40,10 +40,6 @@ void cb_dl_total(off_t total);
|
|||||||
/* callback to handle display of download progress */
|
/* callback to handle display of download progress */
|
||||||
void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total);
|
void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total);
|
||||||
|
|
||||||
/* callback to handle messages/notifications from pacman library */
|
|
||||||
__attribute__((format(printf, 2, 0)))
|
|
||||||
void cb_log(alpm_loglevel_t level, const char *fmt, va_list args);
|
|
||||||
|
|
||||||
#endif /* _PM_CALLBACK_H */
|
#endif /* _PM_CALLBACK_H */
|
||||||
|
|
||||||
/* vim: set noet: */
|
/* vim: set noet: */
|
||||||
|
@ -685,7 +685,6 @@ static int setup_libalpm(void)
|
|||||||
}
|
}
|
||||||
config->handle = handle;
|
config->handle = handle;
|
||||||
|
|
||||||
alpm_option_set_logcb(handle, cb_log);
|
|
||||||
alpm_option_set_dlcb(handle, cb_dl_progress);
|
alpm_option_set_dlcb(handle, cb_dl_progress);
|
||||||
alpm_option_set_eventcb(handle, cb_event);
|
alpm_option_set_eventcb(handle, cb_event);
|
||||||
alpm_option_set_questioncb(handle, cb_question);
|
alpm_option_set_questioncb(handle, cb_question);
|
||||||
|
@ -35,17 +35,19 @@ static void cleanup(int signum)
|
|||||||
exit(signum);
|
exit(signum);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((format(printf, 2, 0)))
|
static void output_cb(alpm_event_log_t *event)
|
||||||
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
|
|
||||||
{
|
{
|
||||||
if(strlen(fmt)) {
|
if(event->type != ALPM_EVENT_LOG) {
|
||||||
switch(level) {
|
return;
|
||||||
|
}
|
||||||
|
if(strlen(event->fmt)) {
|
||||||
|
switch(event->level) {
|
||||||
case ALPM_LOG_ERROR: printf("error: "); break;
|
case ALPM_LOG_ERROR: printf("error: "); break;
|
||||||
case ALPM_LOG_WARNING: printf("warning: "); break;
|
case ALPM_LOG_WARNING: printf("warning: "); break;
|
||||||
/* case ALPM_LOG_DEBUG: printf("debug: "); break; */
|
/* case ALPM_LOG_DEBUG: printf("debug: "); break; */
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
vprintf(fmt, args);
|
vprintf(event->fmt, event->args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +128,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* let us get log messages from libalpm */
|
/* let us get log messages from libalpm */
|
||||||
alpm_option_set_logcb(handle, output_cb);
|
alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
|
||||||
|
|
||||||
checkdbs(dbnames);
|
checkdbs(dbnames);
|
||||||
alpm_list_free(dbnames);
|
alpm_list_free(dbnames);
|
||||||
|
@ -39,16 +39,18 @@ static void cleanup(int signum)
|
|||||||
exit(signum);
|
exit(signum);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((format(printf, 2, 0)))
|
static void output_cb(alpm_event_log_t *event)
|
||||||
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
|
|
||||||
{
|
{
|
||||||
if(strlen(fmt)) {
|
if(event->type != ALPM_EVENT_LOG) {
|
||||||
switch(level) {
|
return;
|
||||||
|
}
|
||||||
|
if(strlen(event->fmt)) {
|
||||||
|
switch(event->level) {
|
||||||
case ALPM_LOG_ERROR: printf("error: "); break;
|
case ALPM_LOG_ERROR: printf("error: "); break;
|
||||||
case ALPM_LOG_WARNING: printf("warning: "); break;
|
case ALPM_LOG_WARNING: printf("warning: "); break;
|
||||||
default: return;
|
default: return;
|
||||||
}
|
}
|
||||||
vprintf(fmt, args);
|
vprintf(event->fmt, event->args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +284,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* let us get log messages from libalpm */
|
/* let us get log messages from libalpm */
|
||||||
alpm_option_set_logcb(handle, output_cb);
|
alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
|
||||||
|
|
||||||
if(!dbnames) {
|
if(!dbnames) {
|
||||||
errors = check_localdb();
|
errors = check_localdb();
|
||||||
|
@ -23,18 +23,20 @@
|
|||||||
|
|
||||||
#include <alpm.h>
|
#include <alpm.h>
|
||||||
|
|
||||||
__attribute__((format(printf, 2, 0)))
|
static void output_cb(alpm_event_log_t *event)
|
||||||
static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
|
|
||||||
{
|
{
|
||||||
if(fmt[0] == '\0') {
|
if(event->type != ALPM_EVENT_LOG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch(level) {
|
if(event->fmt[0] == '\0') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch(event->level) {
|
||||||
case ALPM_LOG_ERROR: printf("error: "); break;
|
case ALPM_LOG_ERROR: printf("error: "); break;
|
||||||
case ALPM_LOG_WARNING: printf("warning: "); break;
|
case ALPM_LOG_WARNING: printf("warning: "); break;
|
||||||
default: return; /* skip other messages */
|
default: return; /* skip other messages */
|
||||||
}
|
}
|
||||||
vprintf(fmt, args);
|
vprintf(event->fmt, event->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@ -59,7 +61,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* let us get log messages from libalpm */
|
/* let us get log messages from libalpm */
|
||||||
alpm_option_set_logcb(handle, output_cb);
|
alpm_option_set_eventcb(handle, (alpm_cb_event) output_cb);
|
||||||
|
|
||||||
/* set gpgdir to default */
|
/* set gpgdir to default */
|
||||||
alpm_option_set_gpgdir(handle, GPGDIR);
|
alpm_option_set_gpgdir(handle, GPGDIR);
|
||||||
|
Loading…
Reference in New Issue
Block a user