[listener] Support passing multiple events in a single notify call

This commit is contained in:
chme 2017-11-13 21:58:54 +01:00
parent 1e24b3656a
commit 8d130cdc7c
7 changed files with 19 additions and 19 deletions

View File

@ -873,7 +873,7 @@ cache_daap_update(void *arg, int *retval)
/* Callback from filescanner thread */
static void
cache_daap_listener_cb(enum listener_event_type type)
cache_daap_listener_cb(short event_mask)
{
commands_exec_async(cmdbase, cache_daap_update, NULL);
}

View File

@ -719,12 +719,12 @@ playstatusupdate_cb(int fd, short what, void *arg)
/* Thread: player */
static void
dacp_playstatus_update_handler(enum listener_event_type type)
dacp_playstatus_update_handler(short event_mask)
{
int ret;
// Only send status update on player change events
if (type != LISTENER_PLAYER)
if (!(event_mask & LISTENER_PLAYER))
return;
#ifdef HAVE_EVENTFD

View File

@ -185,7 +185,7 @@ streaming_send_cb(evutil_socket_t fd, short event, void *arg)
// Thread: player (not fully thread safe, but hey...)
static void
player_change_cb(enum listener_event_type type)
player_change_cb(short event_mask)
{
streaming_player_changed = 1;
}

View File

@ -764,7 +764,7 @@ pipelist_create(void)
// the pipe thread to watch the pipes. If no pipes in library, it will shut down
// the pipe thread.
static void
pipe_listener_cb(enum listener_event_type type)
pipe_listener_cb(short event_mask)
{
union pipe_arg *cmdarg;

View File

@ -28,18 +28,18 @@ enum listener_event_type
LISTENER_LASTFM = (1 << 10),
};
typedef void (*notify)(enum listener_event_type type);
typedef void (*notify)(short event_mask);
/*
* Registers the given callback function to the given event types.
* This function is not thread safe. Listeners must be added once at startup.
*
* @param notify_cb Callback function
* @param events Event mask, one or more of LISTENER_*
* @param event_mask Event mask, one or more of LISTENER_*
* @return 0 on success, -1 on failure
*/
int
listener_add(notify notify_cb, short events);
listener_add(notify notify_cb, short event_mask);
/*
* Removes the given callback function

View File

@ -4768,12 +4768,12 @@ mpd_notify_idle_client(struct mpd_client_ctx *client_ctx, short events)
static enum command_state
mpd_notify_idle(void *arg, int *retval)
{
enum listener_event_type type;
short event_mask;
struct mpd_client_ctx *client;
int i;
type = *(enum listener_event_type *)arg;
DPRINTF(E_DBG, L_MPD, "Notify clients waiting for idle results: %d\n", type);
event_mask = *(short *)arg;
DPRINTF(E_DBG, L_MPD, "Notify clients waiting for idle results: %d\n", event_mask);
i = 0;
client = mpd_clients;
@ -4781,7 +4781,7 @@ mpd_notify_idle(void *arg, int *retval)
{
DPRINTF(E_DBG, L_MPD, "Notify client #%d\n", i);
mpd_notify_idle_client(client, type);
mpd_notify_idle_client(client, event_mask);
client = client->next;
i++;
}
@ -4791,14 +4791,14 @@ mpd_notify_idle(void *arg, int *retval)
}
static void
mpd_listener_cb(enum listener_event_type type)
mpd_listener_cb(short event_mask)
{
enum listener_event_type *ptr;
short *ptr;
ptr = (enum listener_event_type *)malloc(sizeof(enum listener_event_type));
*ptr = type;
ptr = (short *)malloc(sizeof(short));
*ptr = event_mask;
DPRINTF(E_DBG, L_MPD, "Listener callback called with event type %d.\n", type);
DPRINTF(E_DBG, L_MPD, "Listener callback called with event type %d.\n", event_mask);
commands_exec_async(cmdbase, mpd_notify_idle, ptr);
}

View File

@ -50,10 +50,10 @@ static short write_events;
/* Thread: library (the thread the event occurred) */
static void
listener_cb(enum listener_event_type type)
listener_cb(short event_mask)
{
// Add event to the event mask, clients will be notified at the next break of the libwebsockets service loop
events |= type;
events |= event_mask;
}
/*