From e8dd76c1c44567b917a7ff081d6ed80b8ef9f722 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 15 May 2017 12:59:55 -0700 Subject: binding: bluetooth: add support for avrcp metadata reporting Add binding support for reporting avrcp metadata, and status events. Bug-AGL: SPEC-596 Change-Id: I33a1045db5aa421a01e28c7bda254085b107e4f1 Signed-off-by: Matt Ranostay --- binding-bluetooth/bluetooth-api.c | 67 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) (limited to 'binding-bluetooth/bluetooth-api.c') diff --git a/binding-bluetooth/bluetooth-api.c b/binding-bluetooth/bluetooth-api.c index 520d9e2..31d179a 100644 --- a/binding-bluetooth/bluetooth-api.c +++ b/binding-bluetooth/bluetooth-api.c @@ -115,6 +115,65 @@ static int event_push(struct json_object *args, const char *tag) return e ? afb_event_push(e->event, json_object_get(args)) : -1; } +static json_object *new_json_object_parse_avrcp(struct btd_device *BDdevice, unsigned int filter) +{ + json_object *jresp = json_object_new_object(); + json_object *jstring = NULL; + + if (BD_AVRCP_TITLE & filter) + { + if (BDdevice->avrcp_title) + { + jstring = json_object_new_string(BDdevice->avrcp_title); + } + else + { + jstring = json_object_new_string(""); + } + json_object_object_add(jresp, "Title", jstring); + } + + if (BD_AVRCP_ARTIST & filter) + { + if (BDdevice->avrcp_artist) + { + jstring = json_object_new_string(BDdevice->avrcp_artist); + } + else + { + jstring = json_object_new_string(""); + } + json_object_object_add(jresp, "Artist", jstring); + } + + if (BD_AVRCP_STATUS & filter) + { + if (BDdevice->avrcp_status) + { + jstring = json_object_new_string(BDdevice->avrcp_status); + } + else + { + jstring = json_object_new_string(""); + } + json_object_object_add(jresp, "Status", jstring); + } + + if (BD_AVRCP_DURATION & filter) + { + json_object_object_add(jresp, "Duration", + json_object_new_int(BDdevice->avrcp_duration)); + } + + if (BD_AVRCP_POSITION & filter) + { + json_object_object_add(jresp, "Position", + json_object_new_int(BDdevice->avrcp_position)); + } + + return jresp; +} + /* create device json object*/ static json_object *new_json_object_from_device(struct btd_device *BDdevice, unsigned int filter) { @@ -186,6 +245,12 @@ static json_object *new_json_object_from_device(struct btd_device *BDdevice, uns jstring = (TRUE == BDdevice->avconnected) ? json_object_new_string("True"):json_object_new_string("False"); json_object_object_add(jresp, "AVPConnected", jstring); + + if (BDdevice->avconnected) + { + jstring = new_json_object_parse_avrcp(BDdevice, filter); + json_object_object_add(jresp, "Metadata", jstring); + } } if (BD_HFPCONNECTED & filter) @@ -638,7 +703,7 @@ void bt_broadcast_device_removed(struct btd_device *BDdevice) void bt_broadcast_device_properties_change(struct btd_device *BDdevice) { - unsigned int filter = BD_ADDER|BD_NAME|BD_PAIRED|BD_ACLCONNECTED|BD_AVCONNECTED|BD_HFPCONNECTED; + unsigned int filter = BD_ADDER|BD_NAME|BD_PAIRED|BD_ACLCONNECTED|BD_AVCONNECTED|BD_HFPCONNECTED|BD_AVRCP_TITLE|BD_AVRCP_ARTIST|BD_AVRCP_STATUS|BD_AVRCP_DURATION|BD_AVRCP_POSITION; int ret; json_object *jresp = new_json_object_from_device(BDdevice, filter); -- cgit 1.2.3-korg