input: Implement idle timeout for fakehid.
PATCH 1/1 input: Implement idle timeout for fakehid.
The batteries on my BD remote would die in a few days without this patch. Now they've been going for weeks (hopefully months).
--- profiles/input/device.c | 6 ++++++ profiles/input/device.h | 4 ++++ profiles/input/fakehid.c | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 0 deletions(-)
profiles/input/device.c +6 -0
@@ -638,6 +638,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 ;
@@ -1307,3 +1308,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 ); +}
profiles/input/device.h +4 -0
@@ -37,6 +37,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,
@@ -49,3 +51,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);
profiles/input/fakehid.c +18 -0
@@ -199,6 +199,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) {
@@ -209,6 +216,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;
@@ -328,6 +342,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
Hi Jeff,
profiles/input/device.c static int hidp_add_connection(const struct input_device *idev, · line 641
Quoted 1 line · Jeff Hansen
profiles/input/device.c +1
-0+ fake->timeout = iconn->timeout *1000 ;
Why not use the original iconn->timeout value and then use g_timeout_add_seconds instead of g_timeout_add?
profiles/input/device.h struct fake_input { · line 41
Quoted 2 lines
profiles/input/device.h +2
-0+guint idle_timeout; +uint32_t timeout;
Why uint32_t instead of just int that iconn->timeout is?
profiles/input/fakehid.c error: · line 207
Quoted 6 lines
profiles/input/fakehid.c +6
-0+static gboolean ps3remote_idle (gpointer data) +{ +struct fake_input *fake = data; +input_device_request_disconnect (fake->idev); +return FALSE; +}
Could you add an empty line before and after input_device_request_disconnect for slightly better readability.
Review
Quoted 1 line
(quoted diff) +1
-0+ if (fake->idle_timeout) {
For consistency with the rest of the code base please use > 0 for checking for valid GSource IDs. I'd also just call it idle_id to avoid confusion with "timeout" which is not a GSource ID.
profiles/input/fakehid.c static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond, · line 224
Quoted 5 lines
profiles/input/fakehid.c +5
-0+g_source_remove (fake->idle_timeout); + fake->idle_timeout =0 ; + } +if (fake->timeout) + fake->idle_timeout =g_timeout_add (fake->timeout, ps3remote_idle, fake);
Please add an empty line before this second if statement and also do > 0 here.
Review
Quoted 1 line
(quoted diff) +1
-0+ if (fake->idle_timeout) {
And > 0 again here.
Johan