Re: Wizard patch

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

 



On Mon, 2008-06-30 at 15:58 -0400, Michael Terry wrote:
> Here's an updated services patch, to go along with the changes in callback2.diff.  I'll wait to provide an updated wizard-ui.diff until I get feedback.

Guh, I need that plugin that warns me about not attaching files.  :)

Actually attached now.

-mt
diff -rup ../bluez-gnome-callback/common/client.c ./common/client.c
--- ../bluez-gnome-callback/common/client.c	2008-06-30 14:57:48.000000000 -0400
+++ ./common/client.c	2008-06-30 15:40:26.000000000 -0400
@@ -48,6 +48,8 @@ struct _BluetoothClientPrivate {
 
 	DBusGConnection *conn;
 	DBusGProxy *manager_object;
+	DBusGProxy *input_service;
+	DBusGProxy *audio_service;
 	GtkTreeStore *store;
 	gchar *default_adapter;
 };
@@ -935,6 +937,33 @@ static void setup_manager(BluetoothClien
 		g_error_free(error);
 }
 
+static void setup_services(BluetoothClient *client)
+{
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	gchar *busname = NULL;
+
+	priv->input_service = NULL;
+	priv->audio_service = NULL;
+
+	if (dbus_g_proxy_call(priv->manager_object, "FindService", NULL,
+	                      G_TYPE_STRING, "input", G_TYPE_INVALID,
+	                      G_TYPE_STRING, &busname, G_TYPE_INVALID)) {
+		priv->input_service = dbus_g_proxy_new_for_name(priv->conn, busname,
+		                                                "/org/bluez/input",
+		                                                "org.bluez.input.Manager");
+		g_free(busname);
+	}
+
+	if (dbus_g_proxy_call(priv->manager_object, "FindService", NULL,
+	                      G_TYPE_STRING, "audio", G_TYPE_INVALID,
+	                      G_TYPE_STRING, &busname, G_TYPE_INVALID)) {
+		priv->audio_service = dbus_g_proxy_new_for_name(priv->conn, busname,
+		                                                "/org/bluez/audio",
+		                                                "org.bluez.audio.Manager");
+		g_free(busname);
+	}
+}
+
 static void name_owner_changed(DBusGProxy *object, const char *name,
 			const char *prev, const char *new, gpointer user_data)
 {
@@ -984,6 +1013,8 @@ static void bluetooth_client_finalize(GO
 	g_free(priv->default_adapter);
 	g_object_unref(G_OBJECT(priv->store));
 	g_object_unref (priv->manager_object);
+	g_object_unref (priv->input_service);
+	g_object_unref (priv->audio_service);
 }
 
 static void bluetooth_client_init(BluetoothClient *client)
@@ -1000,6 +1031,8 @@ static void bluetooth_client_init(Blueto
 	setup_dbus(client);
 
 	setup_manager(client);
+
+	setup_services(client);
 }
 
 static void bluetooth_client_set_property(GObject *object, guint prop_id,
@@ -1085,6 +1118,19 @@ BluetoothClient *bluetooth_client_new(vo
 	}
 }
 
+int bluetooth_client_available_services(BluetoothClient *client)
+{
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	int rv = 0;
+
+	if (priv->input_service)
+		rv |= BLUETOOTH_TYPE_INPUT;
+	if (priv->audio_service)
+		rv |= BLUETOOTH_TYPE_HEADSET;
+
+	return rv;
+}
+
 gboolean bluetooth_client_register_passkey_agent(BluetoothClient *client,
 		const char *path, const char *address, const void *info)
 {
@@ -1124,6 +1170,13 @@ static void call_reply(DBusGProxy *proxy
 		g_error_free(error);
 }
 
+static void connect_reply(DBusGProxy *proxy, char *s,
+					GError *error, gpointer userdata)
+{
+	g_object_set_data(G_OBJECT(proxy), "connect-call", NULL);
+	call_reply(proxy, error, userdata);
+}
+
 static void create_bonding_reply(DBusGProxy *proxy,
 					GError *error, gpointer userdata)
 {
@@ -1131,6 +1184,89 @@ static void create_bonding_reply(DBusGPr
 	call_reply(proxy, error, userdata);
 }
 
+static gboolean connect_to_service(BluetoothClient *client, DBusGProxy *object,
+						const gchar *address, guint type,
+						gpointer userdata)
+{
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	DBusGProxyCall *call = NULL;
+
+	/* Special case the few types we can handle */
+	if (type & BLUETOOTH_TYPE_INPUT)
+		call = input_create_secure_device_async(priv->input_service, address,
+					connect_reply, userdata);
+	else if (type & BLUETOOTH_TYPE_HEADSET)
+		call = audio_create_headset_async(priv->audio_service, address,
+					connect_reply, userdata);
+
+	g_object_set_data(G_OBJECT(object), "connect-call", call);
+	return call != NULL;
+}
+
+gboolean bluetooth_client_connect(BluetoothClient *client, guint type,
+					gchar *adapter, const gchar *address,
+					bluetooth_client_call_reply callback,
+					gpointer userdata)
+{
+	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
+	GtkTreeIter iter;
+	gboolean cont;
+
+	if (adapter == NULL)
+		adapter = priv->default_adapter;
+
+	if (adapter == NULL)
+		return FALSE;
+
+	cont = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(priv->store), &iter);
+
+	while (cont == TRUE) {
+		DBusGProxy *object;
+		gchar *path;
+
+		gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &iter,
+						COLUMN_PATH, &path,
+						COLUMN_OBJECT, &object, -1);
+
+		if (g_ascii_strcasecmp(path, adapter) == 0) {
+			DBusGAsyncData *stuff;
+			gboolean cont;
+			GtkTreeIter child;
+
+			stuff = g_new (DBusGAsyncData, 1);
+			stuff->cb = G_CALLBACK (callback);
+			stuff->userdata = userdata;
+
+			/* If caller didn't specify a forced type, determine it from device info */
+			if (type == 0 || type == BLUETOOTH_TYPE_ANY) {
+				cont = gtk_tree_model_iter_children(GTK_TREE_MODEL(priv->store),
+										&child, &iter);
+
+				while (cont == TRUE) {
+					gchar *value;
+
+					gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &child,
+									COLUMN_ADDRESS, &value, -1);
+
+					if (g_ascii_strcasecmp(address, value) == 0) {
+						gtk_tree_model_get(GTK_TREE_MODEL(priv->store), &child,
+									COLUMN_TYPE, &type, -1);
+						break;
+					}
+
+					cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &child);
+				}
+			}
+
+			return connect_to_service(client, object, address, type, stuff);
+		}
+
+		cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
+	}
+
+	return FALSE;
+}
+
 gboolean bluetooth_client_create_bonding(BluetoothClient *client,
 					gchar *adapter, const gchar *address,
 					bluetooth_client_call_reply callback,
@@ -1410,8 +1546,8 @@ gboolean bluetooth_client_cancel_discove
 	return FALSE;
 }
 
