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 09:51:55 -0400 [thread overview]
Message-ID: <1214833915.6764.17.camel@bongo> (raw)
In-Reply-To: <1214605438.11537.0.camel@violet.holtmann.net>
[-- Attachment #1.1.1: Type: text/plain, Size: 971 bytes --]
On Sat, 2008-06-28 at 00:23 +0200, Marcel Holtmann wrote:
> looks nice. However you have to break this up into pieces for. Sent
> small patches and I can quickly review and commit them.
Here's a patch to add support for connecting to devices via the client code. This patch depends on the callback patch.
It finds known services on startup (in setup_services()). Bastien
suggested that we don't need to call setup_services() since those
services are enabled by default, but I'm not quite sure what he meant.
We need to call it to get the service bus IDs so that we can then get
DBusGProxies for them.
It adds the function bluetooth_client_available_services() which gives
back a type mask for services that were detected. Basically which
devices are likely to succeed from a bluetooth_client_connect() call.
bluetooth_client_connect() does device-specific connection handling.
It only handles a few types right now (input and headset).
-mt
[-- Attachment #1.1.2: services.diff --]
[-- Type: text/x-patch, Size: 7428 bytes --]
diff -upr ../bluez-gnome-callback/common/client.c ./common/client.c
--- ../bluez-gnome-callback/common/client.c 2008-06-30 09:04:57.000000000 -0400
+++ ./common/client.c 2008-06-30 09:35:52.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, "ActivateService", 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, "ActivateService", 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)
{
@@ -1131,6 +1177,89 @@ static void call_reply_s(DBusGProxy *pro
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,
+ call_reply_s, userdata);
+ else if (type & BLUETOOTH_TYPE_HEADSET)
+ call = audio_create_headset_async(priv->audio_service, address,
+ call_reply_s, userdata);
+
+ g_object_set_data(G_OBJECT(object), "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,
diff -upr ../bluez-gnome-callback/common/client.h ./common/client.h
--- ../bluez-gnome-callback/common/client.h 2008-06-30 09:03:44.000000000 -0400
+++ ./common/client.h 2008-06-30 09:43:13.000000000 -0400
@@ -101,8 +101,16 @@ gboolean bluetooth_client_register_passk
typedef void (*bluetooth_client_call_reply) (GError *error, gpointer data);
+int bluetooth_client_available_services(BluetoothClient *self);
+
gboolean bluetooth_client_cancel_call(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_create_bonding(BluetoothClient *self,
gchar *adapter, const gchar *address,
bluetooth_client_call_reply callback,
diff -upr ../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 09:38:59.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
next prev parent reply other threads:[~2008-06-30 13:51 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 [this message]
2008-06-30 19:58 ` Michael Terry
2008-06-30 20:01 ` Michael Terry
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=1214833915.6764.17.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