Google
  Web www.spinics.net

Re: Wizard patch

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


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

[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Free Online Dating]     [Linux Kernel]     [Linux SCSI]     [XFree86]

Add to Google Powered by Linux