mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-29 00:23:23 -05:00
[listener] Support passing multiple events in a single notify call
This commit is contained in:
parent
1e24b3656a
commit
8d130cdc7c
@ -873,7 +873,7 @@ cache_daap_update(void *arg, int *retval)
|
|||||||
|
|
||||||
/* Callback from filescanner thread */
|
/* Callback from filescanner thread */
|
||||||
static void
|
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);
|
commands_exec_async(cmdbase, cache_daap_update, NULL);
|
||||||
}
|
}
|
||||||
|
@ -719,12 +719,12 @@ playstatusupdate_cb(int fd, short what, void *arg)
|
|||||||
|
|
||||||
/* Thread: player */
|
/* Thread: player */
|
||||||
static void
|
static void
|
||||||
dacp_playstatus_update_handler(enum listener_event_type type)
|
dacp_playstatus_update_handler(short event_mask)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
// Only send status update on player change events
|
// Only send status update on player change events
|
||||||
if (type != LISTENER_PLAYER)
|
if (!(event_mask & LISTENER_PLAYER))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef HAVE_EVENTFD
|
#ifdef HAVE_EVENTFD
|
||||||
|
@ -185,7 +185,7 @@ streaming_send_cb(evutil_socket_t fd, short event, void *arg)
|
|||||||
|
|
||||||
// Thread: player (not fully thread safe, but hey...)
|
// Thread: player (not fully thread safe, but hey...)
|
||||||
static void
|
static void
|
||||||
player_change_cb(enum listener_event_type type)
|
player_change_cb(short event_mask)
|
||||||
{
|
{
|
||||||
streaming_player_changed = 1;
|
streaming_player_changed = 1;
|
||||||
}
|
}
|
||||||
|
@ -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 to watch the pipes. If no pipes in library, it will shut down
|
||||||
// the pipe thread.
|
// the pipe thread.
|
||||||
static void
|
static void
|
||||||
pipe_listener_cb(enum listener_event_type type)
|
pipe_listener_cb(short event_mask)
|
||||||
{
|
{
|
||||||
union pipe_arg *cmdarg;
|
union pipe_arg *cmdarg;
|
||||||
|
|
||||||
|
@ -28,18 +28,18 @@ enum listener_event_type
|
|||||||
LISTENER_LASTFM = (1 << 10),
|
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.
|
* Registers the given callback function to the given event types.
|
||||||
* This function is not thread safe. Listeners must be added once at startup.
|
* This function is not thread safe. Listeners must be added once at startup.
|
||||||
*
|
*
|
||||||
* @param notify_cb Callback function
|
* @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
|
* @return 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
listener_add(notify notify_cb, short events);
|
listener_add(notify notify_cb, short event_mask);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removes the given callback function
|
* Removes the given callback function
|
||||||
|
18
src/mpd.c
18
src/mpd.c
@ -4768,12 +4768,12 @@ mpd_notify_idle_client(struct mpd_client_ctx *client_ctx, short events)
|
|||||||
static enum command_state
|
static enum command_state
|
||||||
mpd_notify_idle(void *arg, int *retval)
|
mpd_notify_idle(void *arg, int *retval)
|
||||||
{
|
{
|
||||||
enum listener_event_type type;
|
short event_mask;
|
||||||
struct mpd_client_ctx *client;
|
struct mpd_client_ctx *client;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
type = *(enum listener_event_type *)arg;
|
event_mask = *(short *)arg;
|
||||||
DPRINTF(E_DBG, L_MPD, "Notify clients waiting for idle results: %d\n", type);
|
DPRINTF(E_DBG, L_MPD, "Notify clients waiting for idle results: %d\n", event_mask);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
client = mpd_clients;
|
client = mpd_clients;
|
||||||
@ -4781,7 +4781,7 @@ mpd_notify_idle(void *arg, int *retval)
|
|||||||
{
|
{
|
||||||
DPRINTF(E_DBG, L_MPD, "Notify client #%d\n", i);
|
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;
|
client = client->next;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@ -4791,14 +4791,14 @@ mpd_notify_idle(void *arg, int *retval)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 = (short *)malloc(sizeof(short));
|
||||||
*ptr = type;
|
*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);
|
commands_exec_async(cmdbase, mpd_notify_idle, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,10 +50,10 @@ static short write_events;
|
|||||||
|
|
||||||
/* Thread: library (the thread the event occurred) */
|
/* Thread: library (the thread the event occurred) */
|
||||||
static void
|
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
|
// Add event to the event mask, clients will be notified at the next break of the libwebsockets service loop
|
||||||
events |= type;
|
events |= event_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user