summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-11-07 23:39:18 -0800
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-11-12 04:20:33 -0800
commit5a8da86bb274c3c665a7cf364335fe181f546132 (patch)
tree915a15a4810a1266d4d54812443117207f4d6f99 /binding
parent2c8ef7ac3c5dcf414b6e16feed5c20be20f9278b (diff)
binding: bluetooth-pbap: upgrade bluetooth binding calls to version 2.0guppy_6.99.3guppy_6.99.2guppy_6.99.1guppy/6.99.3guppy/6.99.2guppy/6.99.16.99.36.99.26.99.1
Bug-AGL: SPEC-1630 Change-Id: If9efc97fb5f89a31ca08eb1189156a3519475601 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/bluetooth-pbap-binding.c120
1 files changed, 81 insertions, 39 deletions
diff --git a/binding/bluetooth-pbap-binding.c b/binding/bluetooth-pbap-binding.c
index 953d73c..9d30ed6 100644
--- a/binding/bluetooth-pbap-binding.c
+++ b/binding/bluetooth-pbap-binding.c
@@ -540,25 +540,51 @@ static gboolean init_session(const gchar *address)
static gboolean is_pbap_dev_and_init(struct json_object *dev)
{
- struct json_object *name, *address, *hfp_connected;
- json_object_object_get_ex(dev, "Name", &name);
- json_object_object_get_ex(dev, "Address", &address);
- json_object_object_get_ex(dev, "HFPConnected", &hfp_connected);
- if (!g_strcmp0(json_object_get_string(hfp_connected), "True")) {
- if (init_session(json_object_get_string(address))) {
- struct json_object *event, *status;
- event = json_object_new_object();
+ struct json_object *jresp, *props = NULL, *val = NULL;
+ int i;
+
+ json_object_object_get_ex(dev, "properties", &props);
+ if (!props)
+ return FALSE;
+
+ json_object_object_get_ex(props, "connected", &val);
+ if (!val || !json_object_get_boolean(val))
+ return FALSE;
+
+ json_object_object_get_ex(props, "uuids", &val);
+ for (i = 0; i < json_object_array_length(val); i++) {
+ const char *uuid = json_object_get_string(json_object_array_get_idx(val, i));
+ const char *address = NULL;
+ struct json_object *val1 = NULL;
+
+ if (g_strcmp0(PBAP_UUID, uuid))
+ continue;
+
+ json_object_object_get_ex(props, "address", &val1);
+ address = json_object_get_string(val1);
+
+ if (!address)
+ return FALSE;
+
+ if (init_session(address)) {
+ jresp = json_object_new_object();
+
g_mutex_lock(&connected_mutex);
connected = TRUE;
- status = json_object_new_boolean(connected);
+ json_object_object_add(jresp, "connected",
+ json_object_new_boolean(connected));
g_mutex_unlock(&connected_mutex);
- json_object_object_add(event, "connected", status);
- afb_event_push(status_event, event);
- AFB_NOTICE("PBAP device connected: %s", json_object_get_string(address));
+
+ afb_event_push(status_event, jresp);
+
+ AFB_NOTICE("PBAP device connected: %s", address);
+
+ return TRUE;
}
+ break;
}
- return connected;
+ return FALSE;
}
static void discovery_result_cb(void *closure, struct json_object *result,
@@ -566,10 +592,10 @@ static void discovery_result_cb(void *closure, struct json_object *result,
afb_api_t api)
{
enum json_type type;
- struct json_object *dev, *tmp = NULL;
+ struct json_object *dev, *tmp;
int i;
- if (!json_object_object_get_ex(result, "list", &tmp))
+ if (!json_object_object_get_ex(result, "devices", &tmp))
return;
type = json_object_get_type(tmp);
@@ -588,11 +614,11 @@ static void init_bt(afb_api_t api)
struct json_object *args;
args = json_object_new_object();
- json_object_object_add(args , "value", json_object_new_string("connection"));
+ json_object_object_add(args , "value", json_object_new_string("device_changes"));
afb_api_call_sync(api, "Bluetooth-Manager", "subscribe", args, NULL, NULL, NULL);
args = json_object_new_object();
- afb_api_call(api, "Bluetooth-Manager", "discovery_result", args, discovery_result_cb, NULL);
+ afb_api_call(api, "Bluetooth-Manager", "managed_objects", args, discovery_result_cb, NULL);
}
static const afb_verb_t binding_verbs[] = {
@@ -637,38 +663,54 @@ static int init(afb_api_t api)
return ret;
}
+
static void process_connection_event(afb_api_t api, struct json_object *object)
{
- struct json_object *args, *status_obj, *address_obj;
- const char *status, *address;
+ struct json_object *jresp, *val = NULL, *props = NULL;
+ const char *action, *address;
+
+ json_object_object_get_ex(object, "action", &val);
+ if (!val)
+ return;
+ action = json_object_get_string(val);
+ if (g_strcmp0("changed", action))
+ return;
- json_object_object_get_ex(object, "Status", &status_obj);
- status = json_object_get_string(status_obj);
+ json_object_object_get_ex(object, "properties", &props);
+ if (!props)
+ return;
- if (!g_strcmp0(status, "connected")) {
- args = json_object_new_object();
+ json_object_object_get_ex(props, "connected", &val);
+ if (!val)
+ return;
- afb_api_call(api, "Bluetooth-Manager", "discovery_result",
+ if (json_object_get_boolean(val)) {
+ struct json_object *args = json_object_new_object();
+ afb_api_call(api, "Bluetooth-Manager", "managed_objects",
args, discovery_result_cb, NULL);
- } else if (!g_strcmp0(status, "disconnected")) {
- struct json_object *event, *status;
- event = json_object_new_object();
- g_mutex_lock(&connected_mutex);
- connected = FALSE;
- status = json_object_new_boolean(connected);
- g_mutex_unlock(&connected_mutex);
- json_object_object_add(event, "connected", status);
- afb_event_push(status_event, event);
- json_object_object_get_ex(object, "Address", &address_obj);
- address = json_object_get_string(address_obj);
- AFB_NOTICE("PBAP device disconnected: %s", address);
- } else
- AFB_ERROR("Unsupported connection status: %s\n", status);
+ return;
+ }
+
+ json_object_object_get_ex(props, "address", &val);
+ if (!val)
+ return;
+
+ address = json_object_get_string(val);
+ jresp = json_object_new_object();
+
+ g_mutex_lock(&connected_mutex);
+ connected = FALSE;
+ json_object_object_add(jresp, "connected", json_object_new_boolean(connected));
+ g_mutex_unlock(&connected_mutex);
+
+ afb_event_push(status_event, jresp);
+
+ AFB_NOTICE("PBAP device disconnected: %s", address);
}
static void onevent(afb_api_t api, const char *event, struct json_object *object)
{
- if (!g_strcmp0(event, "Bluetooth-Manager/connection"))
+ if (!g_ascii_strcasecmp(event, "Bluetooth-Manager/device_changes"))
process_connection_event(api, object);
else
AFB_ERROR("Unsupported event: %s\n", event);