Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v0 1/4] bluetooth: Fix reading Bluetooth Adapters
@ 2012-11-20 12:12 Claudio Takahasi
  2012-11-20 12:12 ` [PATCH v0 2/4] bluetooth: Fix reading adapter properties Claudio Takahasi
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Claudio Takahasi @ 2012-11-20 12:12 UTC (permalink / raw)
  To: ofono

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

This patch replaces GetProperties method by the Get method of the
object manager to read the available Bluetooth adapters.
---
 plugins/bluetooth.c | 30 ++++++++++++++++++++++--------
 plugins/bluetooth.h |  2 ++
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 5d28530..f35c755 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -749,7 +749,7 @@ static gboolean device_removed(DBusConnection *conn,
 	return TRUE;
 }
 
-static void parse_adapters(DBusMessageIter *array, gpointer user_data)
+static void parse_adapters(DBusMessageIter *array)
 {
 	DBusMessageIter value;
 
@@ -776,26 +776,35 @@ static void parse_adapters(DBusMessageIter *array, gpointer user_data)
 	}
 }
 
-static void manager_properties_cb(DBusPendingCall *call, gpointer user_data)
+static void adapters_objects_cb(DBusPendingCall *call, gpointer user_data)
 {
 	DBusMessage *reply;
 	DBusError derr;
+	DBusMessageIter array, variant;
+
+	DBG("");
 
 	reply = dbus_pending_call_steal_reply(call);
 
 	dbus_error_init(&derr);
 
 	if (dbus_set_error_from_message(&derr, reply)) {
-		ofono_error("Manager.GetProperties() replied an error: %s, %s",
+		ofono_error("Get(\"%s\", \"Adapters\") replied an error: %s, "
+					"%s", FREEDESKTOP_PROPERTIES_INTERFACE,
 					derr.name, derr.message);
 		dbus_error_free(&derr);
 		goto done;
 	}
 
-	DBG("");
+	if (dbus_message_iter_init(reply, &variant) == FALSE)
+		goto done;
 
-	bluetooth_parse_properties(reply, "Adapters", parse_adapters, NULL,
-						NULL);
+	if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_VARIANT)
+		goto done;
+
+	dbus_message_iter_recurse(&variant, &array);
+
+	parse_adapters(&array);
 
 done:
 	dbus_message_unref(reply);
@@ -803,8 +812,13 @@ done:
 
 static void bluetooth_connect(DBusConnection *conn, void *user_data)
 {
-	bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "GetProperties",
-				NULL, manager_properties_cb, NULL, NULL, -1,
+	const char *interface = BLUEZ_MANAGER_INTERFACE;
+	const char *property = "Adapters";
+
+	bluetooth_send_with_reply("/", FREEDESKTOP_PROPERTIES_INTERFACE, "Get",
+				NULL, adapters_objects_cb, NULL, NULL, -1,
+				DBUS_TYPE_STRING, &interface,
+				DBUS_TYPE_STRING, &property,
 				DBUS_TYPE_INVALID);
 
 	bluetooth_send_with_reply("/", BLUEZ_MANAGER_INTERFACE, "FindAdapter",
diff --git a/plugins/bluetooth.h b/plugins/bluetooth.h
index 4fc16ad..af59d3d 100644
--- a/plugins/bluetooth.h
+++ b/plugins/bluetooth.h
@@ -29,6 +29,8 @@
 #define	BLUEZ_SERVICE_INTERFACE		BLUEZ_SERVICE ".Service"
 #define BLUEZ_SERIAL_INTERFACE		BLUEZ_SERVICE ".Serial"
 
+#define	FREEDESKTOP_PROPERTIES_INTERFACE	"org.freedesktop.DBus.Properties"
+
 #define DBUS_TIMEOUT 15
 
 #define DUN_GW_UUID	"00001103-0000-1000-8000-00805f9b34fb"
-- 
1.7.11.7


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

end of thread, other threads:[~2012-12-17 14:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-20 12:12 [PATCH v0 1/4] bluetooth: Fix reading Bluetooth Adapters Claudio Takahasi
2012-11-20 12:12 ` [PATCH v0 2/4] bluetooth: Fix reading adapter properties Claudio Takahasi
2012-11-20 12:12 ` [PATCH v0 3/4] bluetooth: Fix read device properties Claudio Takahasi
2012-11-20 12:12 ` [PATCH v0 4/4] bluetooth: Fix Device PropertyChanged Claudio Takahasi
2012-11-20 12:42   ` Daniel Wagner
2012-11-20 13:06     ` Claudio Takahasi
2012-12-17 14:25 ` [PATCH v0 1/4] bluetooth: Fix reading Bluetooth Adapters Claudio Takahasi

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