gnome-bluetooth r502 - trunk/common



Author: hadess
Date: Thu Mar 19 18:00:34 2009
New Revision: 502
URL: http://svn.gnome.org/viewvc/gnome-bluetooth?rev=502&view=rev

Log:
Add connect_audio() helper

Tries to connect to AudioSink first, then HeadSet.



Modified:
   trunk/common/bluetooth-client.c
   trunk/common/bluetooth-client.h

Modified: trunk/common/bluetooth-client.c
==============================================================================
--- trunk/common/bluetooth-client.c	(original)
+++ trunk/common/bluetooth-client.c	Thu Mar 19 18:00:34 2009
@@ -66,6 +66,8 @@
 
 /* Keep in sync with above */
 #define BLUEZ_INPUT_INTERFACE	(connectable_interfaces[2])
+#define BLUEZ_INPUT_HEADSET (connectable_interfaces[1])
+#define BLUEZ_INPUT_AUDIOSINK (connectable_interfaces[0])
 
 static DBusGConnection *connection = NULL;
 static BluetoothClient *bluetooth_client = NULL;
@@ -1317,6 +1319,7 @@
 typedef struct {
 	BluetoothClientConnectFunc func;
 	gpointer data;
+	gboolean did_audiosink;
 } ConnectData;
 
 static void connect_input_callback(DBusGProxy *proxy,
@@ -1336,11 +1339,41 @@
 	g_object_unref(proxy);
 }
 
+static void connect_audio_callback(DBusGProxy *proxy,
+				   DBusGProxyCall *call, void *user_data)
+{
+	ConnectData *conndata = user_data;
+	GError *error = NULL;
+
+	dbus_g_proxy_end_call(proxy, call, &error, G_TYPE_INVALID);
+
+	if (error != NULL)
+		g_error_free(error);
+
+	if (conndata->did_audiosink) {
+		if (conndata->func)
+			conndata->func(conndata->data);
+
+		g_object_unref(proxy);
+	} else {
+		DBusGProxy *new_proxy;
+
+		conndata->did_audiosink = TRUE;
+		new_proxy = dbus_g_proxy_new_from_proxy(proxy,
+						    BLUEZ_INPUT_HEADSET, NULL);
+		g_object_unref (proxy);
+		call = dbus_g_proxy_begin_call(new_proxy, "Connect",
+					       connect_audio_callback, conndata, g_free,
+					       G_TYPE_INVALID);
+	}
+}
+
 static gboolean bluetooth_client_connect_service(BluetoothClient *client,
 				const char *device, const char *iface_name,
 				BluetoothClientConnectFunc func, gpointer data)
 {
 	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	DBusGProxyCallNotify notify_func;
 	ConnectData *conndata;
 	DBusGProxy *proxy;
 	DBusGProxyCall *call;
@@ -1361,13 +1394,27 @@
 	conndata->func = func;
 	conndata->data = data;
 
+	if (g_str_equal (iface_name, BLUEZ_INPUT_INTERFACE))
+		notify_func = connect_input_callback;
+	else
+		notify_func = connect_audio_callback;
+
 	call = dbus_g_proxy_begin_call(proxy, "Connect",
-				connect_input_callback, conndata, g_free,
-							G_TYPE_INVALID);
+				       notify_func, conndata, g_free,
+				       G_TYPE_INVALID);
 
 	return TRUE;
 }
 
+gboolean bluetooth_client_connect_audio(BluetoothClient *client,
+				const char *device,
+				BluetoothClientConnectFunc func, gpointer data)
+{
+	return bluetooth_client_connect_service(client, device,
+						BLUEZ_INPUT_AUDIOSINK,
+						func, data);
+}
+
 gboolean bluetooth_client_connect_input(BluetoothClient *client,
 				const char *device,
 				BluetoothClientConnectFunc func, gpointer data)

Modified: trunk/common/bluetooth-client.h
==============================================================================
--- trunk/common/bluetooth-client.h	(original)
+++ trunk/common/bluetooth-client.h	Thu Mar 19 18:00:34 2009
@@ -105,7 +105,10 @@
 
 gboolean bluetooth_client_connect_input(BluetoothClient *client,
 				const char *device,
-				BluetoothClientConnectFunc, gpointer data);
+				BluetoothClientConnectFunc func, gpointer data);
+gboolean bluetooth_client_connect_audio(BluetoothClient *client,
+				const char *device,
+				BluetoothClientConnectFunc func, gpointer data);
 
 const gchar *bluetooth_type_to_string(guint type);
 gboolean bluetooth_verify_address (const char *bdaddr);



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