[PATCH 14/18] Add a Discover method to the GATT Client

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This methods allows users to actively start the discovery of characteristics
presents in a service.
---
 attrib/client.c |   40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/attrib/client.c b/attrib/client.c
index 21ce439..8dc5c79 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -497,15 +497,6 @@ static DBusMessage *unregister_watcher(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
-static GDBusMethodTable prim_methods[] = {
-	{ "GetCharacteristics",	"",	"a{oa{sv}}", get_characteristics},
-	{ "RegisterCharacteristicsWatcher",	"o", "",
-						register_watcher	},
-	{ "UnregisterCharacteristicsWatcher",	"o", "",
-						unregister_watcher	},
-	{ }
-};
-
 static DBusMessage *set_value(DBusConnection *conn, DBusMessage *msg,
 			DBusMessageIter *iter, struct characteristic *chr)
 {
@@ -971,21 +962,40 @@ fail:
 	g_free(current);
 }
 
-static void discover_all_char(gpointer data, gpointer user_data)
+static DBusMessage *discover_char(DBusConnection *conn, DBusMessage *msg,
+								void *data)
 {
-	struct query_data *qchr;
-	struct gatt_service *gatt = user_data;
 	struct primary *prim = data;
 	struct att_primary *att = prim->att;
+	struct gatt_service *gatt = prim->gatt;
+	struct query_data *qchr;
+	GError *gerr = NULL;
+
+	if (l2cap_connect(prim->gatt, &gerr, FALSE) < 0) {
+		DBusMessage *reply = btd_error_failed(msg, gerr->message);
+		g_error_free(gerr);
+		return reply;
+	}
 
 	qchr = g_new0(struct query_data, 1);
 	qchr->prim = prim;
 
-	gatt->attrib = g_attrib_ref(gatt->attrib);
 	gatt_discover_char(gatt->attrib, att->start, att->end,
 						char_discovered_cb, qchr);
+
+	return dbus_message_new_method_return(msg);
 }
 
+static GDBusMethodTable prim_methods[] = {
+	{ "GetCharacteristics",	"",	"a{oa{sv}}", get_characteristics},
+	{ "Discover",		"",	"",		discover_char	},
+	{ "RegisterCharacteristicsWatcher",	"o", "",
+						register_watcher	},
+	{ "UnregisterCharacteristicsWatcher",	"o", "",
+						unregister_watcher	},
+	{ }
+};
+
 static void register_primaries(struct gatt_service *gatt, GSList *primaries)
 {
 	GSList *l;
@@ -1031,10 +1041,6 @@ int attrib_client_register(struct btd_device *device, int psm)
 
 	register_primaries(gatt, primaries);
 
-	/* FIXME: just to avoid breaking the build */
-	if (FALSE)
-		discover_all_char(NULL, NULL);
-
 	gatt_services = g_slist_append(gatt_services, gatt);
 
 	return 0;
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux