Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=dc74987ec0e9b39c6cc39acd9230916519ac78d4

commit dc74987ec0e9b39c6cc39acd9230916519ac78d4
Author: Michel Hermier <herm...@frugalware.org>
Date:   Sun Jul 31 18:37:51 2011 +0200

trans.*: Pack callbacks in a pmtrans_cbs_t struct.

diff --git a/lib/libpacman/add.c b/lib/libpacman/add.c
index a5ab9b5..88447a0 100644
--- a/lib/libpacman/add.c
+++ b/lib/libpacman/add.c
@@ -372,7 +372,8 @@ int _pacman_add_commit(pmtrans_t *trans, pmlist_t **data)
if(tr == NULL) {
RET_ERR(PM_ERR_TRANS_ABORT, -1);
}
-                                       if(_pacman_trans_init(tr, 
PM_TRANS_TYPE_UPGRADE, trans->flags, NULL, NULL, NULL) == -1) {
+                                       pmtrans_cbs_t null_cbs = { NULL };
+                                       if(_pacman_trans_init(tr, 
PM_TRANS_TYPE_UPGRADE, trans->flags, null_cbs) == -1) {
FREETRANS(tr);
RET_ERR(PM_ERR_TRANS_ABORT, -1);
}
diff --git a/lib/libpacman/pacman.c b/lib/libpacman/pacman.c
index c4df011..cc23407 100644
--- a/lib/libpacman/pacman.c
+++ b/lib/libpacman/pacman.c
@@ -807,7 +807,13 @@ int pacman_trans_init(unsigned char type, unsigned int 
flags, pacman_trans_cb_ev
RET_ERR(PM_ERR_MEMORY, -1);
}

-       return(_pacman_trans_init(handle->trans, type, flags, event, conv, 
progress));
+       pmtrans_cbs_t cbs = {
+               .event = event,
+               .conv = conv,
+               .progress = progress
+       };
+
+       return(_pacman_trans_init(handle->trans, type, flags, cbs));
}

/** Search for packages to upgrade and add them to the transaction.
diff --git a/lib/libpacman/sync.c b/lib/libpacman/sync.c
index d018c4d..588d5a6 100644
--- a/lib/libpacman/sync.c
+++ b/lib/libpacman/sync.c
@@ -969,7 +969,7 @@ int _pacman_sync_commit(pmtrans_t *trans, pmlist_t **data)
goto error;
}

-       if(_pacman_trans_init(tr, PM_TRANS_TYPE_REMOVE, PM_TRANS_FLAG_NODEPS, 
trans->cb_event, trans->cb_conv, trans->cb_progress) == -1) {
+       if(_pacman_trans_init(tr, PM_TRANS_TYPE_REMOVE, PM_TRANS_FLAG_NODEPS, 
trans->cbs) == -1) {
_pacman_log(PM_LOG_ERROR, _("could not initialize the removal transaction"));
goto error;
}
@@ -995,7 +995,7 @@ int _pacman_sync_commit(pmtrans_t *trans, pmlist_t **data)
goto error;
}
/* we want the frontend to be aware of commit details */
-               tr->cb_event = trans->cb_event;
+               tr->cbs.event = trans->cbs.event;
if(_pacman_trans_commit(tr, NULL) == -1) {
_pacman_log(PM_LOG_ERROR, _("could not commit removal transaction"));
goto error;
@@ -1011,7 +1011,7 @@ int _pacman_sync_commit(pmtrans_t *trans, pmlist_t **data)
pm_errno = PM_ERR_MEMORY;
goto error;
}
-       if(_pacman_trans_init(tr, PM_TRANS_TYPE_UPGRADE, trans->flags | 
PM_TRANS_FLAG_NODEPS, trans->cb_event, trans->cb_conv, trans->cb_progress) == 
-1) {
+       if(_pacman_trans_init(tr, PM_TRANS_TYPE_UPGRADE, trans->flags | 
PM_TRANS_FLAG_NODEPS, trans->cbs) == -1) {
_pacman_log(PM_LOG_ERROR, _("could not initialize transaction"));
goto error;
}
diff --git a/lib/libpacman/trans.c b/lib/libpacman/trans.c
index 1b47d45..357444e 100644
--- a/lib/libpacman/trans.c
+++ b/lib/libpacman/trans.c
@@ -90,7 +90,7 @@ void _pacman_trans_free(pmtrans_t *trans)
free(trans);
}