-gboolean bluetooth_client_cancel_bonding(BluetoothClient *client,
-					gchar *adapter, const gchar *address)
+static gboolean bluetooth_client_cancel_call(BluetoothClient *client,
+					gchar *adapter, const gchar *address, const gchar *call_id)
 {
 	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
 	GtkTreeIter iter;
@@ -1435,10 +1571,10 @@ gboolean bluetooth_client_cancel_bonding
 
 		if (g_ascii_strcasecmp(path, adapter) == 0) {
 			DBusGProxyCall *call;
-			call = (DBusGProxyCall *)g_object_get_data(G_OBJECT(object), "bonding-call");
+			call = (DBusGProxyCall *)g_object_get_data(G_OBJECT(object), call_id);
 			if (call != NULL) {
 				dbus_g_proxy_cancel_call(object, call);
-				g_object_set_data(G_OBJECT(object), "bonding-call", NULL);
+				g_object_set_data(G_OBJECT(object), call_id, NULL);
 				return TRUE;
 			}
 			return FALSE;
@@ -1450,6 +1586,18 @@ gboolean bluetooth_client_cancel_bonding
 	return FALSE;
 }
 
+gboolean bluetooth_client_cancel_bonding(BluetoothClient *client,
+					gchar *adapter, const gchar *address)
+{
+	return bluetooth_client_cancel_call(client, adapter, address, "bonding-call");
+}
+
+gboolean bluetooth_client_cancel_connect(BluetoothClient *client,
+					gchar *adapter, const gchar *address)
+{
+	return bluetooth_client_cancel_call(client, adapter, address, "connect-call");
+}
+
 GtkTreeModel *bluetooth_client_get_model(BluetoothClient *client)
 {
 	BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
diff -rup ../bluez-gnome-callback/common/client.h ./common/client.h
--- ../bluez-gnome-callback/common/client.h	2008-06-30 14:43:21.000000000 -0400
+++ ./common/client.h	2008-06-30 14:56:51.000000000 -0400
@@ -107,6 +107,15 @@ gboolean bluetooth_client_create_bonding
 					gpointer data);
 gboolean bluetooth_client_cancel_bonding(BluetoothClient *self,
 					gchar *adapter, const gchar *address);
+
+/* Set 'type' to non-zero to force a certain type connection -- useful for dumb devices */
+gboolean bluetooth_client_connect(BluetoothClient *self, guint type,
+					gchar *adapter, const gchar *address,
+					bluetooth_client_call_reply callback,
+					gpointer data);
+gboolean bluetooth_client_cancel_connect(BluetoothClient *self,
+					gchar *adapter, const gchar *address);
+
 gboolean bluetooth_client_remove_bonding(BluetoothClient *self,
 					gchar *adapter, const gchar *address,
 					bluetooth_client_call_reply callback,
diff -rup ../bluez-gnome-callback/common/dbus.xml ./common/dbus.xml
--- ../bluez-gnome-callback/common/dbus.xml	2008-06-30 08:55:31.000000000 -0400
+++ ./common/dbus.xml	2008-06-30 14:55:56.000000000 -0400
@@ -98,4 +98,20 @@
       <arg type="s" name="address"/>
     </method>
   </interface>
+
+  <interface name="input">
+    <method name="CreateSecureDevice">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg type="s" name="address"/>
+      <arg type="s" direction="out"/>
+    </method>
+  </interface>
+
+  <interface name="audio">
+    <method name="CreateHeadset">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg type="s" name="address"/>
+      <arg type="s" direction="out"/>
+    </method>
+  </interface>
 </node>

Attachment: signature.asc
Description: This is a digitally signed message part

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Bluez-devel mailing list
Bluez-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.sourceforge.net/lists/listinfo/bluez-devel

[Index of Archives]     [Linux Bluetooth Devel]     [Linux USB Devel]     [Network Devel]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux