* [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes @ 2010-08-13 9:19 Daniel Örstadius 2010-08-17 8:46 ` Daniel Örstadius 0 siblings, 1 reply; 5+ messages in thread From: Daniel Örstadius @ 2010-08-13 9:19 UTC (permalink / raw) To: linux-bluetooth [-- Attachment #1: Type: text/plain, Size: 437 bytes --] 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. /Daniel [-- Attachment #2: 0001-Maemo6-MCE-listen-to-adapter-mode-changes.patch --] [-- Type: text/x-patch, Size: 3567 bytes --] From cc89e05c1d406e7d9021030e25e3b32a14bbd28c Mon Sep 17 00:00:00 2001 From: Daniel Orstadius <daniel.orstadius@nokia.com> Date: Fri, 13 Aug 2010 11:18:32 +0300 Subject: [PATCH] Maemo6 MCE: listen to adapter mode changes 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..20e5c00 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_mode_change(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_mode_change 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_mode_callback(adapter, adapter_mode_change); + return 0; } -- 1.6.0.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes 2010-08-13 9:19 [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes Daniel Örstadius @ 2010-08-17 8:46 ` Daniel Örstadius 2010-08-17 10:30 ` Johan Hedberg 0 siblings, 1 reply; 5+ messages in thread From: Daniel Örstadius @ 2010-08-17 8:46 UTC (permalink / raw) To: linux-bluetooth [-- Attachment #1: Type: text/plain, Size: 580 bytes --] On Fri, Aug 13, 2010 at 12:19 PM, Daniel Örstadius <daniel.orstadius@gmail.com> 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 [-- Attachment #2: 0001-Maemo6-MCE-listen-to-adapter-powered-state.patch --] [-- Type: text/x-patch, Size: 3559 bytes --] From 1d72b15a82d8d9fdfb194b96dfad0d3c9cb79a3a Mon Sep 17 00:00:00 2001 From: Daniel Orstadius <daniel.orstadius@nokia.com> 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes 2010-08-17 8:46 ` Daniel Örstadius @ 2010-08-17 10:30 ` Johan Hedberg 2010-08-17 12:54 ` Daniel Örstadius 0 siblings, 1 reply; 5+ messages in thread From: Johan Hedberg @ 2010-08-17 10:30 UTC (permalink / raw) To: Daniel Örstadius; +Cc: linux-bluetooth Hi Daniel, > From: Daniel Orstadius <daniel.orstadius@nokia.com> > 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(-) A couple of issues I noticed: > + DBG("adapter_powered called with %d", (int) powered); I don't think the int cast is necessary here. Or do you get a warning otherwise? > + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &radio_states, > + DBUS_TYPE_UINT32, &radio_mask); DBUS_TYPE_INVALID is missing from the end of the arguments list. > +} > + > + > static int mce_probe(struct btd_adapter *adapter) Why the two consecutive empty lines? Please remove one. > @@ -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; > } > It seems you're missing the corresponding unregister_powered_callback call in mce_remove(). Johan ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes 2010-08-17 10:30 ` Johan Hedberg @ 2010-08-17 12:54 ` Daniel Örstadius 2010-08-17 13:33 ` Johan Hedberg 0 siblings, 1 reply; 5+ messages in thread From: Daniel Örstadius @ 2010-08-17 12:54 UTC (permalink / raw) To: linux-bluetooth [-- Attachment #1: Type: text/plain, Size: 1204 bytes --] On Tue, Aug 17, 2010 at 1:30 PM, Johan Hedberg <johan.hedberg@gmail.com> wrote: > > A couple of issues I noticed: > >> + DBG("adapter_powered called with %d", (int) powered); > > I don't think the int cast is necessary here. Or do you get a warning > otherwise? > >> + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &radio_states, >> + DBUS_TYPE_UINT32, &radio_mask); > > DBUS_TYPE_INVALID is missing from the end of the arguments list. > >> +} >> + >> + >> static int mce_probe(struct btd_adapter *adapter) > > Why the two consecutive empty lines? Please remove one. > >> @@ -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; >> } >> > > It seems you're missing the corresponding unregister_powered_callback > call in mce_remove(). > Corrected in the attached patch. /Daniel [-- Attachment #2: 0001-Maemo6-MCE-listen-to-adapter-powered-state.patch --] [-- Type: text/x-patch, Size: 3836 bytes --] From 263f53fe9cddd9fe9c8c8d4e8265cfbbe3f8c37e Mon Sep 17 00:00:00 2001 From: Daniel Orstadius <daniel.orstadius@nokia.com> Date: Tue, 17 Aug 2010 15:48:45 +0300 Subject: [PATCH] Maemo6 MCE: listen to adapter powered state Registers a callback to 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 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 48 insertions(+), 2 deletions(-) diff --git a/plugins/maemo6.c b/plugins/maemo6.c index 2ed5f12..55ea508 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", 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, + DBUS_TYPE_INVALID); + + 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; } @@ -141,6 +185,8 @@ static void mce_remove(struct btd_adapter *adapter) if (watch_id > 0) g_dbus_remove_watch(conn, watch_id); + + btd_adapter_unregister_powered_callback(adapter, adapter_powered); } static struct btd_adapter_driver mce_driver = { -- 1.6.0.4 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes 2010-08-17 12:54 ` Daniel Örstadius @ 2010-08-17 13:33 ` Johan Hedberg 0 siblings, 0 replies; 5+ messages in thread From: Johan Hedberg @ 2010-08-17 13:33 UTC (permalink / raw) To: Daniel Örstadius; +Cc: linux-bluetooth Hi Daniel, On Tue, Aug 17, 2010, Daniel Örstadius wrote: > Corrected in the attached patch. > > /Daniel > From 263f53fe9cddd9fe9c8c8d4e8265cfbbe3f8c37e Mon Sep 17 00:00:00 2001 > From: Daniel Orstadius <daniel.orstadius@nokia.com> > Date: Tue, 17 Aug 2010 15:48:45 +0300 > Subject: [PATCH] Maemo6 MCE: listen to adapter powered state > > Registers a callback to 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 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- > 1 files changed, 48 insertions(+), 2 deletions(-) Thanks. This patch is now also upstream. Johan ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-08-17 13:33 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-08-13 9:19 [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes Daniel Örstadius 2010-08-17 8:46 ` Daniel Örstadius 2010-08-17 10:30 ` Johan Hedberg 2010-08-17 12:54 ` Daniel Örstadius 2010-08-17 13:33 ` Johan Hedberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox