From: "João Paulo Rechi Vita" <jprvita@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: claudio.takahasi@openbossa.org,
"João Paulo Rechi Vita" <jprvita@openbossa.org>
Subject: [RFC v2 02/16] HoG: register ATTIO callbacks
Date: Wed, 18 Apr 2012 19:08:10 -0300 [thread overview]
Message-ID: <1334786904-26282-3-git-send-email-jprvita@openbossa.org> (raw)
In-Reply-To: <1334786904-26282-1-git-send-email-jprvita@openbossa.org>
This way the LE connection is kept up. Also set device to autoconnect.
---
Makefile.am | 2 +-
input/hog_device.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++++++
input/hog_device.h | 3 +
input/manager.c | 4 +-
4 files changed, 148 insertions(+), 2 deletions(-)
create mode 100644 input/hog_device.c
diff --git a/Makefile.am b/Makefile.am
index 6e152f4..50777dc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -185,7 +185,7 @@ endif
if HOGPLUGIN
builtin_modules += hog
-builtin_sources += input/hog_device.h
+builtin_sources += input/hog_device.h input/hog_device.c
endif
if SERIALPLUGIN
diff --git a/input/hog_device.c b/input/hog_device.c
new file mode 100644
index 0000000..687dc95
--- /dev/null
+++ b/input/hog_device.c
@@ -0,0 +1,141 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2012 Marcel Holtmann <marcel@holtmann.org>
+ * Copyright (C) 2012 Instituto Nokia de Tecnologia - INdT
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include <bluetooth/bluetooth.h>
+
+#include <glib.h>
+
+#include "log.h"
+
+#include "../src/adapter.h"
+#include "../src/device.h"
+
+#include "hog_device.h"
+
+#include "gattrib.h"
+#include "attio.h"
+
+struct hog_device {
+ char *path;
+ struct btd_device *device;
+ GAttrib *attrib;
+ guint attioid;
+};
+
+static GSList *devices = NULL;
+
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+ struct hog_device *hogdev = user_data;
+
+ hogdev->attrib = g_attrib_ref(attrib);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+ struct hog_device *hogdev = user_data;
+
+ g_attrib_unref(hogdev->attrib);
+ hogdev->attrib = NULL;
+}
+
+static struct hog_device *find_device_by_path(GSList *list, const char *path)
+{
+ for (; list; list = list->next) {
+ struct hog_device *hogdev = list->data;
+
+ if (!strcmp(hogdev->path, path))
+ return hogdev;
+ }
+
+ return NULL;
+}
+
+static struct hog_device *hog_device_new(struct btd_device *device,
+ const char *path)
+{
+ struct hog_device *hogdev;
+
+ hogdev = g_new0(struct hog_device, 1);
+ if (!hogdev)
+ return NULL;
+
+ hogdev->path = g_strdup(path);
+ hogdev->device = btd_device_ref(device);
+
+ return hogdev;
+}
+
+int hog_device_register(struct btd_device *device, const char *path)
+{
+ struct hog_device *hogdev;
+
+ hogdev = find_device_by_path(devices, path);
+ if (hogdev)
+ return -EALREADY;
+
+ hogdev = hog_device_new(device, path);
+ if (!hogdev)
+ return -ENOMEM;
+
+ hogdev->attioid = btd_device_add_attio_callback(device,
+ attio_connected_cb,
+ attio_disconnected_cb,
+ hogdev);
+ device_set_auto_connect(device, TRUE);
+
+ devices = g_slist_append(devices, hogdev);
+
+ return 0;
+}
+
+static void hog_device_free(struct hog_device *hogdev)
+{
+ btd_device_unref(hogdev->device);
+ g_free(hogdev->path);
+ g_free(hogdev);
+}
+
+int hog_device_unregister(const char *path)
+{
+ struct hog_device *hogdev;
+
+ hogdev = find_device_by_path(devices, path);
+ if (hogdev == NULL)
+ return -EINVAL;
+
+ btd_device_remove_attio_callback(hogdev->device, hogdev->attioid);
+ devices = g_slist_remove(devices, hogdev);
+ hog_device_free(hogdev);
+
+ return 0;
+}
diff --git a/input/hog_device.h b/input/hog_device.h
index a0158ea..ce6a79e 100644
--- a/input/hog_device.h
+++ b/input/hog_device.h
@@ -23,3 +23,6 @@
*/
#define HOG_UUID "00001812-0000-1000-8000-00805f9b34fb"
+
+int hog_device_register(struct btd_device *device, const char *path);
+int hog_device_unregister(const char *path);
diff --git a/input/manager.c b/input/manager.c
index e1d1f81..3707e88 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -202,7 +202,7 @@ static int hog_device_probe(struct btd_device *device, GSList *uuids)
DBG("path %s", path);
- return 0;
+ return hog_device_register(device, path);
}
static void hog_device_remove(struct btd_device *device)
@@ -210,6 +210,8 @@ static void hog_device_remove(struct btd_device *device)
const gchar *path = device_get_path(device);
DBG("path %s", path);
+
+ hog_device_unregister(path);
}
static struct btd_device_driver hog_driver = {
--
1.7.7.6
next prev 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 ` João Paulo Rechi Vita [this message]
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 ` [RFC v2 15/16] HoG: Register only one notification callback João Paulo Rechi Vita
2012-04-20 19:31 ` 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-3-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).