public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* Port bluetooth-sendto to BlueZ 4.x
@ 2008-09-24  0:55 Bastien Nocera
  2008-09-24  2:57 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien Nocera @ 2008-09-24  0:55 UTC (permalink / raw)
  To: linux-bluetooth

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

Patch attached.

[-- Attachment #2: 0001-Fix-getting-names-of-remote-devices.patch --]
[-- Type: text/x-patch, Size: 3458 bytes --]

>From 71bd2202a5407af206f2476de20e379d8bbea264 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Tue, 23 Sep 2008 17:53:49 -0700
Subject: [PATCH] Fix getting names of remote devices

Look in the BlueZ device database to find the name of the
remote device, porting code from BlueZ 3.x to the 4.x APIs
---
 sendto/main.c |   80 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/sendto/main.c b/sendto/main.c
index daccf91..044bbbc 100644
--- a/sendto/main.c
+++ b/sendto/main.c
@@ -415,52 +415,76 @@ static void create_notify(DBusGProxy *proxy,
 							G_TYPE_INVALID);
 }
 
+static char *
+get_name (DBusGProxy *device)
+{
+	GHashTable *hash;
+
+	if (dbus_g_proxy_call(device, "GetProperties", NULL,
+			      G_TYPE_INVALID, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+			      &hash, G_TYPE_INVALID) != FALSE) {
+		GValue *value;
+		char *name;
+
+		value = g_hash_table_lookup(hash, "Name");
+		name = value ? g_value_dup_string(value) : NULL;
+		g_hash_table_destroy(hash);
+		return name;
+	}
+
+	return NULL;
+}
+
 static gchar *get_device_name(const gchar *address)
 {
 	DBusGConnection *connection;
-	DBusGProxy *manager, *proxy;
-	gchar *adapter, *name;
+	DBusGProxy *manager;
+	GPtrArray *adapters;
+	gchar *name;
+	guint i;
+
+	name = NULL;
 
 	connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
 	if (connection == NULL)
-		return NULL;
+		return name;
 
 	manager = dbus_g_proxy_new_for_name(connection, "org.bluez",
-					"/org/bluez", "org.bluez.Manager");
+					    "/", "org.bluez.Manager");
 	if (manager == NULL) {
 		dbus_g_connection_unref(connection);
-		return NULL;
+		return name;
 	}
 
-	if (dbus_g_proxy_call(manager, "DefaultAdapter", NULL, G_TYPE_INVALID,
-			G_TYPE_STRING, &adapter, G_TYPE_INVALID) == FALSE) {
+	if (dbus_g_proxy_call(manager, "ListAdapters", NULL,
+			      G_TYPE_INVALID, dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters,
+			      G_TYPE_INVALID) == FALSE) {
 		g_object_unref(manager);
 		dbus_g_connection_unref(connection);
-		return NULL;
+		return name;
 	}
 
-	g_object_unref(manager);
-
-	proxy = dbus_g_proxy_new_for_name(connection, "org.bluez",
-						adapter, "org.bluez.Adapter");
-	if (proxy == NULL) {
-		g_free(adapter);
-		dbus_g_connection_unref(connection);
-		return NULL;
-	}
-
-	g_free(adapter);
-
-	if (dbus_g_proxy_call(proxy, "GetRemoteName", NULL,
-			G_TYPE_STRING, address, G_TYPE_INVALID,
-			G_TYPE_STRING, &name, G_TYPE_INVALID) == FALSE) {
-		g_object_unref(proxy);
-		dbus_g_connection_unref(connection);
-		return NULL;
+	for (i = 0; i < adapters->len && name == NULL; i++)
+	{
+		DBusGProxy *adapter;
+		char *device_path;
+
+		adapter = dbus_g_proxy_new_for_name(connection, "org.bluez",
+						    g_ptr_array_index (adapters, i), "org.bluez.Adapter");
+		if (dbus_g_proxy_call(adapter, "FindDevice", NULL,
+				      G_TYPE_STRING, address, G_TYPE_INVALID,
+				      DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) != FALSE) {
+			DBusGProxy *device;
+			device = dbus_g_proxy_new_for_name(connection, "org.bluez", device_path, "org.bluez.Device");
+			name = get_name(device);
+			g_object_unref(device);
+			break;
+		}
+		g_object_unref(adapter);
 	}
 
-	g_object_unref(proxy);
-
+	g_ptr_array_free(adapters, TRUE);
+	g_object_unref(manager);
 	dbus_g_connection_unref(connection);
 
 	return name;
-- 
1.6.0.1


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

* Re: Port bluetooth-sendto to BlueZ 4.x
  2008-09-24  0:55 Port bluetooth-sendto to BlueZ 4.x Bastien Nocera
@ 2008-09-24  2:57 ` Marcel Holtmann
  2008-09-24 18:18   ` Bastien Nocera
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2008-09-24  2:57 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: linux-bluetooth

Hi Bastien,

> Patch attached.

it doesn't apply against upstream GIT and please also fix the coding
style.

Regards

Marcel



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

* Re: Port bluetooth-sendto to BlueZ 4.x
  2008-09-24  2:57 ` Marcel Holtmann
@ 2008-09-24 18:18   ` Bastien Nocera
  2008-09-27  4:32     ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien Nocera @ 2008-09-24 18:18 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

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

On Wed, 2008-09-24 at 04:57 +0200, Marcel Holtmann wrote:
> Hi Bastien,
> 
> > Patch attached.
> 
> it doesn't apply against upstream GIT and please also fix the coding
> style.

I blame git for allowing me to do stupid things. Fixed patch attached.

Cheers

[-- Attachment #2: 0001-Fix-getting-names-of-remote-devices.patch --]
[-- Type: text/x-patch, Size: 2973 bytes --]

diff --git a/sendto/main.c b/sendto/main.c
index afa8036..b01dafc 100644
--- a/sendto/main.c
+++ b/sendto/main.c
@@ -415,52 +415,75 @@ static void create_notify(DBusGProxy *proxy,
 							G_TYPE_INVALID);
 }
 
+static gchar *get_name(DBusGProxy *device)
+{
+	GHashTable *hash;
+
+	if (dbus_g_proxy_call(device, "GetProperties", NULL,
+			      G_TYPE_INVALID, dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE),
+			      &hash, G_TYPE_INVALID) != FALSE) {
+		GValue *value;
+		char *name;
+
+		value = g_hash_table_lookup(hash, "Name");
+		name = value ? g_value_dup_string(value) : NULL;
+		g_hash_table_destroy(hash);
+		return name;
+	}
+
+	return NULL;
+}
+
 static gchar *get_device_name(const gchar *address)
 {
 	DBusGConnection *connection;
-	DBusGProxy *manager, *proxy;
-	gchar *adapter, *name;
+	DBusGProxy *manager;
+	GPtrArray *adapters;
+	gchar *name;
+	guint i;
+
+	name = NULL;
 
 	connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL);
 	if (connection == NULL)
-		return NULL;
+		return name;
 
 	manager = dbus_g_proxy_new_for_name(connection, "org.bluez",
-						"/", "org.bluez.Manager");
+					    "/", "org.bluez.Manager");
 	if (manager == NULL) {
 		dbus_g_connection_unref(connection);
-		return NULL;
+		return name;
 	}
 
