linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: chen.ganir@ti.com
To: linux-bluetooth@vger.kernel.org
Cc: Chen Ganir <chen.ganir@ti.com>
Subject: [PATCH v3 2/5] DeviceInfo: Add connection logic
Date: Wed, 28 Mar 2012 17:26:42 +0200	[thread overview]
Message-ID: <1332948405-1104-3-git-send-email-chen.ganir@ti.com> (raw)
In-Reply-To: <1332948405-1104-1-git-send-email-chen.ganir@ti.com>

From: Chen Ganir <chen.ganir@ti.com>

Add connection logic to the Device Information Plugin. When the
driver is loaded, it will request a connection to the remote device
and release the connection request when destroyed.
---
 deviceinfo/deviceinfo.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/deviceinfo/deviceinfo.c b/deviceinfo/deviceinfo.c
index 95e7f1d..8624a31 100644
--- a/deviceinfo/deviceinfo.c
+++ b/deviceinfo/deviceinfo.c
@@ -29,13 +29,18 @@
 #include <bluetooth/uuid.h>
 #include "adapter.h"
 #include "device.h"
+#include "gattrib.h"
+#include "attio.h"
 #include "att.h"
 #include "gattrib.h"
 #include "gatt.h"
 #include "deviceinfo.h"
 
+
 struct deviceinfo {
 	struct btd_device	*dev;		/* Device reference */
+	GAttrib			*attrib;		/* GATT connection */
+	guint			attioid;		/* Att watcher id */
 };
 
 static GSList *deviceinfoservers = NULL;
@@ -44,6 +49,12 @@ static void deviceinfo_free(gpointer user_data)
 {
 	struct deviceinfo *d = user_data;
 
+	if (d->attioid > 0)
+		btd_device_remove_attio_callback(d->dev, d->attioid);
+
+	if (d->attrib != NULL)
+		g_attrib_unref(d->attrib);
+
 	btd_device_unref(d->dev);
 	g_free(d);
 }
@@ -59,6 +70,21 @@ static gint cmp_device(gconstpointer a, gconstpointer b)
 	return -1;
 }
 
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+	struct deviceinfo *d = user_data;
+
+	d->attrib = g_attrib_ref(attrib);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+	struct deviceinfo *d = user_data;
+
+	g_attrib_unref(d->attrib);
+	d->attrib = NULL;
+}
+
 int deviceinfo_register(struct btd_device *device)
 {
 	struct deviceinfo *d;
@@ -68,6 +94,8 @@ int deviceinfo_register(struct btd_device *device)
 
 	deviceinfoservers = g_slist_prepend(deviceinfoservers, d);
 
+	d->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
+						attio_disconnected_cb, d);
 	return 0;
 }
 
-- 
1.7.4.1


  parent reply	other threads:[~2012-03-28 15:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-28 15:26 [PATCH v3 0/5] Add DeviceInformationService plugin chen.ganir
2012-03-28 15:26 ` [PATCH v3 1/5] Add DeviceInformation GATT Client chen.ganir
2012-03-29 10:15   ` Johan Hedberg
2012-03-28 15:26 ` chen.ganir [this message]
2012-03-28 15:26 ` [PATCH v3 3/5] DeviceInfo: Discover Characteristics chen.ganir
2012-03-29 10:18   ` Johan Hedberg
2012-03-28 15:26 ` [PATCH v3 4/5] Fix device version in GetProperties chen.ganir
2012-03-29 10:19   ` Johan Hedberg
2012-03-28 15:26 ` [PATCH v3 5/5] DeviceInfo: Read PNP ID chen.ganir
2012-03-29 10:22   ` Johan Hedberg
2012-03-29 10:45     ` Anderson Lizardo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1332948405-1104-3-git-send-email-chen.ganir@ti.com \
    --to=chen.ganir@ti.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).