Re: [PATCH 2/3] Maemo6 MCE: listen to adapter mode changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 17, 2010 at 1:30 PM, Johan Hedberg <johan.hedberg@xxxxxxxxx> 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
From 263f53fe9cddd9fe9c8c8d4e8265cfbbe3f8c37e Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx>
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


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux