[pacman-dev] [PATCH v2 3/7] Update the event callback

Olivier Brunel jjk at jjacky.com
Fri Jan 10 10:25:14 EST 2014


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 at jjacky.com>
---
 lib/libalpm/add.c     |  31 ++++++-----
 lib/libalpm/alpm.h    | 148 +++++++++++++++++++++++++++++---------------------
 lib/libalpm/be_sync.c |   6 +-
 lib/libalpm/handle.h  |   4 +-
 lib/libalpm/remove.c  |  25 +++++++--
 lib/libalpm/sync.c    |  81 +++++++++++++++++++--------
 lib/libalpm/util.c    |   6 +-
 src/pacman/callback.c |  87 ++++++++++++++++-------------
 src/pacman/callback.h |   2 +-
 9 files changed, 241 insertions(+), 149 deletions(-)

diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 91b40a1..1eaea36 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -460,7 +460,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;
 
@@ -473,18 +473,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;
 
@@ -496,9 +493,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;
 
@@ -649,20 +651,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;
@@ -682,7 +684,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);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 126f50a5..9379372 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -275,10 +275,9 @@ int alpm_logaction(alpm_handle_t *handle, const char *prefix,
 		const char *fmt, ...) __attribute__((format(printf, 3, 4)));
 
 /**
- * Events.
- * NULL parameters are passed to in all events unless specified otherwise.
+ * Type of events.
  */
