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

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

 



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
From cc89e05c1d406e7d9021030e25e3b32a14bbd28c Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@xxxxxxxxx>
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


[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