diff --git a/src/listener.h b/src/listener.h index ae0b995f..83bb2967 100644 --- a/src/listener.h +++ b/src/listener.h @@ -20,6 +20,8 @@ enum listener_event_type LISTENER_STORED_PLAYLIST = (1 << 6), /* A library update has started or finished */ LISTENER_UPDATE = (1 << 7), + /* A pairing request has started or finished */ + LISTENER_PAIRING = (1 << 8), }; typedef void (*notify)(enum listener_event_type type); diff --git a/src/remote_pairing.c b/src/remote_pairing.c index 9d5fd9b8..047d0137 100644 --- a/src/remote_pairing.c +++ b/src/remote_pairing.c @@ -56,6 +56,7 @@ #include "misc.h" #include "db.h" #include "remote_pairing.h" +#include "listener.h" struct remote_info { @@ -70,8 +71,6 @@ struct remote_info { char *v6_address; struct evhttp_connection *evcon; - - struct remote_info *next; }; @@ -613,6 +612,7 @@ pairing_cb(int fd, short event, void *arg) CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&remote_lck)); + listener_notify(LISTENER_PAIRING); event_add(pairingev, NULL); } @@ -710,6 +710,8 @@ touch_remote_cb(const char *name, const char *type, const char *domain, const ch CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&remote_lck)); } + + listener_notify(LISTENER_PAIRING); } /* Thread: filescanner, mpd */ @@ -736,6 +738,31 @@ remote_pairing_kickoff(char **arglist) CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&remote_lck)); } +/* + * Returns the remote name of the current active pairing request as an allocated string (needs to be freed by the caller) + * or NULL in case there is no active pairing request. + * + * Thread: httpd + */ +char * +remote_pairing_get_name(void) +{ + char *remote_name; + + DPRINTF(E_DBG, L_REMOTE, "Get pairing remote name\n"); + + CHECK_ERR(L_REMOTE, pthread_mutex_lock(&remote_lck)); + + if (remote_info) + remote_name = strdup(remote_info->pi.name); + else + remote_name = NULL; + + CHECK_ERR(L_REMOTE, pthread_mutex_unlock(&remote_lck)); + + return remote_name; +} + /* Thread: main */ int diff --git a/src/remote_pairing.h b/src/remote_pairing.h index 6a34d29f..64ac1bd6 100644 --- a/src/remote_pairing.h +++ b/src/remote_pairing.h @@ -5,6 +5,9 @@ void remote_pairing_kickoff(char **arglist); +char * +remote_pairing_get_name(void); + int remote_pairing_init(void);