-typedef enum _alpm_event_t {
+typedef enum _alpm_event_type_t {
 	/** Dependencies will be computed for a package. */
 	ALPM_EVENT_CHECKDEPS_START = 1,
 	/** Dependencies were computed for a package. */
@@ -295,49 +294,12 @@ typedef enum _alpm_event_t {
 	ALPM_EVENT_INTERCONFLICTS_START,
 	/** Inter-conflicts were checked for target package. */
 	ALPM_EVENT_INTERCONFLICTS_DONE,
-	/** Package will be installed.
-	 * A pointer to the target package is passed to the callback.
-	 */
-	ALPM_EVENT_ADD_START,
-	/** Package was installed.
-	 * A pointer to the new package is passed to the callback.
-	 */
-	ALPM_EVENT_ADD_DONE,
-	/** Package will be removed.
-	 * A pointer to the target package is passed to the callback.
-	 */
-	ALPM_EVENT_REMOVE_START,
-	/** Package was removed.
-	 * A pointer to the removed package is passed to the callback.
-	 */
-	ALPM_EVENT_REMOVE_DONE,
-	/** Package will be upgraded.
-	 * A pointer to the upgraded package is passed to the callback.
-	 */
-	ALPM_EVENT_UPGRADE_START,
-	/** Package was upgraded.
-	 * A pointer to the new package, and a pointer to the old package is passed
-	 * to the callback, respectively.
-	 */
-	ALPM_EVENT_UPGRADE_DONE,
-	/** Package will be downgraded.
-	 * A pointer to the downgraded package is passed to the callback.
-	 */
-	ALPM_EVENT_DOWNGRADE_START,
-	/** Package was downgraded.
-	 * A pointer to the new package, and a pointer to the old package is passed
-	 * to the callback, respectively.
-	 */
-	ALPM_EVENT_DOWNGRADE_DONE,
-	/** Package will be reinstalled.
-	 * A pointer to the reinstalled package is passed to the callback.
-	 */
-	ALPM_EVENT_REINSTALL_START,
-	/** Package was reinstalled.
-	 * A pointer to the new package, and a pointer to the old package is passed
-	 * to the callback, respectively.
-	 */
-	ALPM_EVENT_REINSTALL_DONE,
+	/** Package will be installed/upgraded/downgraded/re-installed/removed; See
+	 * alpm_event_package_operation_t for arguments. */
+	ALPM_EVENT_PACKAGE_OPERATION_START,
+	/** Package was installed/upgraded/downgraded/re-installed/removed; See
+	 * alpm_event_package_operation_t for arguments. */
+	ALPM_EVENT_PACKAGE_OPERATION_DONE,
 	/** Target package's integrity will be checked. */
 	ALPM_EVENT_INTEGRITY_START,
 	/** Target package's integrity was checked. */
@@ -354,31 +316,27 @@ typedef enum _alpm_event_t {
 	ALPM_EVENT_DELTA_PATCHES_START,
 	/** Deltas were applied to packages. */
 	ALPM_EVENT_DELTA_PATCHES_DONE,
-	/** Delta patch will be applied to target package.
-	 * The filename of the package and the filename of the patch is passed to the
-	 * callback.
-	 */
+	/** Delta patch will be applied to target package; See
+	 * alpm_event_delta_patch_t for arguments.. */
 	ALPM_EVENT_DELTA_PATCH_START,
 	/** Delta patch was applied to target package. */
 	ALPM_EVENT_DELTA_PATCH_DONE,
 	/** Delta patch failed to apply to target package. */
 	ALPM_EVENT_DELTA_PATCH_FAILED,
-	/** Scriptlet has printed information.
-	 * A line of text is passed to the callback.
-	 */
+	/** Scriptlet has printed information; See alpm_event_scriptlet_info_t for
+	 * arguments. */
 	ALPM_EVENT_SCRIPTLET_INFO,
-	/** Files will be downloaded from a repository.
-	 * The repository's tree name is passed to the callback.
-	 */
+	/** Files will be downloaded from a repository. */
 	ALPM_EVENT_RETRIEVE_START,
-	/** Disk space usage will be computed for a package */
+	/** Disk space usage will be computed for a package. */
 	ALPM_EVENT_DISKSPACE_START,
-	/** Disk space usage was computed for a package */
+	/** Disk space usage was computed for a package. */
 	ALPM_EVENT_DISKSPACE_DONE,
-	/** An optdepend for another package is being removed
-	 * The requiring package and its dependency are passed to the callback */
+	/** An optdepend for another package is being removed; See
+	 * alpm_event_optdep_removal_t for arguments. */
 	ALPM_EVENT_OPTDEP_REMOVAL,
-	/** A configured repository database is missing */
+	/** A configured repository database is missing; See
+	 * alpm_event_database_missing_t for arguments. */
 	ALPM_EVENT_DATABASE_MISSING,
 	/** Checking keys used to create signatures are in keyring. */
 	ALPM_EVENT_KEYRING_START,
@@ -388,10 +346,74 @@ typedef enum _alpm_event_t {
 	ALPM_EVENT_KEY_DOWNLOAD_START,
 	/** Key downloading is finished. */
 	ALPM_EVENT_KEY_DOWNLOAD_DONE
+} alpm_event_type_t;
+
+/** Events.
+ * This is a generic struct this is passed to the callback, that allows the
+ * frontend to know which type of event was triggered. It is then possible to
+ * typecast the pointer to the right structure, in order to access
+ * event-specific data. */
+typedef struct _alpm_event_t {
+	/** Type of event. */
+	alpm_event_type_t type;
 } alpm_event_t;
 
-/** Event callback */
-typedef void (*alpm_cb_event)(alpm_event_t, void *, void *);
+typedef enum _alpm_package_operation_t {
+	/** Package (to be) installed. (No oldpkg) */
+	ALPM_PACKAGE_INSTALL = 1,
+	/** Package (to be) upgraded */
+	ALPM_PACKAGE_UPGRADE,
+	/** Package (to be) re-installed. */
+	ALPM_PACKAGE_REINSTALL,
+	/** Package (to be) downgraded. */
+	ALPM_PACKAGE_DOWNGRADE,
+	/** Package (to be) removed. (No newpkg) */
+	ALPM_PACKAGE_REMOVE
+} alpm_package_operation_t;
+
+typedef struct _alpm_event_package_operation_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Type of operation. */
+	alpm_package_operation_t operation;
+	/** Old package. */
+	alpm_pkg_t *oldpkg;
+	/** New package. */
+	alpm_pkg_t *newpkg;
+} alpm_event_package_operation_t;
+
+typedef struct _alpm_event_optdep_removal_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Package with the optdep. */
+	alpm_pkg_t *pkg;
+	/** Optdep being removed. */
+	alpm_depend_t *optdep;
+} alpm_event_optdep_removal_t;
+
+typedef struct _alpm_event_delta_patch_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Delta info */
+	alpm_delta_t *delta;
+} alpm_event_delta_patch_t;
+
+typedef struct _alpm_event_scriptlet_info_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Line of scriptlet output. */
+	const char *line;
+} alpm_event_scriptlet_info_t;
+
+typedef struct _alpm_event_database_missing_t {
+	/** Type of event. */
+	alpm_event_type_t type;
+	/** Name of the database. */
+	const char *dbname;
+} alpm_event_database_missing_t;
+
+/** Event callback. */
+typedef void (*alpm_cb_event)(alpm_event_t *);
 
 /**
  * Questions.
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 67b7368..922b3a2 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -89,9 +89,13 @@ static int sync_db_validate(alpm_db_t *db)
 
 	/* we can skip any validation if the database doesn't exist */
 	if(_alpm_access(db->handle, NULL, dbpath, R_OK) != 0 && errno == ENOENT) {
+		alpm_event_database_missing_t event = {
+			.type = ALPM_EVENT_DATABASE_MISSING,
+			.dbname = db->treename
+		};
 		db->status &= ~DB_STATUS_EXISTS;
 		db->status |= DB_STATUS_MISSING;
-		EVENT(db->handle, ALPM_EVENT_DATABASE_MISSING, db->treename, NULL);
+		EVENT(db->handle, &event);
 		goto valid;
 	}
 	db->status |= DB_STATUS_EXISTS;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index fcfd4fa..d767fb6 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -31,10 +31,10 @@
 #include <curl/curl.h>
 #endif
 
