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:15:13 -0400 [thread overview]
Message-ID: <1214831713.6764.8.camel@bongo> (raw)
In-Reply-To: <1214605438.11537.0.camel@violet.holtmann.net>
[-- Attachment #1.1.1: Type: text/plain, Size: 787 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 callback support to many of the common/client
calls.
It also adds a new function: bluetooth_client_cancel_call(). This
cancels the last client call made for the given adapter/address.
Admittedly, it would be fancier if, for example,
bluetooth_client_create_bonding() gave back a handle which could be used
to cancel its call, rather than just keeping track of the last one.
But the cancel-last-call style was simpler and sufficient for the
wizard's purposes and presumably sufficient for others' purposes (by
virtue of the lack of canceling before).
-mt
[-- Attachment #1.1.2: callback.diff --]
[-- Type: text/x-patch, Size: 9501 bytes --]
Index: common/client.c
===================================================================
RCS file: /cvsroot/bluez/gnome/common/client.c,v
retrieving revision 1.44
diff -u -p -r1.44 client.c
--- common/client.c 12 Mar 2008 21:03:38 -0000 1.44
+++ common/client.c 30 Jun 2008 13:05:05 -0000
@@ -1112,14 +1112,29 @@ gboolean bluetooth_client_register_passk
return TRUE;
}
-static void create_bonding_reply(DBusGProxy *proxy,
+static void call_reply(DBusGProxy *proxy,
GError *error, gpointer userdata)
{
- //g_printf("create bonding reply\n");
+ DBusGAsyncData *data = (DBusGAsyncData*) userdata;
+ g_object_set_data(G_OBJECT(proxy), "call", NULL);
+ if (data) {
+ (*(bluetooth_client_call_reply)data->cb) (error, data->userdata);
+ g_free(data);
+ }
+ if (error)
+ g_error_free(error);
+}
+
+static void call_reply_s(DBusGProxy *proxy, char *s,
+ GError *error, gpointer userdata)
+{
+ call_reply(proxy, error, userdata);
}
gboolean bluetooth_client_create_bonding(BluetoothClient *client,
- gchar *adapter, const gchar *address)
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer userdata)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
@@ -1142,9 +1157,15 @@ gboolean bluetooth_client_create_bonding
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
- adapter_create_bonding_async(object, address,
- create_bonding_reply, NULL);
- return TRUE;
+ DBusGProxyCall *call;
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ call = adapter_create_bonding_async(object, address,
+ call_reply, stuff);
+ g_object_set_data(G_OBJECT(object), "call", call);
+ return call != NULL;
}
cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
@@ -1153,14 +1174,10 @@ gboolean bluetooth_client_create_bonding
return FALSE;
}
-static void remove_bonding_reply(DBusGProxy *proxy,
- GError *error, gpointer userdata)
-{
- //g_printf("remove bonding reply\n");
-}
-
gboolean bluetooth_client_remove_bonding(BluetoothClient *client,
- gchar *adapter, const gchar *address)
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer userdata)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
@@ -1183,8 +1200,14 @@ gboolean bluetooth_client_remove_bonding
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
- adapter_remove_bonding_async(object, address,
- remove_bonding_reply, NULL);
+ DBusGProxyCall *call;
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ call = adapter_remove_bonding_async(object, address,
+ call_reply, stuff);
+ g_object_set_data(G_OBJECT(object), "call", call);
return TRUE;
}
@@ -1194,14 +1217,10 @@ gboolean bluetooth_client_remove_bonding
return FALSE;
}
-static void set_trusted_reply(DBusGProxy *proxy,
- GError *error, gpointer userdata)
-{
- //g_printf("set trusted reply\n");
-}
-
gboolean bluetooth_client_set_trusted(BluetoothClient *client,
- gchar *adapter, const gchar *address)
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer userdata)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
@@ -1224,8 +1243,14 @@ gboolean bluetooth_client_set_trusted(Bl
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
- adapter_set_trusted_async(object, address,
- set_trusted_reply, NULL);
+ DBusGProxyCall *call;
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ call = adapter_set_trusted_async(object, address,
+ call_reply, stuff);
+ g_object_set_data(G_OBJECT(object), "call", call);
return TRUE;
}
@@ -1235,14 +1260,10 @@ gboolean bluetooth_client_set_trusted(Bl
return FALSE;
}
-static void remove_trust_reply(DBusGProxy *proxy,
- GError *error, gpointer userdata)
-{
- //g_printf("remove trust reply\n");
-}
-
gboolean bluetooth_client_remove_trust(BluetoothClient *client,
- gchar *adapter, const gchar *address)
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer userdata)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
GtkTreeIter iter;
@@ -1265,8 +1286,14 @@ gboolean bluetooth_client_remove_trust(B
COLUMN_OBJECT, &object, -1);
if (g_ascii_strcasecmp(path, adapter) == 0) {
- adapter_remove_trust_async(object, address,
- remove_trust_reply, NULL);
+ DBusGProxyCall *call;
+ DBusGAsyncData *stuff;
+ stuff = g_new (DBusGAsyncData, 1);
+ stuff->cb = G_CALLBACK (callback);
+ stuff->userdata = userdata;
+ call = adapter_remove_trust_async(object, address,
+ call_reply, stuff);
+ g_object_set_data(G_OBJECT(object), "call", call);
return TRUE;
}
@@ -1386,6 +1413,46 @@ gboolean bluetooth_client_cancel_discove
return FALSE;
}
+gboolean bluetooth_client_cancel_call(BluetoothClient *client,
+ gchar *adapter, const gchar *address)
+{
+ 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) {
+ DBusGProxyCall *call;
+ call = (DBusGProxyCall *)g_object_get_data(G_OBJECT(object), "call");
+ if (call != NULL) {
+ dbus_g_proxy_cancel_call(object, call);
+ g_object_set_data(G_OBJECT(object), "call", NULL);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ cont = gtk_tree_model_iter_next(GTK_TREE_MODEL(priv->store), &iter);
+ }
+
+ return FALSE;
+}
+
GtkTreeModel *bluetooth_client_get_model(BluetoothClient *client)
{
BluetoothClientPrivate *priv = BLUETOOTH_CLIENT_GET_PRIVATE(client);
Index: common/client.h
===================================================================
RCS file: /cvsroot/bluez/gnome/common/client.h,v
retrieving revision 1.24
diff -u -p -r1.24 client.h
--- common/client.h 6 Mar 2008 10:54:29 -0000 1.24
+++ common/client.h 30 Jun 2008 13:05:05 -0000
@@ -99,14 +99,26 @@ const gchar *bluetooth_type_to_string(gu
gboolean bluetooth_client_register_passkey_agent(BluetoothClient *self,
const char *path, const char *address, const void *info);
-gboolean bluetooth_client_create_bonding(BluetoothClient *self,
+typedef void (*bluetooth_client_call_reply) (GError *error, gpointer data);
+
+gboolean bluetooth_client_cancel_call(BluetoothClient *self,
gchar *adapter, const gchar *address);
+gboolean bluetooth_client_create_bonding(BluetoothClient *self,
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer data);
gboolean bluetooth_client_remove_bonding(BluetoothClient *self,
- gchar *adapter, const gchar *address);
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer data);
gboolean bluetooth_client_set_trusted(BluetoothClient *self,
- gchar *adapter, const gchar *address);
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer data);
gboolean bluetooth_client_remove_trust(BluetoothClient *self,
- gchar *adapter, const gchar *address);
+ gchar *adapter, const gchar *address,
+ bluetooth_client_call_reply callback,
+ gpointer data);
gboolean bluetooth_client_disconnect(BluetoothClient *self,
gchar *adapter, const gchar *address);
Index: properties/adapter.c
===================================================================
RCS file: /cvsroot/bluez/gnome/properties/adapter.c,v
retrieving revision 1.22
diff -u -p -r1.22 adapter.c
--- properties/adapter.c 11 Feb 2008 14:34:37 -0000 1.22
+++ properties/adapter.c 30 Jun 2008 13:05:06 -0000
@@ -317,7 +317,7 @@ static void delete_callback(GtkWidget *b
gtk_tree_model_get(model, &iter, COLUMN_ADDRESS, &address, -1);
if (show_confirm_dialog() == TRUE)
- bluetooth_client_remove_bonding(client, adapter->path, address);
+ bluetooth_client_remove_bonding(client, adapter->path, address, NULL, NULL);
g_free(address);
}
@@ -338,9 +338,9 @@ static void trusted_callback(GtkWidget *
COLUMN_TRUSTED, &trusted, -1);
if (trusted == FALSE)
- bluetooth_client_set_trusted(client, adapter->path, address);
+ bluetooth_client_set_trusted(client, adapter->path, address, NULL, NULL);
else
- bluetooth_client_remove_trust(client, adapter->path, address);
+ bluetooth_client_remove_trust(client, adapter->path, address, NULL, NULL);
g_free(address);
}
[-- 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:15 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 [this message]
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
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=1214831713.6764.8.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