linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: claudio.takahasi@openbossa.org
Subject: [RFC v2 15/16] HoG: Register only one notification callback
Date: Wed, 18 Apr 2012 19:08:23 -0300	[thread overview]
Message-ID: <1334786904-26282-16-git-send-email-jprvita@openbossa.org> (raw)
In-Reply-To: <1334786904-26282-1-git-send-email-jprvita@openbossa.org>

From: Claudio Takahasi <claudio.takahasi@openbossa.org>

Fix registering the notification callback per report. Only one instance
of GAttrib callback for all report notifications should be registered.
---
 input/hog_device.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/input/hog_device.c b/input/hog_device.c
index a522699..cfe8f03 100644
--- a/input/hog_device.c
+++ b/input/hog_device.c
@@ -68,6 +68,7 @@ struct hog_device {
 	struct btd_device	*device;
 	GAttrib			*attrib;
 	guint			attioid;
+	guint			report_cb_id;
 	struct gatt_primary	*hog_primary;
 	GSList			*reports;
 	int			uhid_fd;
@@ -111,8 +112,6 @@ static void report_value_cb(const uint8_t *pdu, uint16_t len, gpointer user_data
 static void report_ccc_written_cb(guint8 status, const guint8 *pdu,
 					guint16 plen, gpointer user_data)
 {
-	struct hog_device *hogdev = user_data;
-
 	if (status != 0) {
 		error("Write report characteristic descriptor failed: %s",
 							att_ecode2str(status));
@@ -120,9 +119,6 @@ static void report_ccc_written_cb(guint8 status, const guint8 *pdu,
 	}
 
 	DBG("Report characteristic descriptor written: notification enabled");
-
-	g_attrib_register(hogdev->attrib, ATT_OP_HANDLE_NOTIFY, report_value_cb,
-								hogdev, NULL);
 }
 
 static void write_ccc(uint16_t handle, gpointer user_data)
@@ -309,8 +305,14 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 		return;
 
 	hogdev->uhid_fd = open(UHID_DEVICE_FILE, O_RDWR | O_CLOEXEC);
-	if (hogdev->uhid_fd < 0)
+	if (hogdev->uhid_fd < 0) {
 		error("Failed to open UHID device: %s", strerror(errno));
+		return;
+	}
+
+	hogdev->report_cb_id = g_attrib_register(hogdev->attrib,
+					ATT_OP_HANDLE_NOTIFY, report_value_cb,
+					hogdev, NULL);
 }
 
 static void attio_disconnected_cb(gpointer user_data)
@@ -326,6 +328,9 @@ static void attio_disconnected_cb(gpointer user_data)
 	close(hogdev->uhid_fd);
 	hogdev->uhid_fd = -1;
 
+	g_attrib_unregister(hogdev->attrib, hogdev->report_cb_id);
+	hogdev->report_cb_id = 0;
+
 	g_attrib_unref(hogdev->attrib);
 	hogdev->attrib = NULL;
 }
-- 
1.7.7.6


  parent reply	other threads:[~2012-04-18 22:08 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-18 22:08 [RFC v2 00/16] HoG plugin João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 01/16] HoG: Register HID over GATT device driver João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 02/16] HoG: register ATTIO callbacks João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 03/16] HoG: load primary service handle João Paulo Rechi Vita
2012-04-20 17:52   ` Anderson Lizardo
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 04/16] HoG: discover all characteristics declaration João Paulo Rechi Vita
2012-04-19  1:23   ` Paulo Alcantara
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-20 18:06   ` Anderson Lizardo
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 05/16] HoG: discover descriptors for all characteristics João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 06/16] HoG: discover the "Report Map" characteristic João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 07/16] HoG: enable "Report" characteristic notification João Paulo Rechi Vita
2012-04-20 19:19   ` Anderson Lizardo
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 08/16] HoG: add report notification handler João Paulo Rechi Vita
2012-04-20 19:23   ` Anderson Lizardo
2012-04-26 19:43     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 09/16] HoG: HID I/O driver João Paulo Rechi Vita
2012-04-19  2:16   ` Paulo Alcantara
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 10/16] HoG: Use real values for vendor and product IDs João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 11/16] GATT: Add Report Reference Descriptor declaration João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 12/16] HoG: Add read Report Reference descriptor João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 13/16] GATT: Rename Characteristic Configuration constants João Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 14/16] GATT: Move GATT assigned numbers to GATT header João Paulo Rechi Vita
2012-04-18 22:08 ` João Paulo Rechi Vita [this message]
2012-04-20 19:31   ` [RFC v2 15/16] HoG: Register only one notification callback Anderson Lizardo
2012-04-26 19:43     ` Joao Paulo Rechi Vita
2012-04-18 22:08 ` [RFC v2 16/16] HoG: Prepend report id to the HID report João Paulo Rechi Vita
2012-04-19  2:45   ` Paulo Alcantara
2012-04-26 19:42     ` Joao Paulo Rechi Vita
2012-04-19  7:56 ` [RFC v2 00/16] HoG plugin Johan Hedberg
2012-04-20 17:01   ` Joao Paulo Rechi Vita
2012-04-19  9:45 ` Arik Nemtsov
2012-04-20 17:06   ` Joao Paulo Rechi Vita
     [not found]     ` <CANtih+-ssKaFugW1Ymo49gsoq1F9YQnFfH+dNKyCT67hXh7z8A@mail.gmail.com>
2012-04-20 18:44       ` Joao Paulo Rechi Vita

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=1334786904-26282-16-git-send-email-jprvita@openbossa.org \
    --to=jprvita@openbossa.org \
    --cc=claudio.takahasi@openbossa.org \
    --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).