public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Michael Terry <michael.terry@canonical.com>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] Wizard patch
Date: Mon, 30 Jun 2008 16:01:14 -0400	[thread overview]
Message-ID: <1214856074.6764.58.camel@bongo> (raw)
In-Reply-To: <1214855909.6764.57.camel@bongo>


[-- Attachment #1.1.1: Type: text/plain, Size: 317 bytes --]

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

[-- Attachment #1.1.2: services2.diff --]
[-- Type: text/x-patch, Size: 9448 bytes --]

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 #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 247 bytes --]

-------------------------------------------------------------------------
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

[-- Attachment #3: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

  reply	other threads:[~2008-06-30 20:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27 19:05 [Bluez-devel] Wizard patch Michael Terry
2008-06-27 19:18 ` Michael Terry
2008-06-27 19:38 ` David Stockwell
2008-06-27 19:42   ` Michael Terry
2008-06-27 22:24     ` Marcel Holtmann
2008-06-27 22:23 ` Marcel Holtmann
2008-06-30 12:51   ` Michael Terry
2008-06-30 12:57     ` Marcel Holtmann
2008-06-30 13:20       ` Michael Terry
2008-06-30 14:07         ` Marcel Holtmann
2008-06-30 13:15   ` Michael Terry
2008-06-30 14:06     ` Marcel Holtmann
2008-06-30 15:57       ` Michael Terry
2008-06-30 16:03         ` Marcel Holtmann
2008-06-30 18:53           ` Michael Terry
2008-07-01  1:10             ` Marcel Holtmann
2008-07-09 14:28               ` Michael Terry
2008-08-19 17:33                 ` Michael Terry
2008-06-30 13:51   ` Michael Terry
2008-06-30 19:58     ` Michael Terry
2008-06-30 20:01       ` Michael Terry [this message]
2008-06-30 20:38         ` Bastien Nocera
2008-06-30 20:42         ` Mario Limonciello
2008-07-01  1:16     ` Marcel Holtmann
2008-06-30 15:48   ` Michael Terry
2008-07-01  1:24     ` Marcel Holtmann
2008-06-27 22:44 ` Bastien Nocera
     [not found]   ` <031301c8da4d$0bce3720$6701a8c0@freqonedev>
     [not found]     ` <1214813891.4435.149.camel@cookie.hadess.net>
2008-06-30 13:15       ` David Stockwell
2008-06-30 22:27         ` Luiz Augusto von Dentz
2008-07-01 18:56           ` David Stockwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1214856074.6764.58.camel@bongo \
    --to=michael.terry@canonical.com \
    --cc=bluez-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox