Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Store new local name before writing it to HCI
@ 2010-08-30 14:35 Daniel Örstadius
  2010-09-03  7:37 ` Daniel Örstadius
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Örstadius @ 2010-08-30 14:35 UTC (permalink / raw)
  To: linux-bluetooth

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

Store new local name to the filesystem and emit property changed
before actually writing the name to the chip. Avoids writing the
name twice by using a boolean variable in the btd_adapter struct.
The flag is needed since the name is read immediately after setting
it and since the name could be changed by using for example
hciconfig (in which case the flag would not be set).

/Daniel

[-- Attachment #2: 0001-Store-new-local-name-before-writing-it-to-HCI.patch --]
[-- Type: text/x-patch, Size: 2922 bytes --]

From 140d4d7f194c5da2fbf6584d8de3cdff68b70fec Mon Sep 17 00:00:00 2001
From: Daniel Orstadius <daniel.orstadius@nokia.com>
Date: Mon, 30 Aug 2010 16:54:09 +0300
Subject: [PATCH] Store new local name before writing it to HCI

Store new local name to the filesystem and emit property changed
before actually writing the name to the chip. Avoids writing the
name twice by using a boolean variable in the btd_adapter struct.
The flag is needed since the name is read immediately after setting
it and since the name could be changed by using for example
hciconfig (in which case the flag would not be set).
---
 src/adapter.c |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 377bacc..0dbb295 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -137,6 +137,8 @@ struct btd_adapter {
 	gint ref;
 
 	GSList *powered_callbacks;
+
+	gboolean name_stored;
 };
 
 static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
@@ -950,17 +952,21 @@ void adapter_update_local_name(bdaddr_t *bdaddr, uint8_t status, void *ptr)
 
 	strncpy((char *) dev->name, (char *) rp.name, MAX_NAME_LENGTH);
 
-	write_local_name(bdaddr, (char *) dev->name);
+	if (!adapter->name_stored) {
+		write_local_name(bdaddr, (char *) dev->name);
 
-	update_ext_inquiry_response(adapter);
+		name = g_strdup((char *) dev->name);
 
-	name = g_strdup((char *) dev->name);
+		if (connection)
+			emit_property_changed(connection, adapter->path,
+						ADAPTER_INTERFACE, "Name",
+						DBUS_TYPE_STRING, &name);
+		g_free(name);
+	}
 
-	if (connection)
-		emit_property_changed(connection, adapter->path,
-					ADAPTER_INTERFACE, "Name",
-					DBUS_TYPE_STRING, &name);
-	g_free(name);
+	adapter->name_stored = FALSE;
+
+	update_ext_inquiry_response(adapter);
 }
 
 void adapter_setname_complete(bdaddr_t *local, uint8_t status)
@@ -998,16 +1004,18 @@ static DBusMessage *set_name(DBusConnection *conn, DBusMessage *msg,
 	if (strncmp(name, (char *) dev->name, MAX_NAME_LENGTH) == 0)
 		goto done;
 
-	if (!adapter->up) {
-		strncpy((char *) adapter->dev.name, name, MAX_NAME_LENGTH);
-		write_local_name(&adapter->bdaddr, name);
-		emit_property_changed(connection, adapter->path,
+	strncpy((char *) adapter->dev.name, name, MAX_NAME_LENGTH);
+	write_local_name(&adapter->bdaddr, name);
+	emit_property_changed(connection, adapter->path,
 					ADAPTER_INTERFACE, "Name",
 					DBUS_TYPE_STRING, &name);
-	} else {
+
+	if (adapter->up) {
 		int err = adapter_ops->set_name(adapter->dev_id, name);
 		if (err < 0)
 			return failed_strerror(msg, err);
+
+		adapter->name_stored = TRUE;
 	}
 
 done:
@@ -2504,6 +2512,7 @@ int adapter_stop(struct btd_adapter *adapter)
 	adapter->cache_enable = TRUE;
 	adapter->pending_cod = 0;
 	adapter->off_requested = FALSE;
+	adapter->name_stored = FALSE;
 
 	call_adapter_powered_callbacks(adapter, FALSE);
 
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-03  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-30 14:35 [PATCH] Store new local name before writing it to HCI Daniel Örstadius
2010-09-03  7:37 ` Daniel Örstadius
2010-09-03  7:58   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox