event transaction callback rework to prepare the introduction of a conversation callback

This commit is contained in:
Aurelien Foret 2005-05-04 19:55:23 +00:00
parent 14c8583ccb
commit a26095f8fc
7 changed files with 33 additions and 30 deletions

View file

@ -200,7 +200,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) { if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
PMList *i; PMList *i;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for conflicts or unsatisfied dependencies"); _alpm_log(PM_LOG_FLOW1, "looking for conflicts or unsatisfied dependencies");
lp = checkdeps(db, trans->type, trans->packages); lp = checkdeps(db, trans->type, trans->packages);
@ -257,13 +257,13 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
FREELISTPTR(trans->packages); FREELISTPTR(trans->packages);
trans->packages = lp; trans->packages = lp;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
} }
/* Check for file conflicts /* Check for file conflicts
*/ */
if(!(trans->flags & PM_TRANS_FLAG_FORCE)) { if(!(trans->flags & PM_TRANS_FLAG_FORCE)) {
TRANS_CB(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for file conflicts"); _alpm_log(PM_LOG_FLOW1, "looking for file conflicts");
lp = db_find_conflicts(db, trans->packages, handle->root); lp = db_find_conflicts(db, trans->packages, handle->root);
@ -272,7 +272,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
RET_ERR(PM_ERR_FILE_CONFLICTS, -1); RET_ERR(PM_ERR_FILE_CONFLICTS, -1);
} }
TRANS_CB(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
} }
return(0); return(0);
@ -312,7 +312,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
if(pmo_upgrade) { if(pmo_upgrade) {
pmpkg_t *local = db_get_pkgfromcache(db, info->name); pmpkg_t *local = db_get_pkgfromcache(db, info->name);
if(local) { if(local) {
TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL); EVENT(trans, PM_TRANS_EVT_UPGRADE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version); _alpm_log(PM_LOG_FLOW1, "upgrading package %s-%s", info->name, info->version);
/* we'll need to save some record for backup checks later */ /* we'll need to save some record for backup checks later */
@ -360,7 +360,7 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
} }
} }
if(!pmo_upgrade) { if(!pmo_upgrade) {
TRANS_CB(trans, PM_TRANS_EVT_ADD_START, info, NULL); EVENT(trans, PM_TRANS_EVT_ADD_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "adding package %s-%s", info->name, info->version); _alpm_log(PM_LOG_FLOW1, "adding package %s-%s", info->name, info->version);
/* pre_install scriptlet */ /* pre_install scriptlet */
@ -656,11 +656,11 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
} }
if(pmo_upgrade) { if(pmo_upgrade) {
TRANS_CB(trans, PM_TRANS_EVT_UPGRADE_DONE, info, NULL); EVENT(trans, PM_TRANS_EVT_UPGRADE_DONE, info, NULL);
alpm_logaction("upgraded %s (%s -> %s)", info->name, alpm_logaction("upgraded %s (%s -> %s)", info->name,
oldpkg ? oldpkg->version : NULL, info->version); oldpkg ? oldpkg->version : NULL, info->version);
} else { } else {
TRANS_CB(trans, PM_TRANS_EVT_ADD_DONE, info, NULL); EVENT(trans, PM_TRANS_EVT_ADD_DONE, info, NULL);
alpm_logaction("installed %s (%s)", info->name, info->version); alpm_logaction("installed %s (%s)", info->name, info->version);
} }

View file

@ -541,7 +541,7 @@ void *alpm_trans_getinfo(unsigned char parm)
return(data); return(data);
} }
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb) int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event event)
{ {
/* Sanity checks */ /* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
@ -553,7 +553,7 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb)
RET_ERR(PM_ERR_MEMORY, -1); RET_ERR(PM_ERR_MEMORY, -1);
} }
return(trans_init(handle->trans, type, flags, cb)); return(trans_init(handle->trans, type, flags, event));
} }
int alpm_trans_sysupgrade() int alpm_trans_sysupgrade()

View file

@ -229,7 +229,10 @@ enum {
}; };
/* Event callback */ /* Event callback */
typedef void (*alpm_trans_cb)(unsigned short, void *, void *); typedef void (*alpm_trans_cb_event)(unsigned char, void *, void *);
/* Conversation callback */
typedef void (*alpm_trans_cb_conv)(unsigned char, void *, void *);
/* Info parameters */ /* Info parameters */
enum { enum {
@ -240,7 +243,7 @@ enum {
}; };
void *alpm_trans_getinfo(unsigned char parm); void *alpm_trans_getinfo(unsigned char parm);
int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb cb); int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event cb_event);
int alpm_trans_sysupgrade(); int alpm_trans_sysupgrade();
int alpm_trans_addtarget(char *target); int alpm_trans_addtarget(char *target);
int alpm_trans_prepare(PM_LIST **data); int alpm_trans_prepare(PM_LIST **data);

View file

@ -81,7 +81,7 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) { if(!(trans->flags & (PM_TRANS_FLAG_NODEPS)) && (trans->type != PM_TRANS_TYPE_UPGRADE)) {
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "looking for unsatisfied dependencies"); _alpm_log(PM_LOG_FLOW1, "looking for unsatisfied dependencies");
if((lp = checkdeps(db, trans->type, trans->packages)) != NULL) { if((lp = checkdeps(db, trans->type, trans->packages)) != NULL) {
@ -119,7 +119,7 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
FREELISTPTR(trans->packages); FREELISTPTR(trans->packages);
trans->packages = lp; trans->packages = lp;
TRANS_CB(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
} }
return(0); return(0);
@ -147,7 +147,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
info = (pmpkg_t*)targ->data; info = (pmpkg_t*)targ->data;
if(trans->type != PM_TRANS_TYPE_UPGRADE) { if(trans->type != PM_TRANS_TYPE_UPGRADE) {
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_START, info, NULL); EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
_alpm_log(PM_LOG_FLOW1, "removing package %s-%s", info->name, info->version); _alpm_log(PM_LOG_FLOW1, "removing package %s-%s", info->name, info->version);
/* run the pre-remove scriptlet if it exists */ /* run the pre-remove scriptlet if it exists */
@ -273,7 +273,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
} }
if(trans->type != PM_TRANS_TYPE_UPGRADE) { if(trans->type != PM_TRANS_TYPE_UPGRADE) {
TRANS_CB(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL); EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
alpm_logaction("removed %s (%s)", info->name, info->version); alpm_logaction("removed %s (%s)", info->name, info->version);
} }
} }

View file

@ -344,7 +344,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
trail = pm_list_new(); trail = pm_list_new();
/* Resolve targets dependencies */ /* Resolve targets dependencies */
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "resolving targets dependencies"); _alpm_log(PM_LOG_FLOW1, "resolving targets dependencies");
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
@ -362,10 +362,10 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
trans->packages = pm_list_add(trans->packages, sync); trans->packages = pm_list_add(trans->packages, sync);
} }
} }
TRANS_CB(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
/* check for inter-conflicts and whatnot */ /* check for inter-conflicts and whatnot */
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_START, NULL, NULL);
deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list); deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list);
if(deps) { if(deps) {
int found; int found;
@ -431,7 +431,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
RET_ERR(PM_ERR_CONFLICTING_DEPS, -1); RET_ERR(PM_ERR_CONFLICTING_DEPS, -1);
} }
} }
TRANS_CB(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
FREELISTPTR(list); FREELISTPTR(list);
FREELISTPTR(trail); FREELISTPTR(trail);
@ -511,7 +511,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
goto error; goto error;
} }
/* we want the frontend to be aware of commit details */ /* we want the frontend to be aware of commit details */
tr->cb = trans->cb; tr->cb_event = trans->cb_event;
if(trans_commit(tr) == -1) { if(trans_commit(tr) == -1) {
_alpm_log(PM_LOG_ERROR, "could not commit removal transaction"); _alpm_log(PM_LOG_ERROR, "could not commit removal transaction");
pm_errno = PM_ERR_XXX; pm_errno = PM_ERR_XXX;
@ -558,7 +558,7 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
goto error; goto error;
} }
/* we want the frontend to be aware of commit details */ /* we want the frontend to be aware of commit details */
tr->cb = trans->cb; tr->cb_event = trans->cb_event;
if(trans_commit(tr) == -1) { if(trans_commit(tr) == -1) {
_alpm_log(PM_LOG_ERROR, "could not commit transaction"); _alpm_log(PM_LOG_ERROR, "could not commit transaction");
pm_errno = PM_ERR_XXX; pm_errno = PM_ERR_XXX;

View file

@ -48,7 +48,7 @@ pmtrans_t *trans_new()
trans->packages = NULL; trans->packages = NULL;
trans->type = 0; trans->type = 0;
trans->flags = 0; trans->flags = 0;
trans->cb = NULL; trans->cb_event = NULL;
trans->state = STATE_IDLE; trans->state = STATE_IDLE;
return(trans); return(trans);
@ -75,7 +75,7 @@ void trans_free(pmtrans_t *trans)
free(trans); free(trans);
} }
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb cb) int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb_event event)
{ {
/* Sanity checks */ /* Sanity checks */
if(trans == NULL) { if(trans == NULL) {
@ -88,7 +88,7 @@ int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_t
trans->type = type; trans->type = type;
trans->flags = flags; trans->flags = flags;
trans->cb = cb; trans->cb_event = event;
trans->state = STATE_INITIALIZED; trans->state = STATE_INITIALIZED;
return(0); return(0);

View file

@ -36,7 +36,7 @@ typedef struct __pmtrans_t {
unsigned char state; unsigned char state;
PMList *targets; /* PMList of (char *) */ PMList *targets; /* PMList of (char *) */
PMList *packages; /* PMList of (pmpkg_t *) or (pmsyncpkg_t *) */ PMList *packages; /* PMList of (pmpkg_t *) or (pmsyncpkg_t *) */
alpm_trans_cb cb; alpm_trans_cb_event cb_event;
} pmtrans_t; } pmtrans_t;
#define FREETRANS(p) \ #define FREETRANS(p) \
@ -46,16 +46,16 @@ do { \
p = NULL; \ p = NULL; \
} \ } \
} while (0) } while (0)
#define TRANS_CB(t, e, d1, d2) \ #define EVENT(t, e, d1, d2) \
do { \ do { \
if((t) && (t)->cb) { \ if((t) && (t)->cb_event) { \
(t)->cb(e, d1, d2); \ (t)->cb_event(e, d1, d2); \
} \ } \
} while(0) } while(0)
pmtrans_t *trans_new(); pmtrans_t *trans_new();
void trans_free(pmtrans_t *trans); void trans_free(pmtrans_t *trans);
int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb cb); int trans_init(pmtrans_t *trans, unsigned char type, unsigned char flags, alpm_trans_cb_event event);
int trans_sysupgrade(pmtrans_t *trans); int trans_sysupgrade(pmtrans_t *trans);
int trans_addtarget(pmtrans_t *trans, char *target); int trans_addtarget(pmtrans_t *trans, char *target);
int trans_prepare(pmtrans_t *trans, PMList **data); int trans_prepare(pmtrans_t *trans, PMList **data);