* [PATCH 1/3] Add mode callback to btd_adapter
@ 2010-08-13 9:18 Daniel Örstadius
2010-08-13 12:41 ` Johan Hedberg
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-13 9:18 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 346 bytes --]
With this patch callback functions can be registered to the
btd_adapter struct. The functions are then called when the powered
state of the adapter changes, with a boolean argument indicating
the new state. The reason for adding the functionality is that the
Maemo6 MCE plugin needs to be notified when the adapter is powered
on or off.
/Daniel
[-- Attachment #2: 0001-Add-mode-callback-to-btd_adapter.patch --]
[-- Type: text/x-patch, Size: 2710 bytes --]
From 489843b65a43773d678bdfe5a3669e3408fdaccc Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Fri, 13 Aug 2010 10:30:37 +0300
Subject: [PATCH] Add mode callback to btd_adapter
With this patch callback functions can be registered to the
btd_adapter struct. The functions are then called when the powered
state of the adapter changes, with a boolean argument indicating
the new state. The reason for adding the functionality is that the
Maemo6 MCE plugin needs to be notified when the adapter is powered
on or off.
---
src/adapter.c | 25 +++++++++++++++++++++++++
src/adapter.h | 4 ++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index fc1e123..ff78539 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -135,6 +135,8 @@ struct btd_adapter {
gboolean cache_enable;
gint ref;
+
+ GSList *mode_callbacks;
};
static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -2203,6 +2205,18 @@ static void adapter_disable_cod_cache(struct btd_adapter *adapter)
adapter->pending_cod = adapter->wanted_cod;
}
+static void adapter_mode_callbacks(struct btd_adapter *adapter,
+ gboolean powered)
+{
+ GSList *l;
+
+ for (l = adapter->mode_callbacks; l; l = l->next) {
+ btd_adapter_mode_cb cb = l->data;
+
+ cb(adapter, powered);
+ }
+}
+
static int adapter_up(struct btd_adapter *adapter, const char *mode)
{
char srcaddr[18];
@@ -2283,6 +2297,8 @@ proceed:
ADAPTER_INTERFACE, "Powered",
DBUS_TYPE_BOOLEAN, &powered);
+ adapter_mode_callbacks(adapter, TRUE);
+
adapter_disable_cod_cache(adapter);
return 0;
@@ -2487,6 +2503,8 @@ int adapter_stop(struct btd_adapter *adapter)
adapter->cache_enable = TRUE;
adapter->pending_cod = 0;
+ adapter_mode_callbacks(adapter, FALSE);
+
info("Adapter %s has been disabled", adapter->path);
return 0;
@@ -3422,3 +3440,10 @@ int adapter_ops_setup(void)
return adapter_ops->setup();
}
+
+void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
+ btd_adapter_mode_cb cb)
+{
+ adapter->mode_callbacks =
+ g_slist_append(adapter->mode_callbacks, cb);
+}
diff --git a/src/adapter.h b/src/adapter.h
index a7eca0e..9c7cdf2 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -188,3 +188,7 @@ struct btd_adapter_ops {
int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
void btd_adapter_cleanup_ops(struct btd_adapter_ops *btd_adapter_ops);
int adapter_ops_setup(void);
+typedef void (*btd_adapter_mode_cb) (struct btd_adapter *adapter,
+ gboolean powered);
+void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
+ btd_adapter_mode_cb cb);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] Add mode callback to btd_adapter
2010-08-13 9:18 [PATCH 1/3] Add mode callback to btd_adapter Daniel Örstadius
@ 2010-08-13 12:41 ` Johan Hedberg
2010-08-13 13:43 ` Daniel Örstadius
0 siblings, 1 reply; 4+ messages in thread
From: Johan Hedberg @ 2010-08-13 12:41 UTC (permalink / raw)
To: Daniel Örstadius; +Cc: linux-bluetooth
Hi Daniel,
On Fri, Aug 13, 2010, Daniel Örstadius wrote:
> +typedef void (*btd_adapter_mode_cb) (struct btd_adapter *adapter,
> + gboolean powered);
> +void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
> + btd_adapter_mode_cb cb);
In general this seems fine, but I think for completeness there should
also be a unregister function. Also, since we've traditionally used the
term mode to include also the discoverable state the name should
probably be something like btd_adapter_register_powered_callback and
btd_adapter_powered_cb.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] Add mode callback to btd_adapter
2010-08-13 12:41 ` Johan Hedberg
@ 2010-08-13 13:43 ` Daniel Örstadius
2010-08-17 8:28 ` Johan Hedberg
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Örstadius @ 2010-08-13 13:43 UTC (permalink / raw)
To: linux-bluetooth
[-- Attachment #1: Type: text/plain, Size: 846 bytes --]
On Fri, Aug 13, 2010 at 3:41 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote:
> On Fri, Aug 13, 2010, Daniel Örstadius wrote:
>> +typedef void (*btd_adapter_mode_cb) (struct btd_adapter *adapter,
>> + gboolean powered);
>> +void btd_adapter_register_mode_callback(struct btd_adapter *adapter,
>> + btd_adapter_mode_cb cb);
>
> In general this seems fine, but I think for completeness there should
> also be a unregister function. Also, since we've traditionally used the
> term mode to include also the discoverable state the name should
> probably be something like btd_adapter_register_powered_callback and
> btd_adapter_powered_cb.
>
Thanks for the feedback. Replaced 'mode' with 'powered' and added the
unregister function.
/Daniel
[-- Attachment #2: 0001-Add-powered-callback-to-btd_adapter.patch --]
[-- Type: text/x-patch, Size: 3090 bytes --]
From ead124babce407c4ec25cdce073b456979e5d431 Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Fri, 13 Aug 2010 16:38:08 +0300
Subject: [PATCH] Add powered callback to btd_adapter
With this patch callback functions can be registered to the
btd_adapter struct. The functions are then called when the powered
state of the adapter changes, with a boolean argument indicating
the new state. The reason for adding the functionality is that the
Maemo6 MCE plugin needs to be notified when the adapter is powered
on or off.
---
src/adapter.c | 32 ++++++++++++++++++++++++++++++++
src/adapter.h | 7 +++++++
2 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index fc1e123..4ad4165 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -135,6 +135,8 @@ struct btd_adapter {
gboolean cache_enable;
gint ref;
+
+ GSList *powered_callbacks;
};
static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -2203,6 +2205,18 @@ static void adapter_disable_cod_cache(struct btd_adapter *adapter)
adapter->pending_cod = adapter->wanted_cod;
}
+static void call_adapter_powered_callbacks(struct btd_adapter *adapter,
+ gboolean powered)
+{
+ GSList *l;
+
+ for (l = adapter->powered_callbacks; l; l = l->next) {
+ btd_adapter_powered_cb cb = l->data;
+
+ cb(adapter, powered);
+ }
+}
+
static int adapter_up(struct btd_adapter *adapter, const char *mode)
{
char srcaddr[18];
@@ -2283,6 +2297,8 @@ proceed:
ADAPTER_INTERFACE, "Powered",
DBUS_TYPE_BOOLEAN, &powered);
+ call_adapter_powered_callbacks(adapter, TRUE);
+
adapter_disable_cod_cache(adapter);
return 0;
@@ -2487,6 +2503,8 @@ int adapter_stop(struct btd_adapter *adapter)
adapter->cache_enable = TRUE;
adapter->pending_cod = 0;
+ call_adapter_powered_callbacks(adapter, FALSE);
+
info("Adapter %s has been disabled", adapter->path);
return 0;
@@ -3422,3 +3440,17 @@ int adapter_ops_setup(void)
return adapter_ops->setup();
}
+
+void btd_adapter_register_powered_callback(struct btd_adapter *adapter,
+ btd_adapter_powered_cb cb)
+{
+ adapter->powered_callbacks =
+ g_slist_append(adapter->powered_callbacks, cb);
+}
+
+void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter,
+ btd_adapter_powered_cb cb)
+{
+ adapter->powered_callbacks =
+ g_slist_remove(adapter->powered_callbacks, cb);
+}
diff --git a/src/adapter.h b/src/adapter.h
index a7eca0e..58853ac 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -188,3 +188,10 @@ struct btd_adapter_ops {
int btd_register_adapter_ops(struct btd_adapter_ops *btd_adapter_ops);
void btd_adapter_cleanup_ops(struct btd_adapter_ops *btd_adapter_ops);
int adapter_ops_setup(void);
+
+typedef void (*btd_adapter_powered_cb) (struct btd_adapter *adapter,
+ gboolean powered);
+void btd_adapter_register_powered_callback(struct btd_adapter *adapter,
+ btd_adapter_powered_cb cb);
+void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter,
+ btd_adapter_powered_cb cb);
--
1.6.0.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] Add mode callback to btd_adapter
2010-08-13 13:43 ` Daniel Örstadius
@ 2010-08-17 8:28 ` Johan Hedberg
0 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-08-17 8:28 UTC (permalink / raw)
To: Daniel Örstadius; +Cc: linux-bluetooth
Hi Daniel,
On Fri, Aug 13, 2010, Daniel Örstadius wrote:
> From: Daniel Orstadius <daniel.orstadius@nokia.com>
> Date: Fri, 13 Aug 2010 16:38:08 +0300
> Subject: [PATCH] Add powered callback to btd_adapter
>
> With this patch callback functions can be registered to the
> btd_adapter struct. The functions are then called when the powered
> state of the adapter changes, with a boolean argument indicating
> the new state. The reason for adding the functionality is that the
> Maemo6 MCE plugin needs to be notified when the adapter is powered
> on or off.
> ---
> src/adapter.c | 32 ++++++++++++++++++++++++++++++++
> src/adapter.h | 7 +++++++
> 2 files changed, 39 insertions(+), 0 deletions(-)
Thanks. This patch is now pushed upstream.
Johan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-08-17 8:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-13 9:18 [PATCH 1/3] Add mode callback to btd_adapter Daniel Örstadius
2010-08-13 12:41 ` Johan Hedberg
2010-08-13 13:43 ` Daniel Örstadius
2010-08-17 8:28 ` Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox