aboutsummaryrefslogtreecommitdiffstats
path: root/attrib/client.c
diff options
context:
space:
mode:
authorVinicius Costa Gomes <vinicius.gomes@openbossa.org>2010-07-27 15:17:08 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2010-08-09 18:06:47 -0400
commitdb3bf777b85503ab873ac5f057359e1eb912833a (patch)
treefd06f44f45cd993335bd47a04faab8e4ad9d1731 /attrib/client.c
parentdd5279755e9ba6f487e6c03eab621902f767c0bb (diff)
downloadbluez-db3bf777b85503ab873ac5f057359e1eb912833a.tar.gz
bluez-db3bf777b85503ab873ac5f057359e1eb912833a.tar.xz
bluez-db3bf777b85503ab873ac5f057359e1eb912833a.zip
Add support to storing the discoved GATT Services
This adds support to storing the discovered primary services so they can be loaded from storage later.
Diffstat (limited to 'attrib/client.c')
-rw-r--r--attrib/client.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/attrib/client.c b/attrib/client.c
index 5f167312..d984122d 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -35,6 +35,7 @@
#include "log.h"
#include "gdbus.h"
#include "btio.h"
+#include "storage.h"
#include "att.h"
#include "gattrib.h"
@@ -231,6 +232,46 @@ fail:
gatt_service_free(gatt);
}
+static char *primary_list_to_string(GSList *primary_list)
+{
+ GString *services;
+ GSList *l;
+
+ services = g_string_new(NULL);
+
+ for (l = primary_list; l; l = l->next) {
+ struct primary *primary = l->data;
+ uuid_t *uuid128;
+ char service[64];
+ char uuidstr[MAX_LEN_UUID_STR];
+
+ memset(service, 0, sizeof(service));
+
+ uuid128 = sdp_uuid_to_uuid128(primary->uuid);
+ sdp_uuid2strn(uuid128, uuidstr, MAX_LEN_UUID_STR);
+
+ bt_free(uuid128);
+
+ snprintf(service, sizeof(service), "%d#%d#%s ", primary->start,
+ primary->end, uuidstr);
+
+ services = g_string_append(services, service);
+ }
+
+ return g_string_free(services, FALSE);
+}
+
+static void store_primary_services(struct gatt_service *gatt)
+{
+ char *services;
+
+ services = primary_list_to_string(gatt->primary);
+
+ write_device_services(&gatt->sba, &gatt->dba, services);
+
+ g_free(services);
+}
+
static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
@@ -245,6 +286,9 @@ static void primary_cb(guint8 status, const guint8 *pdu, guint16 plen,
if (gatt->primary == NULL)
return;
+ store_primary_services(gatt);
+
+ /* Start Characteristic Discovery */
gatt->cur_prim = gatt->primary;
prim = gatt->cur_prim->data;