diff options
Diffstat (limited to 'binding')
-rw-r--r-- | binding/bluetooth-api.c | 12 | ||||
-rw-r--r-- | binding/bluetooth-api.h | 2 | ||||
-rw-r--r-- | binding/bluetooth-bluez.c | 16 |
3 files changed, 26 insertions, 4 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c index 33b5cac..49ae4e7 100644 --- a/binding/bluetooth-api.c +++ b/binding/bluetooth-api.c @@ -1367,9 +1367,10 @@ static void bluetooth_avrcp_controls(afb_req_t request) { struct bluetooth_state *ns = bluetooth_get_userdata(request); const char *action = afb_req_value(request, "action"); - gchar *device, *player; + gchar *device, *player = NULL; GVariant *reply; GError *error = NULL; + json_object *jval = NULL; if (!action) { afb_req_fail(request, "failed", "No action given"); @@ -1379,7 +1380,14 @@ static void bluetooth_avrcp_controls(afb_req_t request) device = return_bluez_path(request); if (device) { /* TODO: handle multiple players per device */ - player = g_strconcat(device, "/", BLUEZ_DEFAULT_PLAYER, NULL); + jval = bluez_get_property(ns, BLUEZ_AT_MEDIACONTROL, device, FALSE, "Player", NULL); + if (jval) { + player = (gchar *)json_object_get_string(jval); + json_object_put(jval); + jval = NULL; + } + if (!player) + player = g_strconcat(device, "/", BLUEZ_DEFAULT_PLAYER, NULL); g_free(device); } else { player = g_strdup(ns->mediaplayer_path); diff --git a/binding/bluetooth-api.h b/binding/bluetooth-api.h index a0b807b..aecbad0 100644 --- a/binding/bluetooth-api.h +++ b/binding/bluetooth-api.h @@ -35,6 +35,7 @@ #define BLUEZ_DEVICE_INTERFACE BLUEZ_SERVICE ".Device1" #define BLUEZ_MEDIAPLAYER_INTERFACE BLUEZ_SERVICE ".MediaPlayer1" #define BLUEZ_MEDIATRANSPORT_INTERFACE BLUEZ_SERVICE ".MediaTransport1" +#define BLUEZ_MEDIACONTROL_INTERFACE BLUEZ_SERVICE ".MediaControl1" #define BLUEZ_OBJECT_PATH "/" #define BLUEZ_PATH "/org/bluez" @@ -70,6 +71,7 @@ #define BLUEZ_AT_AGENTMANAGER "agent-manager" #define BLUEZ_AT_MEDIAPLAYER "mediaplayer" #define BLUEZ_AT_MEDIATRANSPORT "mediatransport" +#define BLUEZ_AT_MEDIACONTROL "mediacontrol" #define BLUEZ_DEFAULT_ADAPTER "hci0" #define BLUEZ_DEFAULT_PLAYER "player0" diff --git a/binding/bluetooth-bluez.c b/binding/bluetooth-bluez.c index 18194d5..de4bc0f 100644 --- a/binding/bluetooth-bluez.c +++ b/binding/bluetooth-bluez.c @@ -99,6 +99,12 @@ static const struct property_info mediatransport_props[] = { { }, }; +static const struct property_info mediacontrol_props[] = { + { .name = "Connected", .fmt = "b", }, + { .name = "Player", .fmt = "s", }, + { }, +}; + const struct property_info *bluez_get_property_info( const char *access_type, GError **error) { @@ -112,6 +118,8 @@ const struct property_info *bluez_get_property_info( pi = mediaplayer_props; else if (!strcmp(access_type, BLUEZ_AT_MEDIATRANSPORT)) pi = mediatransport_props; + else if (!strcmp(access_type, BLUEZ_AT_MEDIACONTROL)) + pi = mediacontrol_props; else g_set_error(error, NB_ERROR, NB_ERROR_ILLEGAL_ARGUMENT, "illegal %s argument", access_type); @@ -357,7 +365,8 @@ json_object *bluez_get_properties(struct bluetooth_state *ns, if (!strcmp(access_type, BLUEZ_AT_DEVICE) || !strcmp(access_type, BLUEZ_AT_MEDIAPLAYER) || !strcmp(access_type, BLUEZ_AT_MEDIATRANSPORT) || - !strcmp(access_type, BLUEZ_AT_ADAPTER)) { + !strcmp(access_type, BLUEZ_AT_ADAPTER) || + !strcmp(access_type, BLUEZ_AT_MEDIACONTROL)) { pi = bluez_get_property_info(access_type, error); if (!pi) @@ -380,6 +389,8 @@ json_object *bluez_get_properties(struct bluetooth_state *ns, interface2 = BLUEZ_MEDIATRANSPORT_INTERFACE; else if (!strcmp(access_type, BLUEZ_AT_ADAPTER)) interface2 = BLUEZ_ADAPTER_INTERFACE; + else if (!strcmp(access_type, BLUEZ_AT_MEDIACONTROL)) + interface2 = BLUEZ_MEDIACONTROL_INTERFACE; else if (!strcmp(access_type, BLUEZ_AT_OBJECT)) interface2 = NULL; else @@ -404,7 +415,8 @@ json_object *bluez_get_properties(struct bluetooth_state *ns, if (!strcmp(access_type, BLUEZ_AT_DEVICE) || !strcmp(access_type, BLUEZ_AT_MEDIAPLAYER) || !strcmp(access_type, BLUEZ_AT_MEDIATRANSPORT) || - !strcmp(access_type, BLUEZ_AT_ADAPTER)) { + !strcmp(access_type, BLUEZ_AT_ADAPTER) || + !strcmp(access_type, BLUEZ_AT_MEDIACONTROL)) { jprop = json_object_new_object(); g_variant_get(reply, "(a{sv})", &array); while (g_variant_iter_loop(array, "{sv}", &key, &var)) { |