summaryrefslogtreecommitdiffstats
path: root/binding/bluetooth-pbap-binding.c
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2018-06-20 22:02:38 -0400
committerMatt Porter <mporter@konsulko.com>2018-06-20 22:02:38 -0400
commite31431b389c5a078058cf971c636608718180562 (patch)
treed3d9fe5d255f453f822be2678f0d52073d99803c /binding/bluetooth-pbap-binding.c
parent0446b890d9e36de48a7e2634bcecf36c3878f561 (diff)
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 <mporter@konsulko.com>
Diffstat (limited to 'binding/bluetooth-pbap-binding.c')
-rw-r--r--binding/bluetooth-pbap-binding.c26
1 files changed, 18 insertions, 8 deletions
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)