Skip to contentSkip to conversation

input: Implement idle timeout for fakehid

PATCH In review Jeff Hansen 2 participants 3 messages Aug 13, 2012 – Aug 14, 2012 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: Implement idle timeout for fakehid

(bump)

The batteries on my BD remote would die in a few days without this patch. The idle timeout needs to be enforced for fakehid devices as well as normal HID devices.

Quoted 1 line

From a96f67cb6268e34e677e5d288f2c3b89acfca7fe Mon Sep 17 00:00:00 2001

From: Jeff Hansen <[email protected]>
Date: Tue, 31 Jul 2012 22:45:23 -0600
Subject: [PATCH] input: Implement idle timeout for fakehid.

The batteries on my BD remote would die in a few days without this patch.

---
 input/device.c  |    6 ++++++
 input/device.h  |    4 ++++
 input/fakehid.c |   18 ++++++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
input/device.c +6 -0
index 0ab63c0..ae11a13 100644
@@ -609,6 +609,7 @@ static int hidp_add_connection(const struct input_device *idev,
 		fake->disconnect = fake_hid_disconnect;
 		fake->priv = fake_hid;
 		fake->idev = idev;
+		fake->timeout = iconn->timeout * 1000;
 		fake = fake_hid_connadd(fake, iconn->intr_io, fake_hid);
 		if (fake == NULL)
 			err = -ENOMEM;
@@ -1257,3 +1258,8 @@ int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst)
 
 	return 0;
 }
+
+void input_device_request_disconnect(const struct input_device *idev)
+{
+	device_request_disconnect(idev->device, NULL);
+}
input/device.h +4 -0
index 14c0f97..416cc9c 100644
@@ -40,6 +40,8 @@ struct fake_input {
 	int		(*disconnect) (struct input_conn *iconn);
 	void		*priv;
 	const struct input_device *idev;
+	guint		idle_timeout;
+	uint32_t	timeout;
 };
 
 int fake_input_register(DBusConnection *conn, struct btd_device *device,
@@ -54,3 +56,5 @@ int input_device_unregister(const char *path, const char *uuid);
 int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm,
 							GIOChannel *io);
 int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst);
+
+void input_device_request_disconnect(const struct input_device *idev);
input/fakehid.c +18 -0
index b809870..0407ae3 100644
@@ -208,6 +208,13 @@ error:
 	return -1;
 }
 
+static gboolean ps3remote_idle(gpointer data)
+{
+	struct fake_input *fake = data;
+	input_device_request_disconnect(fake->idev);
+	return FALSE;
+}
+
 static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
 				gpointer data)
 {
@@ -218,6 +225,13 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
 	char buff[50];
 	int fd;
 
+	if (fake->idle_timeout) {
+		g_source_remove(fake->idle_timeout);
+		fake->idle_timeout = 0;
+	}
+	if (fake->timeout)
+		fake->idle_timeout = g_timeout_add(fake->timeout, ps3remote_idle, fake);
+
 	if (cond & G_IO_NVAL)
 		return FALSE;
 
@@ -337,6 +351,10 @@ static gboolean fake_hid_common_connect(struct fake_input *fake, GError **err)
 
 static int fake_hid_common_disconnect(struct fake_input *fake)
 {
+	if (fake->idle_timeout) {
+		g_source_remove(fake->idle_timeout);
+		fake->idle_timeout = 0;
+	}
 	return 0;
 }
 
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 5 lines · Jeff Hansen

(bump)

The batteries on my BD remote would die in a few days without this patch. The idle timeout needs to be enforced for fakehid devices as well as normal HID devices.

Except that the timeout is disabled by default for HID devices. I posted a patch that requires a little bit of work to get pushed last month or so.

#2 lore raw
Quoted 10 lines · Bastien Nocera
Quoted 5 lines · Jeff Hansen

(bump)

The batteries on my BD remote would die in a few days without this patch. The idle timeout needs to be enforced for fakehid devices as well as normal HID devices.

Except that the timeout is disabled by default for HID devices. I posted a patch that requires a little bit of work to get pushed last month or so.

Yes, of course it is disabled by default (which I don't understand, but that's a separate issue). That is fine, but if a general timeout *is* specified by the user, it should carry into fakehid devices as well as normal HID devices.

Are there any bluez maintainers that can take a look at this patch? Anything that needs to change?

-Jeff

Signature · 3 lines
---------------------------------------------------
"If someone's gotta do it, it might as well be me."
                [email protected]