* [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
@ 2012-09-07 11:01 Bastien Nocera
0 siblings, 0 replies; 7+ messages in thread
From: Bastien Nocera @ 2012-09-07 11:01 UTC (permalink / raw)
To: linux-bluetooth
After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
battery. This is consistent with its behaviour on the PS3.
Original patch by Ruslan N. Marchenko <rufferson@gmail.com>
---
profiles/input/device.h | 1 +
profiles/input/fakehid.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/profiles/input/device.h b/profiles/input/device.h
index ff52967..d8baa2c 100644
--- a/profiles/input/device.h
+++ b/profiles/input/device.h
@@ -33,6 +33,7 @@ struct fake_input {
int uinput; /* uinput socket */
int rfcomm; /* RFCOMM socket */
uint8_t ch; /* RFCOMM channel number */
+ guint timeout_id; /* Disconnect timeout ID */
gboolean (*connect) (struct input_conn *iconn, GError **err);
int (*disconnect) (struct input_conn *iconn);
void *priv;
diff --git a/profiles/input/fakehid.c b/profiles/input/fakehid.c
index d9af2dd..b12c526 100644
--- a/profiles/input/fakehid.c
+++ b/profiles/input/fakehid.c
@@ -41,6 +41,9 @@
#include "fakehid.h"
#include "uinput.h"
+/* Timeout to get the PS3 remote disconnected, in seconds */
+#define PS3_REMOTE_TIMEOUT 10 * 60
+
enum ps3remote_special_keys {
PS3R_BIT_PS = 0,
PS3R_BIT_ENTER = 3,
@@ -138,6 +141,13 @@ static unsigned int ps3remote_keymap[] = {
[0xff] = KEY_MAX,
};
+static gboolean ps3_remote_timeout_cb(gpointer user_data);
+
+static void ps3remote_set_timeout(struct fake_input *fake)
+{
+ fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
+}
+
static int ps3remote_decode(char *buff, int size, unsigned int *value)
{
static unsigned int lastkey = 0;
@@ -200,6 +210,16 @@ error:
return -1;
}
+static gboolean
+ps3_remote_timeout_cb(gpointer user_data)
+{
+ struct fake_input *fake = (struct fake_input *) user_data;
+ input_device_request_disconnect(fake);
+ DBG("Disconnected PS3 BD Remote after timeout");
+ fake->timeout_id = 0;
+ return FALSE;
+}
+
static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
@@ -253,9 +273,17 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
goto failed;
}
+ if (fake->timeout_id > 0)
+ g_source_remove(fake->timeout_id);
+ ps3remote_set_timeout(fake);
+
return TRUE;
failed:
+ if (fake->timeout_id > 0) {
+ g_source_remove(fake->timeout_id);
+ fake->timeout_id = 0;
+ }
ioctl(fake->uinput, UI_DEV_DESTROY);
close(fake->uinput);
fake->uinput = -1;
@@ -315,6 +343,8 @@ static int ps3remote_setup_uinput(struct fake_input *fake,
goto err;
}
+ ps3remote_set_timeout(fake);
+
return 0;
err:
@@ -375,6 +405,8 @@ struct fake_input *fake_hid_connadd(struct fake_input *fake,
for (l = fake_hid->devices; l != NULL; l = l->next) {
old = l->data;
if (old->idev == fake->idev) {
+ if (fake->timeout_id > 0)
+ g_source_remove(fake->timeout_id);
g_free(fake);
fake = old;
fake_hid->connect(fake, NULL);
--
1.7.12
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
@ 2012-06-16 23:32 Bastien Nocera
2012-06-18 8:44 ` Luiz Augusto von Dentz
2012-06-29 14:50 ` Luiz Augusto von Dentz
0 siblings, 2 replies; 7+ messages in thread
From: Bastien Nocera @ 2012-06-16 23:32 UTC (permalink / raw)
To: linux-bluetooth
After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
battery. This is consistent with its behaviour on the PS3.
Original patch by Ruslan N. Marchenko <rufferson@gmail.com>
---
input/device.h | 1 +
input/fakehid.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/input/device.h b/input/device.h
index ff52967..d8baa2c 100644
--- a/input/device.h
+++ b/input/device.h
@@ -33,6 +33,7 @@ struct fake_input {
int uinput; /* uinput socket */
int rfcomm; /* RFCOMM socket */
uint8_t ch; /* RFCOMM channel number */
+ guint timeout_id; /* Disconnect timeout ID */
gboolean (*connect) (struct input_conn *iconn, GError **err);
int (*disconnect) (struct input_conn *iconn);
void *priv;
diff --git a/input/fakehid.c b/input/fakehid.c
index 3181538..a125356 100644
--- a/input/fakehid.c
+++ b/input/fakehid.c
@@ -44,6 +44,9 @@
#include "fakehid.h"
#include "uinput.h"
+/* Timeout to get the PS3 remote disconnected, in seconds */
+#define PS3_REMOTE_TIMEOUT 10 * 60
+
enum ps3remote_special_keys {
PS3R_BIT_PS = 0,
PS3R_BIT_ENTER = 3,
@@ -141,6 +144,20 @@ static unsigned int ps3remote_keymap[] = {
[0xff] = KEY_MAX,
};
+static gboolean ps3_remote_timeout_cb(gpointer user_data);
+
+static void ps3remote_set_timeout(struct fake_input *fake, gboolean enable)
+{
+ if (enable) {
+ fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
+ } else {
+ if (fake->timeout_id > 0) {
+ g_source_remove(fake->timeout_id);
+ fake->timeout_id = 0;
+ }
+ }
+}
+
static int ps3remote_decode(char *buff, int size, unsigned int *value)
{
static unsigned int lastkey = 0;
@@ -203,6 +220,16 @@ error:
return -1;
}
+static gboolean
+ps3_remote_timeout_cb(gpointer user_data)
+{
+ struct fake_input *fake = (struct fake_input *) user_data;
+ input_device_request_disconnect(fake);
+ DBG("Disconnected PS3 BD Remote after timeout");
+ fake->timeout_id = 0;
+ return FALSE;
+}
+
static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
gpointer data)
{
@@ -221,6 +248,9 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
goto failed;
}
+ /* Remove the old timeout */
+ ps3remote_set_timeout(fake, FALSE);
+
fd = g_io_channel_unix_get_fd(chan);
memset(buff, 0, sizeof(buff));
@@ -256,6 +286,8 @@ static gboolean ps3remote_event(GIOChannel *chan, GIOCondition cond,
goto failed;
}
+ ps3remote_set_timeout(fake, TRUE);
+
return TRUE;
failed:
@@ -318,6 +350,8 @@ static int ps3remote_setup_uinput(struct fake_input *fake,
goto err;
}
+ ps3remote_set_timeout(fake, TRUE);
+
return 0;
err:
@@ -378,6 +412,8 @@ struct fake_input *fake_hid_connadd(struct fake_input *fake,
for (l = fake_hid->devices; l != NULL; l = l->next) {
old = l->data;
if (old->idev == fake->idev) {
+ if (fake->timeout_id > 0)
+ g_source_remove(fake->timeout_id);
g_free(fake);
fake = old;
fake_hid->connect(fake, NULL);
--
1.7.10
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
2012-06-16 23:32 Bastien Nocera
@ 2012-06-18 8:44 ` Luiz Augusto von Dentz
2012-06-18 13:57 ` Bastien Nocera
2012-06-29 14:50 ` Luiz Augusto von Dentz
1 sibling, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-18 8:44 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth
Hi Bastien,
On Sun, Jun 17, 2012 at 2:32 AM, Bastien Nocera <hadess@hadess.net> wrote:
> After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
> battery. This is consistent with its behaviour on the PS3.
>
> Original patch by Ruslan N. Marchenko <rufferson@gmail.com>
> ---
> input/device.h | 1 +
> input/fakehid.c | 36 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/input/device.h b/input/device.h
> index ff52967..d8baa2c 100644
> --- a/input/device.h
> +++ b/input/device.h
> @@ -33,6 +33,7 @@ struct fake_input {
> int uinput; /* uinput socket */
> int rfcomm; /* RFCOMM socket */
> uint8_t ch; /* RFCOMM channel number */
> + guint timeout_id; /* Disconnect timeout ID */
> gboolean (*connect) (struct input_conn *iconn, GError **err);
> int (*disconnect) (struct input_conn *iconn);
> void *priv;
> diff --git a/input/fakehid.c b/input/fakehid.c
> index 3181538..a125356 100644
> --- a/input/fakehid.c
> +++ b/input/fakehid.c
> @@ -44,6 +44,9 @@
> #include "fakehid.h"
> #include "uinput.h"
>
> +/* Timeout to get the PS3 remote disconnected, in seconds */
> +#define PS3_REMOTE_TIMEOUT 10 * 60
> +
> enum ps3remote_special_keys {
> PS3R_BIT_PS = 0,
> PS3R_BIT_ENTER = 3,
> @@ -141,6 +144,20 @@ static unsigned int ps3remote_keymap[] = {
> [0xff] = KEY_MAX,
> };
>
> +static gboolean ps3_remote_timeout_cb(gpointer user_data);
> +
> +static void ps3remote_set_timeout(struct fake_input *fake, gboolean enable)
> +{
> + if (enable) {
> + fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
> + } else {
> + if (fake->timeout_id > 0) {
> + g_source_remove(fake->timeout_id);
> + fake->timeout_id = 0;
> + }
> + }
> +}
It doesn't really need to remove/add the timeout separately, upon
event just reset the idle timeout.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
2012-06-18 8:44 ` Luiz Augusto von Dentz
@ 2012-06-18 13:57 ` Bastien Nocera
2012-06-29 11:35 ` Johan Hedberg
0 siblings, 1 reply; 7+ messages in thread
From: Bastien Nocera @ 2012-06-18 13:57 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
On Mon, 2012-06-18 at 11:44 +0300, Luiz Augusto von Dentz wrote:
> Hi Bastien,
>
> On Sun, Jun 17, 2012 at 2:32 AM, Bastien Nocera <hadess@hadess.net> wrote:
> > After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
> > battery. This is consistent with its behaviour on the PS3.
> >
> > Original patch by Ruslan N. Marchenko <rufferson@gmail.com>
> > ---
> > input/device.h | 1 +
> > input/fakehid.c | 36 ++++++++++++++++++++++++++++++++++++
> > 2 files changed, 37 insertions(+)
> >
> > diff --git a/input/device.h b/input/device.h
> > index ff52967..d8baa2c 100644
> > --- a/input/device.h
> > +++ b/input/device.h
> > @@ -33,6 +33,7 @@ struct fake_input {
> > int uinput; /* uinput socket */
> > int rfcomm; /* RFCOMM socket */
> > uint8_t ch; /* RFCOMM channel number */
> > + guint timeout_id; /* Disconnect timeout ID */
> > gboolean (*connect) (struct input_conn *iconn, GError **err);
> > int (*disconnect) (struct input_conn *iconn);
> > void *priv;
> > diff --git a/input/fakehid.c b/input/fakehid.c
> > index 3181538..a125356 100644
> > --- a/input/fakehid.c
> > +++ b/input/fakehid.c
> > @@ -44,6 +44,9 @@
> > #include "fakehid.h"
> > #include "uinput.h"
> >
> > +/* Timeout to get the PS3 remote disconnected, in seconds */
> > +#define PS3_REMOTE_TIMEOUT 10 * 60
> > +
> > enum ps3remote_special_keys {
> > PS3R_BIT_PS = 0,
> > PS3R_BIT_ENTER = 3,
> > @@ -141,6 +144,20 @@ static unsigned int ps3remote_keymap[] = {
> > [0xff] = KEY_MAX,
> > };
> >
> > +static gboolean ps3_remote_timeout_cb(gpointer user_data);
> > +
> > +static void ps3remote_set_timeout(struct fake_input *fake, gboolean enable)
> > +{
> > + if (enable) {
> > + fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
> > + } else {
> > + if (fake->timeout_id > 0) {
> > + g_source_remove(fake->timeout_id);
> > + fake->timeout_id = 0;
> > + }
> > + }
> > +}
>
> It doesn't really need to remove/add the timeout separately, upon
> event just reset the idle timeout.
I don't understand what you're saying here.
Are you saying I should call g_source_remove, and then g_timeout_add()?
There's no functionality to change the interval for g_timeout_add*
functions.
The call is separate because it is used multiple times in the code (and
handling getting/setting in one place is cleaner).
By the way, the reason why it's handled this way is because the rest of
the input code relies on the kernel switching off the connection using
hidp_connadd_req->idle_to. fakehid doesn't use hidp.
Cheers
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
2012-06-18 13:57 ` Bastien Nocera
@ 2012-06-29 11:35 ` Johan Hedberg
2012-06-29 11:46 ` Bastien Nocera
0 siblings, 1 reply; 7+ messages in thread
From: Johan Hedberg @ 2012-06-29 11:35 UTC (permalink / raw)
To: Bastien Nocera; +Cc: Luiz Augusto von Dentz, linux-bluetooth
Hi Bastien,
On Mon, Jun 18, 2012, Bastien Nocera wrote:
> > It doesn't really need to remove/add the timeout separately, upon
> > event just reset the idle timeout.
>
> I don't understand what you're saying here.
>
> Are you saying I should call g_source_remove, and then g_timeout_add()?
> There's no functionality to change the interval for g_timeout_add*
> functions.
>
> The call is separate because it is used multiple times in the code (and
> handling getting/setting in one place is cleaner).
>
> By the way, the reason why it's handled this way is because the rest of
> the input code relies on the kernel switching off the connection using
> hidp_connadd_req->idle_to. fakehid doesn't use hidp.
Luiz told me that you had some IRC discussion about this and came to
some sort of consensus. Should I be expecting a new patch set?
Johan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
2012-06-29 11:35 ` Johan Hedberg
@ 2012-06-29 11:46 ` Bastien Nocera
0 siblings, 0 replies; 7+ messages in thread
From: Bastien Nocera @ 2012-06-29 11:46 UTC (permalink / raw)
To: Johan Hedberg; +Cc: Luiz Augusto von Dentz, linux-bluetooth
On Fri, 2012-06-29 at 14:35 +0300, Johan Hedberg wrote:
> Hi Bastien,
>
> On Mon, Jun 18, 2012, Bastien Nocera wrote:
> > > It doesn't really need to remove/add the timeout separately, upon
> > > event just reset the idle timeout.
> >
> > I don't understand what you're saying here.
> >
> > Are you saying I should call g_source_remove, and then g_timeout_add()?
> > There's no functionality to change the interval for g_timeout_add*
> > functions.
> >
> > The call is separate because it is used multiple times in the code (and
> > handling getting/setting in one place is cleaner).
> >
> > By the way, the reason why it's handled this way is because the rest of
> > the input code relies on the kernel switching off the connection using
> > hidp_connadd_req->idle_to. fakehid doesn't use hidp.
>
> Luiz told me that you had some IRC discussion about this and came to
> some sort of consensus. Should I be expecting a new patch set?
Have we? I didn't understand what changes he wanted me to do. So don't
expect any updated patches until he answers on the list.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins
2012-06-16 23:32 Bastien Nocera
2012-06-18 8:44 ` Luiz Augusto von Dentz
@ 2012-06-29 14:50 ` Luiz Augusto von Dentz
1 sibling, 0 replies; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2012-06-29 14:50 UTC (permalink / raw)
To: Bastien Nocera; +Cc: linux-bluetooth
Hi Bastien,
On Sun, Jun 17, 2012 at 2:32 AM, Bastien Nocera <hadess@hadess.net> wrote:
> After 10 minutes, disconnect the PS3 BD Remote to avoid draining its
> battery. This is consistent with its behaviour on the PS3.
>
> Original patch by Ruslan N. Marchenko <rufferson@gmail.com>
> ---
> input/device.h | 1 +
> input/fakehid.c | 36 ++++++++++++++++++++++++++++++++++++
> 2 files changed, 37 insertions(+)
>
> diff --git a/input/device.h b/input/device.h
> index ff52967..d8baa2c 100644
> --- a/input/device.h
> +++ b/input/device.h
> @@ -33,6 +33,7 @@ struct fake_input {
> int uinput; /* uinput socket */
> int rfcomm; /* RFCOMM socket */
> uint8_t ch; /* RFCOMM channel number */
> + guint timeout_id; /* Disconnect timeout ID */
> gboolean (*connect) (struct input_conn *iconn, GError **err);
> int (*disconnect) (struct input_conn *iconn);
> void *priv;
> diff --git a/input/fakehid.c b/input/fakehid.c
> index 3181538..a125356 100644
> --- a/input/fakehid.c
> +++ b/input/fakehid.c
> @@ -44,6 +44,9 @@
> #include "fakehid.h"
> #include "uinput.h"
>
> +/* Timeout to get the PS3 remote disconnected, in seconds */
> +#define PS3_REMOTE_TIMEOUT 10 * 60
> +
> enum ps3remote_special_keys {
> PS3R_BIT_PS = 0,
> PS3R_BIT_ENTER = 3,
> @@ -141,6 +144,20 @@ static unsigned int ps3remote_keymap[] = {
> [0xff] = KEY_MAX,
> };
>
> +static gboolean ps3_remote_timeout_cb(gpointer user_data);
> +
> +static void ps3remote_set_timeout(struct fake_input *fake, gboolean enable)
> +{
> + if (enable) {
> + fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT, ps3_remote_timeout_cb, fake);
> + } else {
> + if (fake->timeout_id > 0) {
> + g_source_remove(fake->timeout_id);
> + fake->timeout_id = 0;
> + }
> + }
> +}
What I suggested was to remove the enable parameter e.g:
if (fake->timeout_id > 0)
g_source_remove(fake->timeout_id);
fake->timeout_id = g_timeout_add_seconds(PS3_REMOTE_TIMEOUT,
ps3_remote_timeout_cb, fake);
Because you don't really need to have it disable at any point other
than when is not connected, basically you just reset the timer on
event, no need to have a parameter to disable the timer while
processing the events and reenable when done since it wont fire in the
middle of the processing.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-09-07 11:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-07 11:01 [PATCH 2/3] fakehid: Disconnect from PS3 remote after 10 mins Bastien Nocera
-- strict thread matches above, loose matches on Subject: below --
2012-06-16 23:32 Bastien Nocera
2012-06-18 8:44 ` Luiz Augusto von Dentz
2012-06-18 13:57 ` Bastien Nocera
2012-06-29 11:35 ` Johan Hedberg
2012-06-29 11:46 ` Bastien Nocera
2012-06-29 14:50 ` Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox