On Fri, Aug 13, 2010 at 12:19 PM, Daniel Örstadius <daniel.orstadius@xxxxxxxxx> wrote: > Registers a callback in btd_adapter to get notified when > the powered state of the adapter is changed. This is needed > to update the state stored in the MCE if the adapter is powered > on or off using for example SetProperty(Powered). The current > setting of the MCE is saved in a variable and if the notification > to the plugin does not match this value the MCE is updated > accordingly using its DBus method for setting radio states. > Attaching updated patch. /Daniel
From 1d72b15a82d8d9fdfb194b96dfad0d3c9cb79a3a Mon Sep 17 00:00:00 2001 From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx> Date: Tue, 17 Aug 2010 11:41:33 +0300 Subject: [PATCH] Maemo6 MCE: listen to adapter powered state Registers a callback in btd_adapter to get notified when the powered state of the adapter is changed. This is needed to update the state stored in the MCE if the adapter is powered on or off using for example SetProperty(Powered). The current setting of the MCE is saved in a variable and if the notification to the plugin does not match this value the MCE is updated accordingly using its DBus method for setting radio states. --- plugins/maemo6.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 46 insertions(+), 2 deletions(-) diff --git a/plugins/maemo6.c b/plugins/maemo6.c index 2ed5f12..f9d9c1f 100644 --- a/plugins/maemo6.c +++ b/plugins/maemo6.c @@ -43,11 +43,13 @@ #define MCE_SIGNAL_IF "com.nokia.mce.signal" #define MCE_REQUEST_PATH "/com/nokia/mce/request" #define MCE_SIGNAL_PATH "/com/nokia/mce/signal" +#define MCE_RADIO_STATES_CHANGE_REQ "req_radio_states_change" #define MCE_RADIO_STATES_GET "get_radio_states" #define MCE_RADIO_STATES_SIG "radio_states_ind" static guint watch_id; static DBusConnection *conn = NULL; +static gboolean mce_bt_set = FALSE; static gboolean mce_signal_callback(DBusConnection *connection, DBusMessage *message, void *user_data) @@ -66,7 +68,11 @@ static gboolean mce_signal_callback(DBusConnection *connection, dbus_message_iter_get_basic(&args, &sigvalue); DBG("got signal with value %u", sigvalue); - if (sigvalue & MCE_RADIO_STATE_BLUETOOTH) + /* set the adapter according to the mce signal + and remember the value */ + mce_bt_set = sigvalue & MCE_RADIO_STATE_BLUETOOTH; + + if (mce_bt_set) btd_adapter_switch_online(adapter); else btd_adapter_switch_offline(adapter); @@ -102,13 +108,48 @@ static void read_radio_states_cb(DBusPendingCall *call, void *user_data) goto done; } - if (radio_states & MCE_RADIO_STATE_BLUETOOTH) + DBG("radio_states: %d", radio_states); + + mce_bt_set = radio_states & MCE_RADIO_STATE_BLUETOOTH; + + if (mce_bt_set) btd_adapter_switch_online(adapter); + else + btd_adapter_switch_offline(adapter); done: dbus_message_unref(reply); } +static void adapter_powered(struct btd_adapter *adapter, gboolean powered) +{ + DBusMessage *msg; + dbus_uint32_t radio_states = 0; + dbus_uint32_t radio_mask = MCE_RADIO_STATE_BLUETOOTH; + + DBG("adapter_powered called with %d", (int) powered); + + /* nothing to do if the states match */ + if (mce_bt_set == powered) + return; + + /* set the mce value according to the state of the adapter */ + msg = dbus_message_new_method_call(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_RADIO_STATES_CHANGE_REQ); + + if (powered) + radio_states = MCE_RADIO_STATE_BLUETOOTH; + + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &radio_states, + DBUS_TYPE_UINT32, &radio_mask); + + if (!dbus_connection_send(conn, msg, NULL)) + error("calling %s failed", MCE_RADIO_STATES_CHANGE_REQ); + + dbus_message_unref(msg); +} + + static int mce_probe(struct btd_adapter *adapter) { DBusMessage *msg; @@ -132,6 +173,9 @@ static int mce_probe(struct btd_adapter *adapter) watch_id = g_dbus_add_signal_watch(conn, NULL, MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_RADIO_STATES_SIG, mce_signal_callback, adapter, NULL); + + btd_adapter_register_powered_callback(adapter, adapter_powered); + return 0; } -- 1.6.0.4