From 28dbd5551ee75e843019e6f067ed069daaabba0b Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Fri, 10 Jan 2014 16:25:14 +0100 Subject: 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 Signed-off-by: Allan McRae --- lib/libalpm/add.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'lib/libalpm/add.c') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 1199d300..b0f97d89 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -465,7 +465,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, alpm_db_t *db = handle->db_local; alpm_trans_t *trans = handle->trans; alpm_progress_t progress = ALPM_PROGRESS_ADD_START; - alpm_event_t done = ALPM_EVENT_ADD_DONE, start = ALPM_EVENT_ADD_START; + alpm_event_package_operation_t event; const char *log_msg = "adding"; const char *pkgfile; @@ -478,18 +478,15 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, if(cmp < 0) { log_msg = "downgrading"; progress = ALPM_PROGRESS_DOWNGRADE_START; - start = ALPM_EVENT_DOWNGRADE_START; - done = ALPM_EVENT_DOWNGRADE_DONE; + event.operation = ALPM_PACKAGE_DOWNGRADE; } else if(cmp == 0) { log_msg = "reinstalling"; progress = ALPM_PROGRESS_REINSTALL_START; - start = ALPM_EVENT_REINSTALL_START; - done = ALPM_EVENT_REINSTALL_DONE; + event.operation = ALPM_PACKAGE_REINSTALL; } else { log_msg = "upgrading"; progress = ALPM_PROGRESS_UPGRADE_START; - start = ALPM_EVENT_UPGRADE_START; - done = ALPM_EVENT_UPGRADE_DONE; + event.operation = ALPM_PACKAGE_UPGRADE; } is_upgrade = 1; @@ -501,9 +498,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, /* copy over the install reason */ newpkg->reason = alpm_pkg_get_reason(local); + } else { + event.operation = ALPM_PACKAGE_INSTALL; } - EVENT(handle, start, newpkg, local); + event.type = ALPM_EVENT_PACKAGE_OPERATION_START; + event.oldpkg = oldpkg; + event.newpkg = newpkg; + EVENT(handle, &event); pkgfile = newpkg->origin_data.file; @@ -654,20 +656,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, PROGRESS(handle, progress, newpkg->name, 100, pkg_count, pkg_current); - switch(done) { - case ALPM_EVENT_ADD_DONE: + switch(event.operation) { + case ALPM_PACKAGE_INSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "installed %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_DOWNGRADE_DONE: + case ALPM_PACKAGE_DOWNGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "downgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; - case ALPM_EVENT_REINSTALL_DONE: + case ALPM_PACKAGE_REINSTALL: alpm_logaction(handle, ALPM_CALLER_PREFIX, "reinstalled %s (%s)\n", newpkg->name, newpkg->version); break; - case ALPM_EVENT_UPGRADE_DONE: + case ALPM_PACKAGE_UPGRADE: alpm_logaction(handle, ALPM_CALLER_PREFIX, "upgraded %s (%s -> %s)\n", newpkg->name, oldpkg->version, newpkg->version); break; @@ -687,7 +689,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg, free(scriptlet); } - EVENT(handle, done, newpkg, oldpkg); + event.type = ALPM_EVENT_PACKAGE_OPERATION_DONE; + EVENT(handle, &event); cleanup: _alpm_pkg_free(oldpkg); -- cgit v1.2.3-24-g4f1b