From d2e0a671dff16409377ae8182e737bea8bcc724f Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Tue, 29 Jan 2019 18:20:52 -0800 Subject: binding: bluetooth-pbap: cache contacts list on connection Populating the contacts list can take several seconds for the OBEX transfer to complete. So to avoid phone UI delays service is started at startup, and populates a cached version of contacts for clients. Change-Id: I1687fc6bc075964b71be4515c5048bff1861b4ec Signed-off-by: Matt Ranostay --- binding/bluetooth-pbap-binding.c | 33 +++++++++++++++++++++++++++++++-- conf.d/wgt/config.xml.in | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/binding/bluetooth-pbap-binding.c b/binding/bluetooth-pbap-binding.c index 5a7c140..2765f61 100644 --- a/binding/bluetooth-pbap-binding.c +++ b/binding/bluetooth-pbap-binding.c @@ -39,6 +39,7 @@ static OrgBluezObexClient1 *client; static OrgBluezObexSession1 *session; static OrgBluezObexPhonebookAccess1 *phonebook; static GHashTable *xfer_queue; +static GMutex cached_mutex; static GMutex xfer_queue_mutex; static GHashTable *xfer_complete; static GMutex xfer_complete_mutex; @@ -47,6 +48,8 @@ static GMutex connected_mutex; static gboolean connected = FALSE; static afb_event_t status_event; +json_object *cached_results = NULL; + #define PBAP_UUID "0000112f-0000-1000-8000-00805f9b34fb" #define INTERNAL "int" @@ -314,11 +317,20 @@ void contacts(afb_req_t request) if (!parse_max_entries_parameter(request, &max_entries)) return; - org_bluez_obex_phonebook_access1_call_select_sync( + g_mutex_lock(&cached_mutex); + + if (max_entries == -1 && cached_results) { + jresp = cached_results; + json_object_get(jresp); + } else { + org_bluez_obex_phonebook_access1_call_select_sync( phonebook, INTERNAL, CONTACTS, NULL, NULL); - jresp = get_vcards(max_entries); + jresp = get_vcards(max_entries); + } afb_req_success(request, jresp, "contacts"); + + g_mutex_unlock(&cached_mutex); } void entry(afb_req_t request) @@ -602,6 +614,17 @@ static gboolean is_pbap_dev_and_init(struct json_object *dev) AFB_NOTICE("PBAP device connected: %s", address); + g_mutex_lock(&cached_mutex); + + if (cached_results) + json_object_put(cached_results); + + /* probably should be made async */ + org_bluez_obex_phonebook_access1_call_select_sync( + phonebook, INTERNAL, CONTACTS, NULL, NULL); + cached_results = get_vcards(-1); + g_mutex_unlock(&cached_mutex); + return TRUE; } break; @@ -728,6 +751,12 @@ static void process_connection_event(afb_api_t api, struct json_object *object) afb_event_push(status_event, jresp); + g_mutex_lock(&cached_mutex); + if (cached_results) + json_object_put(cached_results); + cached_results = NULL; + g_mutex_unlock(&cached_mutex); + AFB_NOTICE("PBAP device disconnected: %s", address); } diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in index 161a39f..21040c8 100644 --- a/conf.d/wgt/config.xml.in +++ b/conf.d/wgt/config.xml.in @@ -9,7 +9,7 @@ - + -- cgit 1.2.3-korg