Send connection status upon event subscribe 69/14569/1 5.99.1 5.99.2 5.99.3 5.99.4 5.99.5 5.99.6 6.90.0 flounder/5.99.1 flounder/5.99.2 flounder/5.99.3 flounder/5.99.4 flounder/5.99.5 flounder/5.99.6 flounder_5.99.1 flounder_5.99.2 flounder_5.99.3 flounder_5.99.4 flounder_5.99.5 flounder_5.99.6 guppy/6.90.0 guppy_6.90.0
authorMatt Porter <mporter@konsulko.com>
Thu, 21 Jun 2018 02:02:38 +0000 (22:02 -0400)
committerMatt Porter <mporter@konsulko.com>
Thu, 21 Jun 2018 02:02:38 +0000 (22:02 -0400)
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>
binding/bluetooth-pbap-binding.c

index 73279be..28a90b2 100644 (file)
@@ -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)