-	if (dbus_g_proxy_call(manager, "DefaultAdapter", NULL, G_TYPE_INVALID,
-			G_TYPE_STRING, &adapter, G_TYPE_INVALID) == FALSE) {
+	if (dbus_g_proxy_call(manager, "ListAdapters", NULL,
+			      G_TYPE_INVALID, dbus_g_type_get_collection("GPtrArray", DBUS_TYPE_G_OBJECT_PATH), &adapters,
+			      G_TYPE_INVALID) == FALSE) {
 		g_object_unref(manager);
 		dbus_g_connection_unref(connection);
-		return NULL;
+		return name;
 	}
 
-	g_object_unref(manager);
-
-	proxy = dbus_g_proxy_new_for_name(connection, "org.bluez",
-						adapter, "org.bluez.Adapter");
-	if (proxy == NULL) {
-		g_free(adapter);
-		dbus_g_connection_unref(connection);
-		return NULL;
-	}
-
-	g_free(adapter);
-
-	if (dbus_g_proxy_call(proxy, "GetRemoteName", NULL,
-			G_TYPE_STRING, address, G_TYPE_INVALID,
-			G_TYPE_STRING, &name, G_TYPE_INVALID) == FALSE) {
-		g_object_unref(proxy);
-		dbus_g_connection_unref(connection);
-		return NULL;
+	for (i = 0; i < adapters->len && name == NULL; i++)
+	{
+		DBusGProxy *adapter;
+		char *device_path;
+
+		adapter = dbus_g_proxy_new_for_name(connection, "org.bluez",
+						    g_ptr_array_index(adapters, i), "org.bluez.Adapter");
+		if (dbus_g_proxy_call(adapter, "FindDevice", NULL,
+				      G_TYPE_STRING, address, G_TYPE_INVALID,
+				      DBUS_TYPE_G_OBJECT_PATH, &device_path, G_TYPE_INVALID) != FALSE) {
+			DBusGProxy *device;
+			device = dbus_g_proxy_new_for_name(connection, "org.bluez", device_path, "org.bluez.Device");
+			name = get_name(device);
+			g_object_unref(device);
+			break;
+		}
+		g_object_unref(adapter);
 	}
 
-	g_object_unref(proxy);
-
+	g_ptr_array_free(adapters, TRUE);
+	g_object_unref(manager);
 	dbus_g_connection_unref(connection);
 
 	return name;

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

* Re: Port bluetooth-sendto to BlueZ 4.x
  2008-09-24 18:18   ` Bastien Nocera
@ 2008-09-27  4:32     ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2008-09-27  4:32 UTC (permalink / raw)
  To: Bastien Nocera; +Cc: linux-bluetooth

Hi Bastien,

> > it doesn't apply against upstream GIT and please also fix the coding
> > style.
> 
> I blame git for allowing me to do stupid things. Fixed patch attached.

patch has been applied. Thanks.

Regards

Marcel



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

end of thread, other threads:[~2008-09-27  4:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-24  0:55 Port bluetooth-sendto to BlueZ 4.x Bastien Nocera
2008-09-24  2:57 ` Marcel Holtmann
2008-09-24 18:18   ` Bastien Nocera
2008-09-27  4:32     ` Marcel Holtmann

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