diff options
author | Olivier Brunel <jjk@jjacky.com> | 2014-01-10 16:25:14 +0100 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2014-03-03 11:25:54 +1000 |
commit | 28dbd5551ee75e843019e6f067ed069daaabba0b (patch) | |
tree | 409a7b18a3363ae9a53da30ee17ce59fbc67dd5b /src | |
parent | b6f6a165c4630cac86efb2608b9909b20488a710 (diff) | |
download | pacman-28dbd5551ee75e843019e6f067ed069daaabba0b.tar.xz |
Update the event callback
Instead of using two void* arguments for all events, we now send one
pointer to an alpm_event_t struct. This contains the type of event that
was triggered.
With this information, the pointer can then be typecasted to the
event-specific struct in order to get additional arguments.
Signed-off-by: Olivier Brunel <jjk@jjacky.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/callback.c | 87 | ||||
-rw-r--r-- | src/pacman/callback.h | 2 |
2 files changed, 50 insertions, 39 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 1b5d8f66..218772d5 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -149,12 +149,12 @@ static void fill_progress(const int bar_percent, const int disp_percent, } /* callback to handle messages/notifications from libalpm transactions */ -void cb_event(alpm_event_t event, void *data1, void *data2) +void cb_event(alpm_event_t *event) { if(config->print) { return; } - switch(event) { + switch(event->type) { case ALPM_EVENT_CHECKDEPS_START: printf(_("checking dependencies...\n")); break; @@ -169,38 +169,43 @@ void cb_event(alpm_event_t event, void *data1, void *data2) case ALPM_EVENT_INTERCONFLICTS_START: printf(_("looking for conflicting packages...\n")); break; - case ALPM_EVENT_ADD_START: - if(config->noprogressbar) { - printf(_("installing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_ADD_DONE: - display_optdepends(data1); - break; - case ALPM_EVENT_REMOVE_START: + case ALPM_EVENT_PACKAGE_OPERATION_START: if(config->noprogressbar) { - printf(_("removing %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_START: - if(config->noprogressbar) { - printf(_("upgrading %s...\n"), alpm_pkg_get_name(data1)); - } - break; - case ALPM_EVENT_UPGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_DOWNGRADE_START: - if(config->noprogressbar) { - printf(_("downgrading %s...\n"), alpm_pkg_get_name(data1)); + alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event; + switch(e->operation) { + case ALPM_PACKAGE_INSTALL: + printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_UPGRADE: + printf(_("upgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_REINSTALL: + printf(_("reinstalling %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_DOWNGRADE: + printf(_("downgrading %s...\n"), alpm_pkg_get_name(e->newpkg)); + break; + case ALPM_PACKAGE_REMOVE: + printf(_("removing %s...\n"), alpm_pkg_get_name(e->oldpkg)); + break; + } } break; - case ALPM_EVENT_DOWNGRADE_DONE: - display_new_optdepends(data2, data1); - break; - case ALPM_EVENT_REINSTALL_START: - if(config->noprogressbar) { - printf(_("reinstalling %s...\n"), alpm_pkg_get_name(data1)); + case ALPM_EVENT_PACKAGE_OPERATION_DONE: + { + alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event; + switch(e->operation) { + case ALPM_PACKAGE_INSTALL: + display_optdepends(e->newpkg); + break; + case ALPM_PACKAGE_UPGRADE: + case ALPM_PACKAGE_DOWNGRADE: + display_new_optdepends(e->oldpkg, e->newpkg); + break; + case ALPM_PACKAGE_REINSTALL: + case ALPM_PACKAGE_REMOVE: + break; + } } break; case ALPM_EVENT_INTEGRITY_START: @@ -228,7 +233,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("applying deltas...\n")); break; case ALPM_EVENT_DELTA_PATCH_START: - printf(_("generating %s with %s... "), (char *)data1, (char *)data2); + { + alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event; + printf(_("generating %s with %s... "), e->delta->to, e->delta->delta); + } break; case ALPM_EVENT_DELTA_PATCH_DONE: printf(_("success!\n")); @@ -237,7 +245,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2) printf(_("failed.\n")); break; case ALPM_EVENT_SCRIPTLET_INFO: - fputs((const char *)data1, stdout); + fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout); break; case ALPM_EVENT_RETRIEVE_START: colon_printf(_("Retrieving packages ...\n")); @@ -248,18 +256,21 @@ void cb_event(alpm_event_t event, void *data1, void *data2) } break; case ALPM_EVENT_OPTDEP_REMOVAL: - colon_printf(_("%s optionally requires %s\n"), alpm_pkg_get_name(data1), - alpm_dep_compute_string(data2)); + { + alpm_event_optdep_removal_t *e = (alpm_event_optdep_removal_t *) event; + colon_printf(_("%s optionally requires %s\n"), + alpm_pkg_get_name(e->pkg), + alpm_dep_compute_string(e->optdep)); + } break; case ALPM_EVENT_DATABASE_MISSING: if(!config->op_s_sync) { pm_printf(ALPM_LOG_WARNING, - "database file for '%s' does not exist\n", (char *)data1); + "database file for '%s' does not exist\n", + ((alpm_event_database_missing_t *) event)->dbname); } break; /* all the simple done events, with fallthrough for each */ - case ALPM_EVENT_REINSTALL_DONE: - case ALPM_EVENT_REMOVE_DONE: case ALPM_EVENT_FILECONFLICTS_DONE: case ALPM_EVENT_CHECKDEPS_DONE: case ALPM_EVENT_RESOLVEDEPS_DONE: diff --git a/src/pacman/callback.h b/src/pacman/callback.h index 882210f4..18939939 100644 --- a/src/pacman/callback.h +++ b/src/pacman/callback.h @@ -25,7 +25,7 @@ #include <alpm.h> /* callback to handle messages/notifications from libalpm */ -void cb_event(alpm_event_t event, void *data1, void *data2); +void cb_event(alpm_event_t *event); /* callback to handle questions from libalpm (yes/no) */ void cb_question(alpm_question_t event, void *data1, void *data2, |