-#define EVENT(h, e, d1, d2) \
+#define EVENT(h, e) \
 do { \
 	if((h)->eventcb) { \
-		(h)->eventcb(e, d1, d2); \
+		(h)->eventcb((alpm_event_t *) (e)); \
 	} \
 } while(0)
 #define QUESTION(h, q, d1, d2, d3, r) \
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index d78c5f1..c2831e4 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -179,7 +179,12 @@ static void remove_notify_needed_optdepends(alpm_handle_t *handle, alpm_list_t *
 			for(j = optdeps; j; j = alpm_list_next(j)) {
 				alpm_depend_t *optdep = j->data;
 				if(alpm_pkg_find(lp, optdep->name)) {
-					EVENT(handle, ALPM_EVENT_OPTDEP_REMOVAL, pkg, optdep);
+					alpm_event_optdep_removal_t event = {
+						.type = ALPM_EVENT_OPTDEP_REMOVAL,
+						.pkg = pkg,
+						.optdep = optdep
+					};
+					EVENT(handle, &event);
 				}
 			}
 		}
@@ -203,6 +208,7 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 	alpm_list_t *lp;
 	alpm_trans_t *trans = handle->trans;
 	alpm_db_t *db = handle->db_local;
+	alpm_event_t event;
 
 	if((trans->flags & ALPM_TRANS_FLAG_RECURSE)
 			&& !(trans->flags & ALPM_TRANS_FLAG_CASCADE)) {
@@ -214,7 +220,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 	}
 
 	if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
