aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-03-22 14:03:29 -0300
committerJoão Paulo Rechi Vita <jprvita@openbossa.org>2012-06-20 18:32:19 -0300
commit98e5bf8b98e1e0281639180dd377a66b0de3bf44 (patch)
treee021cf03af6bd005609c95453117ae79cb6846c9
parent83c72a8b4e0f45c196a8790d918e8698b7bcdfa0 (diff)
downloadbluez-98e5bf8b98e1e0281639180dd377a66b0de3bf44.tar.gz
bluez-98e5bf8b98e1e0281639180dd377a66b0de3bf44.tar.xz
bluez-98e5bf8b98e1e0281639180dd377a66b0de3bf44.zip
hog: Register ATTIO callbacks
This way the LE connection is kept up. Also set device to autoconnect.
-rw-r--r--Makefile.am2
-rw-r--r--input/hog_device.c141
-rw-r--r--input/hog_device.h3
-rw-r--r--input/manager.c4
4 files changed, 148 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 9a5d81d5..2fb5a2a3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -190,7 +190,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 00000000..687dc958
--- /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 a0158eab..ce6a79e0 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 8da9f641..01f83ce0 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -203,7 +203,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)
@@ -211,6 +211,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 = {