On Fri, Aug 13, 2010 at 3:41 PM, Johan Hedberg <johan.hedberg@xxxxxxxxx> 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
From ead124babce407c4ec25cdce073b456979e5d431 Mon Sep 17 00:00:00 2001 From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx> 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