-int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pacman_trans_cb_event event, pacman_trans_cb_conv conv, 
pacman_trans_cb_progress progress)
+int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pmtrans_cbs_t cbs)
{
/* Sanity checks */
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
@@ -117,9 +117,7 @@ int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t 
type, unsigned int flags,
trans->handle = handle;
trans->type = type;
trans->flags = flags;
-       trans->cb_event = event;
-       trans->cb_conv = conv;
-       trans->cb_progress = progress;
+       trans->cbs = cbs;
trans->state = STATE_INITIALIZED;

check_oldcache();
diff --git a/lib/libpacman/trans.h b/lib/libpacman/trans.h
index a546d8e..3b6f56b 100644
--- a/lib/libpacman/trans.h
+++ b/lib/libpacman/trans.h
@@ -44,6 +44,12 @@ typedef struct __pmtrans_ops_t {
int (*commit)(pmtrans_t *trans, pmlist_t **data);
} pmtrans_ops_t;

+typedef struct __pmtrans_cbs_t {
+       pacman_trans_cb_event event;
+       pacman_trans_cb_conv conv;
+       pacman_trans_cb_progress progress;
+} pmtrans_cbs_t;
+
struct __pmtrans_t {
pmhandle_t *handle;
pmtranstype_t type;
@@ -53,9 +59,7 @@ struct __pmtrans_t {
pmlist_t *targets;     /* pmlist_t of (char *) */
pmlist_t *packages;    /* pmlist_t of (pmpkg_t *) or (pmsyncpkg_t *) */
pmlist_t *skiplist;    /* pmlist_t of (char *) */
-       pacman_trans_cb_event cb_event;
-       pacman_trans_cb_conv cb_conv;
-       pacman_trans_cb_progress cb_progress;
+       pmtrans_cbs_t cbs;
};

#define FREETRANS(p) \
@@ -65,28 +69,31 @@ do { \
p = NULL; \
} \
} while (0)
-#define EVENT(t, e, d1, d2) \
+#define EVENT(_t, e, d1, d2) \
do { \
-       if((t) && (t)->cb_event) { \
-               (t)->cb_event(e, d1, d2); \
+       pmtrans_t *t = (_t); \
+       if(t && t->cbs.event) { \
+               t->cbs.event((e), (d1), (d2)); \
} \
} while(0)
-#define QUESTION(t, q, d1, d2, d3, r) \
+#define QUESTION(_t, q, d1, d2, d3, r) \
do { \
-       if((t) && (t)->cb_conv) { \
-               (t)->cb_conv(q, d1, d2, d3, r); \
+       pmtrans_t *t = (_t); \
+       if(t && t->cbs.conv) { \
+               t->cbs.conv((q), (d1), (d2), (d3), (r)); \
} \
} while(0)
-#define PROGRESS(t, e, p, per, h, r) \
+#define PROGRESS(_t, e, p, per, h, r) \
do { \
-       if((t) && (t)->cb_progress) { \
-               (t)->cb_progress(e, p, per, h, r); \
+       pmtrans_t *t = (_t); \
+       if(t && t->cbs.progress) { \
+               t->cbs.progress((e), (p), (per), (h), (r)); \
} \
} while(0)

pmtrans_t *_pacman_trans_new(void);
void _pacman_trans_free(pmtrans_t *trans);
-int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pacman_trans_cb_event event, pacman_trans_cb_conv conv, 
pacman_trans_cb_progress progress);
+int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pmtrans_cbs_t cbs);
int _pacman_trans_sysupgrade(pmtrans_t *trans);
int _pacman_trans_addtarget(pmtrans_t *trans, const char *target);
int _pacman_trans_prepare(pmtrans_t *trans, pmlist_t **data);
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to