mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
events: Make alpm_event_t an union of all event-specific struct
Signed-off-by: Olivier Brunel <jjk@jjacky.com> Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
f1fadecfb3
commit
8dbb80cfe9
@ -443,15 +443,10 @@ typedef enum _alpm_event_type_t {
|
|||||||
ALPM_EVENT_PACORIG_CREATED
|
ALPM_EVENT_PACORIG_CREATED
|
||||||
} alpm_event_type_t;
|
} alpm_event_type_t;
|
||||||
|
|
||||||
/** Events.
|
typedef struct _alpm_event_any_t {
|
||||||
* 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. */
|
/** Type of event. */
|
||||||
alpm_event_type_t type;
|
alpm_event_type_t type;
|
||||||
} alpm_event_t;
|
} alpm_event_any_t;
|
||||||
|
|
||||||
typedef enum _alpm_package_operation_t {
|
typedef enum _alpm_package_operation_t {
|
||||||
/** Package (to be) installed. (No oldpkg) */
|
/** Package (to be) installed. (No oldpkg) */
|
||||||
@ -563,6 +558,26 @@ typedef struct _alpm_event_pacorig_created_t {
|
|||||||
const char *file;
|
const char *file;
|
||||||
} alpm_event_pacorig_created_t;
|
} alpm_event_pacorig_created_t;
|
||||||
|
|
||||||
|
/** Events.
|
||||||
|
* This is an union passed to the callback, that allows the frontend to know
|
||||||
|
* which type of event was triggered (via type). It is then possible to
|
||||||
|
* typecast the pointer to the right structure, or use the union field, in order
|
||||||
|
* to access event-specific data. */
|
||||||
|
typedef union _alpm_event_t {
|
||||||
|
alpm_event_type_t type;
|
||||||
|
alpm_event_any_t any;
|
||||||
|
alpm_event_package_operation_t package_operation;
|
||||||
|
alpm_event_optdep_removal_t optdep_removal;
|
||||||
|
alpm_event_delta_patch_t delta_patch;
|
||||||
|
alpm_event_scriptlet_info_t scriptlet_info;
|
||||||
|
alpm_event_database_missing_t database_missing;
|
||||||
|
alpm_event_log_t log;
|
||||||
|
alpm_event_pkgdownload_t pkgdownload;
|
||||||
|
alpm_event_pacnew_created_t pacnew_created;
|
||||||
|
alpm_event_pacsave_created_t pacsave_created;
|
||||||
|
alpm_event_pacorig_created_t pacorig_created;
|
||||||
|
} alpm_event_t;
|
||||||
|
|
||||||
/** Event callback. */
|
/** Event callback. */
|
||||||
typedef void (*alpm_cb_event)(alpm_event_t *);
|
typedef void (*alpm_cb_event)(alpm_event_t *);
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_PACKAGE_OPERATION_START:
|
case ALPM_EVENT_PACKAGE_OPERATION_START:
|
||||||
if(config->noprogressbar) {
|
if(config->noprogressbar) {
|
||||||
alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event;
|
alpm_event_package_operation_t *e = &event->package_operation;
|
||||||
switch(e->operation) {
|
switch(e->operation) {
|
||||||
case ALPM_PACKAGE_INSTALL:
|
case ALPM_PACKAGE_INSTALL:
|
||||||
printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg));
|
printf(_("installing %s...\n"), alpm_pkg_get_name(e->newpkg));
|
||||||
@ -193,7 +193,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_PACKAGE_OPERATION_DONE:
|
case ALPM_EVENT_PACKAGE_OPERATION_DONE:
|
||||||
{
|
{
|
||||||
alpm_event_package_operation_t *e = (alpm_event_package_operation_t *) event;
|
alpm_event_package_operation_t *e = &event->package_operation;
|
||||||
switch(e->operation) {
|
switch(e->operation) {
|
||||||
case ALPM_PACKAGE_INSTALL:
|
case ALPM_PACKAGE_INSTALL:
|
||||||
display_optdepends(e->newpkg);
|
display_optdepends(e->newpkg);
|
||||||
@ -233,10 +233,9 @@ void cb_event(alpm_event_t *event)
|
|||||||
printf(_("applying deltas...\n"));
|
printf(_("applying deltas...\n"));
|
||||||
break;
|
break;
|
||||||
case ALPM_EVENT_DELTA_PATCH_START:
|
case ALPM_EVENT_DELTA_PATCH_START:
|
||||||
{
|
printf(_("generating %s with %s... "),
|
||||||
alpm_event_delta_patch_t *e = (alpm_event_delta_patch_t *) event;
|
event->delta_patch.delta->to,
|
||||||
printf(_("generating %s with %s... "), e->delta->to, e->delta->delta);
|
event->delta_patch.delta->delta);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case ALPM_EVENT_DELTA_PATCH_DONE:
|
case ALPM_EVENT_DELTA_PATCH_DONE:
|
||||||
printf(_("success!\n"));
|
printf(_("success!\n"));
|
||||||
@ -245,7 +244,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
printf(_("failed.\n"));
|
printf(_("failed.\n"));
|
||||||
break;
|
break;
|
||||||
case ALPM_EVENT_SCRIPTLET_INFO:
|
case ALPM_EVENT_SCRIPTLET_INFO:
|
||||||
fputs(((alpm_event_scriptlet_info_t *) event)->line, stdout);
|
fputs(event->scriptlet_info.line, stdout);
|
||||||
break;
|
break;
|
||||||
case ALPM_EVENT_RETRIEVE_START:
|
case ALPM_EVENT_RETRIEVE_START:
|
||||||
colon_printf(_("Retrieving packages ...\n"));
|
colon_printf(_("Retrieving packages ...\n"));
|
||||||
@ -257,7 +256,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_OPTDEP_REMOVAL:
|
case ALPM_EVENT_OPTDEP_REMOVAL:
|
||||||
{
|
{
|
||||||
alpm_event_optdep_removal_t *e = (alpm_event_optdep_removal_t *) event;
|
alpm_event_optdep_removal_t *e = &event->optdep_removal;
|
||||||
colon_printf(_("%s optionally requires %s\n"),
|
colon_printf(_("%s optionally requires %s\n"),
|
||||||
alpm_pkg_get_name(e->pkg),
|
alpm_pkg_get_name(e->pkg),
|
||||||
alpm_dep_compute_string(e->optdep));
|
alpm_dep_compute_string(e->optdep));
|
||||||
@ -267,12 +266,12 @@ void cb_event(alpm_event_t *event)
|
|||||||
if(!config->op_s_sync) {
|
if(!config->op_s_sync) {
|
||||||
pm_printf(ALPM_LOG_WARNING,
|
pm_printf(ALPM_LOG_WARNING,
|
||||||
"database file for '%s' does not exist\n",
|
"database file for '%s' does not exist\n",
|
||||||
((alpm_event_database_missing_t *) event)->dbname);
|
event->database_missing.dbname);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ALPM_EVENT_LOG:
|
case ALPM_EVENT_LOG:
|
||||||
{
|
{
|
||||||
alpm_event_log_t *e = (alpm_event_log_t *) event;
|
alpm_event_log_t *e = &event->log;
|
||||||
if(!e->fmt || strlen(e->fmt) == 0) {
|
if(!e->fmt || strlen(e->fmt) == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -290,7 +289,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_PACNEW_CREATED:
|
case ALPM_EVENT_PACNEW_CREATED:
|
||||||
{
|
{
|
||||||
alpm_event_pacnew_created_t *e = (alpm_event_pacnew_created_t *) event;
|
alpm_event_pacnew_created_t *e = &event->pacnew_created;
|
||||||
if(on_progress) {
|
if(on_progress) {
|
||||||
char *string = NULL;
|
char *string = NULL;
|
||||||
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"),
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s installed as %s.pacnew\n"),
|
||||||
@ -306,7 +305,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_PACSAVE_CREATED:
|
case ALPM_EVENT_PACSAVE_CREATED:
|
||||||
{
|
{
|
||||||
alpm_event_pacsave_created_t *e = (alpm_event_pacsave_created_t *) event;
|
alpm_event_pacsave_created_t *e = &event->pacsave_created;
|
||||||
if(on_progress) {
|
if(on_progress) {
|
||||||
char *string = NULL;
|
char *string = NULL;
|
||||||
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"),
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacsave\n"),
|
||||||
@ -322,7 +321,7 @@ void cb_event(alpm_event_t *event)
|
|||||||
break;
|
break;
|
||||||
case ALPM_EVENT_PACORIG_CREATED:
|
case ALPM_EVENT_PACORIG_CREATED:
|
||||||
{
|
{
|
||||||
alpm_event_pacorig_created_t *e = (alpm_event_pacorig_created_t *) event;
|
alpm_event_pacorig_created_t *e = &event->pacorig_created;
|
||||||
if(on_progress) {
|
if(on_progress) {
|
||||||
char *string = NULL;
|
char *string = NULL;
|
||||||
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
|
pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
|
||||||
|
Loading…
Reference in New Issue
Block a user