-		EVENT(handle, ALPM_EVENT_CHECKDEPS_START, NULL, NULL);
+		event.type = ALPM_EVENT_CHECKDEPS_START;
+		EVENT(handle, &event);
 
 		_alpm_log(handle, ALPM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
 		lp = alpm_checkdeps(handle, _alpm_db_get_pkgcache(db), trans->remove, NULL, 1);
@@ -254,7 +261,8 @@ int _alpm_remove_prepare(alpm_handle_t *handle, alpm_list_t **data)
 	remove_notify_needed_optdepends(handle, trans->remove);
 
 	if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
-		EVENT(handle, ALPM_EVENT_CHECKDEPS_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_CHECKDEPS_DONE;
+		EVENT(handle, &event);
 	}
 
 	return 0;
@@ -656,12 +664,18 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
 {
 	const char *pkgname = oldpkg->name;
 	const char *pkgver = oldpkg->version;
+	alpm_event_package_operation_t event = {
+		.type = ALPM_EVENT_PACKAGE_OPERATION_START,
+		.operation = ALPM_PACKAGE_REMOVE,
+		.oldpkg = oldpkg,
+		.newpkg = NULL
+	};
 
 	if(newpkg) {
 		_alpm_log(handle, ALPM_LOG_DEBUG, "removing old package first (%s-%s)\n",
 				pkgname, pkgver);
 	} else {
-		EVENT(handle, ALPM_EVENT_REMOVE_START, oldpkg, NULL);
+		EVENT(handle, &event);
 		_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
 				pkgname, pkgver);
 
@@ -695,7 +709,8 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
 	}
 
 	if(!newpkg) {
-		EVENT(handle, ALPM_EVENT_REMOVE_DONE, oldpkg, NULL);
+		event.type = ALPM_EVENT_PACKAGE_OPERATION_DONE;
+		EVENT(handle, &event);
 	}
 
 	/* remove the package from the database */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 4ae01ac..63adba4 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -374,6 +374,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 	size_t from_sync = 0;
 	int ret = 0;
 	alpm_trans_t *trans = handle->trans;
+	alpm_event_t event;
 
 	if(data) {
 		*data = NULL;
@@ -403,7 +404,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 
 		/* Build up list by repeatedly resolving each transaction package */
 		/* Resolve targets dependencies */
-		EVENT(handle, ALPM_EVENT_RESOLVEDEPS_START, NULL, NULL);
+		event.type = ALPM_EVENT_RESOLVEDEPS_START;
+		EVENT(handle, &event);
 		_alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n");
 
 		/* build remove list for resolvedeps */
@@ -479,12 +481,14 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 		alpm_list_free(trans->add);
 		trans->add = resolved;
 
-		EVENT(handle, ALPM_EVENT_RESOLVEDEPS_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_RESOLVEDEPS_DONE;
+		EVENT(handle, &event);
 	}
 
 	if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) {
 		/* check for inter-conflicts and whatnot */
-		EVENT(handle, ALPM_EVENT_INTERCONFLICTS_START, NULL, NULL);
+		event.type = ALPM_EVENT_INTERCONFLICTS_START;
+		EVENT(handle, &event);
 
 		_alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n");
 
@@ -594,7 +598,8 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
 				goto cleanup;
 			}
 		}
-		EVENT(handle, ALPM_EVENT_INTERCONFLICTS_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_INTERCONFLICTS_DONE;
+		EVENT(handle, &event);
 		alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_conflict_free);
 		alpm_list_free(deps);
 	}
@@ -678,6 +683,7 @@ static int apply_deltas(alpm_handle_t *handle)
 	int deltas_found = 0, ret = 0;
 	const char *cachedir = _alpm_filecache_setup(handle);
 	alpm_trans_t *trans = handle->trans;
+	alpm_event_delta_patch_t event;
 
 	for(i = trans->add; i; i = i->next) {
 		alpm_pkg_t *spkg = i->data;
@@ -691,7 +697,8 @@ static int apply_deltas(alpm_handle_t *handle)
 		if(!deltas_found) {
 			/* only show this if we actually have deltas to apply, and it is before
 			 * the very first one */
-			EVENT(handle, ALPM_EVENT_DELTA_PATCHES_START, NULL, NULL);
+			event.type = ALPM_EVENT_DELTA_PATCHES_START;
+			EVENT(handle, &event);
 			deltas_found = 1;
 		}
 
@@ -725,11 +732,14 @@ static int apply_deltas(alpm_handle_t *handle)
 
 			_alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command);
 
