Add events ALPM_EVENT_HOOK_{START,DONE}

Add events to let frontends know when hooks are being processed (and when it's
done), as that might be useful to update the UI.

Signed-off-by: Olivier Brunel <jjk@jjacky.com>
This commit is contained in:
Olivier Brunel 2015-12-06 18:35:37 +01:00 committed by Allan McRae
parent 3802cab563
commit 132ec4c3b9
4 changed files with 41 additions and 9 deletions

View File

@ -337,6 +337,16 @@ typedef struct _alpm_siglist_t {
alpm_sigresult_t *results; alpm_sigresult_t *results;
} alpm_siglist_t; } alpm_siglist_t;
/*
* Hooks
*/
typedef enum _alpm_hook_when_t {
ALPM_HOOK_PRE_TRANSACTION = 1,
ALPM_HOOK_POST_TRANSACTION
} alpm_hook_when_t;
/* /*
* Logging facilities * Logging facilities
*/ */
@ -443,7 +453,11 @@ typedef enum _alpm_event_type_t {
ALPM_EVENT_PACNEW_CREATED, ALPM_EVENT_PACNEW_CREATED,
/** A .pacsave file was created; See alpm_event_pacsave_created_t for /** A .pacsave file was created; See alpm_event_pacsave_created_t for
* arguments */ * arguments */
ALPM_EVENT_PACSAVE_CREATED ALPM_EVENT_PACSAVE_CREATED,
/** Processing hooks will be started. */
ALPM_EVENT_HOOK_START,
/** Processing hooks is finished. */
ALPM_EVENT_HOOK_DONE
} alpm_event_type_t; } alpm_event_type_t;
typedef struct _alpm_event_any_t { typedef struct _alpm_event_any_t {
@ -534,6 +548,13 @@ typedef struct _alpm_event_pacsave_created_t {
const char *file; const char *file;
} alpm_event_pacsave_created_t; } alpm_event_pacsave_created_t;
typedef struct _alpm_event_hook_t {
/** Type of event.*/
alpm_event_type_t type;
/** Type of hooks. */
alpm_hook_when_t when;
} alpm_event_hook_t;
/** Events. /** Events.
* This is an union passed to the callback, that allows the frontend to know * 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 * which type of event was triggered (via type). It is then possible to
@ -550,6 +571,7 @@ typedef union _alpm_event_t {
alpm_event_pkgdownload_t pkgdownload; alpm_event_pkgdownload_t pkgdownload;
alpm_event_pacnew_created_t pacnew_created; alpm_event_pacnew_created_t pacnew_created;
alpm_event_pacsave_created_t pacsave_created; alpm_event_pacsave_created_t pacsave_created;
alpm_event_hook_t hook;
} alpm_event_t; } alpm_event_t;
/** Event callback. */ /** Event callback. */

View File

@ -52,7 +52,7 @@ struct _alpm_hook_t {
alpm_list_t *depends; alpm_list_t *depends;
char **cmd; char **cmd;
alpm_list_t *matches; alpm_list_t *matches;
enum _alpm_hook_when_t when; alpm_hook_when_t when;
int abort_on_fail, needs_targets; int abort_on_fail, needs_targets;
}; };
@ -608,8 +608,9 @@ static int _alpm_hook_run_hook(alpm_handle_t *handle, struct _alpm_hook_t *hook)
} }
} }
int _alpm_hook_run(alpm_handle_t *handle, enum _alpm_hook_when_t when) int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when)
{ {
alpm_event_hook_t event = { .when = when };
alpm_list_t *i, *hooks = NULL, *hooks_triggered = NULL; alpm_list_t *i, *hooks = NULL, *hooks_triggered = NULL;
const char *suffix = ".hook"; const char *suffix = ".hook";
size_t suflen = strlen(suffix); size_t suflen = strlen(suffix);
@ -717,6 +718,9 @@ int _alpm_hook_run(alpm_handle_t *handle, enum _alpm_hook_when_t when)
} }
if(hooks_triggered != NULL) { if(hooks_triggered != NULL) {
event.type = ALPM_EVENT_HOOK_START;
EVENT(handle, &event);
for(i = hooks_triggered; i; i = i->next) { for(i = hooks_triggered; i; i = i->next) {
struct _alpm_hook_t *hook = i->data; struct _alpm_hook_t *hook = i->data;
_alpm_log(handle, ALPM_LOG_DEBUG, "running hook %s\n", hook->name); _alpm_log(handle, ALPM_LOG_DEBUG, "running hook %s\n", hook->name);
@ -726,6 +730,9 @@ int _alpm_hook_run(alpm_handle_t *handle, enum _alpm_hook_when_t when)
} }
alpm_list_free(hooks_triggered); alpm_list_free(hooks_triggered);
event.type = ALPM_EVENT_HOOK_DONE;
EVENT(handle, &event);
} }
cleanup: cleanup:

View File

@ -22,12 +22,7 @@
#include "alpm.h" #include "alpm.h"
enum _alpm_hook_when_t { int _alpm_hook_run(alpm_handle_t *handle, alpm_hook_when_t when);
ALPM_HOOK_PRE_TRANSACTION = 1,
ALPM_HOOK_POST_TRANSACTION
};
int _alpm_hook_run(alpm_handle_t *handle, enum _alpm_hook_when_t when);
#endif /* _ALPM_HOOK_H */ #endif /* _ALPM_HOOK_H */

View File

@ -167,6 +167,13 @@ void cb_event(alpm_event_t *event)
return; return;
} }
switch(event->type) { switch(event->type) {
case ALPM_EVENT_HOOK_START:
if(event->hook.when == ALPM_HOOK_PRE_TRANSACTION) {
colon_printf(_("Running pre-transaction hooks...\n"));
} else {
colon_printf(_("Running post-transaction hooks...\n"));
}
break;
case ALPM_EVENT_CHECKDEPS_START: case ALPM_EVENT_CHECKDEPS_START:
printf(_("checking dependencies...\n")); printf(_("checking dependencies...\n"));
break; break;
@ -329,6 +336,7 @@ void cb_event(alpm_event_t *event)
case ALPM_EVENT_DISKSPACE_DONE: case ALPM_EVENT_DISKSPACE_DONE:
case ALPM_EVENT_RETRIEVE_DONE: case ALPM_EVENT_RETRIEVE_DONE:
case ALPM_EVENT_RETRIEVE_FAILED: case ALPM_EVENT_RETRIEVE_FAILED:
case ALPM_EVENT_HOOK_DONE:
/* we can safely ignore those as well */ /* we can safely ignore those as well */
case ALPM_EVENT_PKGDOWNLOAD_START: case ALPM_EVENT_PKGDOWNLOAD_START:
case ALPM_EVENT_PKGDOWNLOAD_DONE: case ALPM_EVENT_PKGDOWNLOAD_DONE: