From e31431b389c5a078058cf971c636608718180562 Mon Sep 17 00:00:00 2001 From: Matt Porter Date: Wed, 20 Jun 2018 22:02:38 -0400 Subject: Send connection status upon event subscribe When the status event is subscribed, immediately send the current PBAP connection status. Bug-AGL: SPEC-1519 Change-Id: I222789f81040c80fb67dac63c889c96586ba0dbd Signed-off-by: Matt Porter --- binding/bluetooth-pbap-binding.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'binding') diff --git a/binding/bluetooth-pbap-binding.c b/binding/bluetooth-pbap-binding.c index 73279be..28a90b2 100644 --- a/binding/bluetooth-pbap-binding.c +++ b/binding/bluetooth-pbap-binding.c @@ -443,16 +443,26 @@ static void status(struct afb_req request) static void subscribe(struct afb_req request) { const char *value = afb_req_value(request, "value"); - if (value) { - if (!g_strcmp0(value, "status")) { - afb_req_subscribe(request, status_event); - } else { - afb_req_fail(request, "failed", "Invalid event"); - return; - } + + if (!value) { + afb_req_fail(request, "failed", "No event"); + return; } - afb_req_success(request, NULL, NULL); + if (!g_strcmp0(value, "status")) { + afb_req_subscribe(request, status_event); + afb_req_success(request, NULL, NULL); + + struct json_object *event, *status; + event = json_object_new_object(); + g_mutex_lock(&connected_mutex); + status = json_object_new_boolean(connected); + g_mutex_unlock(&connected_mutex); + json_object_object_add(event, "connected", status); + afb_event_push(status_event, event); + } else { + afb_req_fail(request, "failed", "Invalid event"); + } } static void unsubscribe(struct afb_req request) -- cgit 1.2.3-korg