-			EVENT(handle, ALPM_EVENT_DELTA_PATCH_START, d->to, d->delta);
+			event.type = ALPM_EVENT_DELTA_PATCH_START;
+			event.delta = d;
+			EVENT(handle, &event);
 
 			int retval = system(command);
 			if(retval == 0) {
-				EVENT(handle, ALPM_EVENT_DELTA_PATCH_DONE, NULL, NULL);
+				event.type = ALPM_EVENT_DELTA_PATCH_DONE;
+				EVENT(handle, &event);
 
 				/* delete the delta file */
 				unlink(delta);
@@ -747,7 +757,8 @@ static int apply_deltas(alpm_handle_t *handle)
 
 			if(retval != 0) {
 				/* one delta failed for this package, cancel the remaining ones */
-				EVENT(handle, ALPM_EVENT_DELTA_PATCH_FAILED, NULL, NULL);
+				event.type = ALPM_EVENT_DELTA_PATCH_FAILED;
+				EVENT(handle, &event);
 				handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED;
 				ret = 1;
 				break;
@@ -755,7 +766,8 @@ static int apply_deltas(alpm_handle_t *handle)
 		}
 	}
 	if(deltas_found) {
-		EVENT(handle, ALPM_EVENT_DELTA_PATCHES_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_DELTA_PATCHES_DONE;
+		EVENT(handle, &event);
 	}
 
 	return ret;
@@ -784,13 +796,15 @@ static int prompt_to_delete(alpm_handle_t *handle, const char *filepath,
 static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
 {
 	alpm_list_t *i, *errors = NULL;
+	alpm_event_t event;
 
 	if(!deltas) {
 		return 0;
 	}
 
 	/* Check integrity of deltas */
-	EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_START, NULL, NULL);
+	event.type = ALPM_EVENT_DELTA_INTEGRITY_START;
+	EVENT(handle, &event);
 	for(i = deltas; i; i = i->next) {
 		alpm_delta_t *d = i->data;
 		char *filepath = _alpm_filecache_find(handle, d->delta);
@@ -801,7 +815,8 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
 			FREE(filepath);
 		}
 	}
-	EVENT(handle, ALPM_EVENT_DELTA_INTEGRITY_DONE, NULL, NULL);
+	event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE;
+	EVENT(handle, &event);
 
 	if(errors) {
 		for(i = errors; i; i = i->next) {
@@ -907,6 +922,7 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
 	const char *cachedir;
 	alpm_list_t *i, *files = NULL;
 	int errors = 0;
+	alpm_event_t event;
 
 	cachedir = _alpm_filecache_setup(handle);
 	handle->trans->state = STATE_DOWNLOADING;
@@ -954,7 +970,8 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
 			}
 		}
 
-		EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL);
+		event.type = ALPM_EVENT_RETRIEVE_START;
+		EVENT(handle, &event);
 		for(i = files; i; i = i->next) {
 			if(download_single_file(handle, i->data, cachedir) == -1) {
 				errors++;
@@ -988,8 +1005,10 @@ static int check_keyring(alpm_handle_t *handle)
 {
 	size_t current = 0, numtargs;
 	alpm_list_t *i, *errors = NULL;
+	alpm_event_t event;
 
-	EVENT(handle, ALPM_EVENT_KEYRING_START, NULL, NULL);
+	event.type = ALPM_EVENT_KEYRING_START;
+	EVENT(handle, &event);
 
 	numtargs = alpm_list_count(handle->trans->add);
 
@@ -1033,10 +1052,12 @@ static int check_keyring(alpm_handle_t *handle)
 
 	PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100,
 			numtargs, current);
-	EVENT(handle, ALPM_EVENT_KEYRING_DONE, NULL, NULL);
+	event.type = ALPM_EVENT_KEYRING_DONE;
+	EVENT(handle, &event);
 
 	if(errors) {
-		EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_START, NULL, NULL);
+		event.type = ALPM_EVENT_KEY_DOWNLOAD_START;
+		EVENT(handle, &event);
 		int fail = 0;
 		alpm_list_t *k;
 		for(k = errors; k; k = k->next) {
@@ -1045,7 +1066,8 @@ static int check_keyring(alpm_handle_t *handle)
 				fail = 1;
 			}
 		}
-		EVENT(handle, ALPM_EVENT_KEY_DOWNLOAD_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE;
+		EVENT(handle, &event);
 		if(fail) {
 			_alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n"));
 			return -1;
@@ -1070,9 +1092,11 @@ static int check_validity(alpm_handle_t *handle,
 	size_t current = 0;
 	uint64_t current_bytes = 0;
 	alpm_list_t *i, *errors = NULL;
+	alpm_event_t event;
 
 	/* Check integrity of packages */
-	EVENT(handle, ALPM_EVENT_INTEGRITY_START, NULL, NULL);
+	event.type = ALPM_EVENT_INTEGRITY_START;
+	EVENT(handle, &event);
 
 	for(i = handle->trans->add; i; i = i->next, current++) {
 		struct validity v = { i->data, NULL, NULL, 0, 0, 0 };
@@ -1104,7 +1128,8 @@ static int check_validity(alpm_handle_t *handle,
 
 	PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100,
 			total, current);
-	EVENT(handle, ALPM_EVENT_INTEGRITY_DONE, NULL, NULL);
+	event.type = ALPM_EVENT_INTEGRITY_DONE;
+	EVENT(handle, &event);
 
 	if(errors) {
 		for(i = errors; i; i = i->next) {
@@ -1143,9 +1168,11 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
 	size_t current = 0, current_bytes = 0;
 	int errors = 0;
 	alpm_list_t *i;
+	alpm_event_t event;
 
 	/* load packages from disk now that they are known-valid */
-	EVENT(handle, ALPM_EVENT_LOAD_START, NULL, NULL);
+	event.type = ALPM_EVENT_LOAD_START;
+	EVENT(handle, &event);
 
 	for(i = handle->trans->add; i; i = i->next, current++) {
 		alpm_pkg_t *spkg = i->data;
@@ -1186,7 +1213,8 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
 
 	PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100,
 			total, current);
-	EVENT(handle, ALPM_EVENT_LOAD_DONE, NULL, NULL);
+	event.type = ALPM_EVENT_LOAD_DONE;
+	EVENT(handle, &event);
 
 	if(errors) {
 		if(!handle->pm_errno) {
@@ -1204,6 +1232,7 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 	size_t total = 0;
 	uint64_t total_bytes = 0;
 	alpm_trans_t *trans = handle->trans;
+	alpm_event_t event;
 
 	if(download_files(handle, &deltas)) {
 		alpm_list_free(deltas);
@@ -1262,7 +1291,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 
 	/* fileconflict check */
 	if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
-		EVENT(handle, ALPM_EVENT_FILECONFLICTS_START, NULL, NULL);
+		event.type = ALPM_EVENT_FILECONFLICTS_START;
+		EVENT(handle, &event);
 
 		_alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n");
 		alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle,
@@ -1277,12 +1307,14 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 			RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1);
 		}
 
-		EVENT(handle, ALPM_EVENT_FILECONFLICTS_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_FILECONFLICTS_DONE;
+		EVENT(handle, &event);
 	}
 
 	/* check available disk space */
 	if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
-		EVENT(handle, ALPM_EVENT_DISKSPACE_START, NULL, NULL);
+		event.type = ALPM_EVENT_DISKSPACE_START;
+		EVENT(handle, &event);
 
 		_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n");
 		if(_alpm_check_diskspace(handle) == -1) {
@@ -1290,7 +1322,8 @@ int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
 			return -1;
 		}
 
-		EVENT(handle, ALPM_EVENT_DISKSPACE_DONE, NULL, NULL);
+		event.type = ALPM_EVENT_DISKSPACE_DONE;
+		EVENT(handle, &event);
 	}
 
 	/* remove conflicting and to-be-replaced packages */
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index f28404d..7704ea5 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -572,10 +572,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
 		} else {
 			while(!feof(pipe_file)) {
 				char line[PATH_MAX];
+				alpm_event_scriptlet_info_t event = {
+					.type = ALPM_EVENT_SCRIPTLET_INFO,
+					.line = line
+				};
 				if(fgets(line, PATH_MAX, pipe_file) == NULL)
 					break;
 				alpm_logaction(handle, "ALPM-SCRIPTLET", "%s", line);
-				EVENT(handle, ALPM_EVENT_SCRIPTLET_INFO, line, NULL);
+				EVENT(handle, &event);
 			}
 			fclose(pipe_file);
 		}
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 4b0f881..8b67ffc 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 61a7e4c..cdc8ee7 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,
-- 
1.8.5.2



More information about the pacman-dev mailing list