soc.2010.detachablepurple: 3bd0a886: Added handling of the close_account_requ...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Sat Jul 31 01:35:52 EDT 2010


----------------------------------------------------------------------
Revision: 3bd0a8862c2036a2b8746566f8c1abcb84084d8c
Parent:   8b83309a890ff2e1f79593c4cda35337bda94a51
Author:   gillux at soc.pidgin.im
Date:     07/30/10 21:08:02
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/3bd0a8862c2036a2b8746566f8c1abcb84084d8c

Changelog: 

Added handling of the close_account_request account uiop, through the new
RequestClosed dbus signal. Now, when a client answer a request, the daemon
will inform the others clients, telling them to close their pending request.

Also moved the implementation of the dbus RunRequest method into a new and
simple purple_callback_run_request() function. This allows us to call this
function not only in the daemon by a client, but also in the client by the
daemon using a signal.

And updated the daemon purple_callback_register_req() call to match the
updates of a previous commit, giving a closing closure as first closure.

Changes against parent 8b83309a890ff2e1f79593c4cda35337bda94a51

  patched  libpurple/dbus-callback.c
  patched  libpurple/dbus-callback.h
  patched  libpurple/dbus-prototypes/callback.xml
  patched  purpled/purpled-account.c

-------------- next part --------------
============================================================
--- libpurple/dbus-callback.c	221b20bd6693435274e288335fa022c6286c8a50
+++ libpurple/dbus-callback.c	97c85b6bfa791e4150a183b86b730294ed3e305b
@@ -66,12 +66,14 @@ enum
 enum
 {
 	SIG_DBUS_RUN_CALLBACK,
+	SIG_DBUS_REQUEST_CLOSED,
 	SIG_LAST
 };
 
 static guint signals[SIG_LAST] = {0, };
 
 static void run_callback_cb(DBusGProxy *proxy, const guint64 callback_id, GPtrArray *params, gpointer data);
+static void request_closed_cb(DBusGProxy *proxy, const guint request_id, gpointer data);
 
 /* This constructor make the singleton thing, using the class field "instance"
  * to store the unique instance of PurpleDBusCallback */
@@ -102,6 +104,11 @@ purple_dbus_callback_constructor(GType t
 			dbus_g_proxy_connect_signal(proxy, "RunCallback",
 			                            G_CALLBACK(run_callback_cb),
 			                            klass->instance, NULL);
+			dbus_g_proxy_add_signal(proxy, "RequestClosed", 
+			                        G_TYPE_UINT, G_TYPE_INVALID);
+			dbus_g_proxy_connect_signal(proxy, "RequestClosed",
+			                        G_CALLBACK(request_closed_cb),
+			                        klass->instance, NULL);
 		}
 	} else {
 		klass->instance = g_object_ref(klass->instance);
@@ -144,6 +151,12 @@ purple_dbus_callback_class_init(PurpleDB
 			 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
 			 purple_smarshal_VOID__UINT64_BOXED,
 			 G_TYPE_NONE, 2, G_TYPE_UINT64, DBUS_GVALUE_ARRAY);
+		signals[SIG_DBUS_REQUEST_CLOSED] =
+			g_signal_new("request_closed",
+			 G_OBJECT_CLASS_TYPE(klass),
+			 G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+			 g_cclosure_marshal_VOID__UINT,
+			 G_TYPE_NONE, 1, G_TYPE_UINT);
 	}
 }
 
@@ -252,6 +265,16 @@ run_callback_cb(DBusGProxy *proxy, const
 	g_hash_table_remove(handler->callbacks, &callback_id);
 }
 
+/**
+ * Callback, called when we receive a dbus "RequestClosed" signal.
+ */
+static void
+request_closed_cb(DBusGProxy *proxy, const guint request_id, gpointer data)
+{
+	/* Forget about this pending request, execute the closing callback */
+	purple_callback_run_request(request_id, 0);
+}
+
 void
 purple_dbus_callback_register(guint64 id, GClosure *closure)
 {
@@ -334,6 +357,13 @@ DBUS_purple_callback_run_request(PurpleD
 gboolean
 DBUS_purple_callback_run_request(PurpleDBusCallback *handler, guint request_id, guint choice, GError** error)
 {
+	return purple_callback_run_request(request_id, choice);
+}
+
+gboolean
+purple_callback_run_request(guint request_id, guint choice)
+{
+	PurpleDBusCallback* handler = g_object_new(PURPLE_TYPE_DBUS_CALLBACK, NULL);
 	GPtrArray *closures;
 	GClosure *closure;
 	void *key = GINT_TO_POINTER(request_id);
============================================================
--- libpurple/dbus-callback.h	93f6bdf2733dc9b83f71daf98125d3e9b9b80a4b
+++ libpurple/dbus-callback.h	b4cbb0f81dcc35f70f866537f6fef24864063d2a
@@ -21,6 +21,8 @@
 #ifndef _DBUS_CALLBACK_H_
 #define _DBUS_CALLBACK_H_
 
+#ifdef HAVE_DBUS
+
 #include "pobject.h"
 
 /* GObject definitions */
@@ -100,13 +102,25 @@ void purple_callback_register_req_id(gui
 void purple_callback_register_req_id(guint request_id, guint n_closures, ...);
 
 /**
- * Client side function that run the RunRequest dbus method on the daemon.
+ * Runs the choice choice of a pending request of id request_id.
+ *
+ * @param request_id The id of the request.
+ * @param choice The choice to answer the request. Giving the choice 0 closes
+ *               the request, and giving a choice > 0 executes that choice
+ *               and then closes the request.
+ * @return TRUE If the request_id request was found, FALSE if not.
  */
+gboolean purple_callback_run_request(guint request_id, guint choice);
+
+/**
+ * Client side purple_callback_run_request() wrapper.
+ */
 void purple_callback_run_request_RPC(guint request_id, guint choice);
 
 /**
- * Daemon side RunRequest dbus method implementation.
+ * Daemon side purple_callback_run_request() wrapper.
  */
 gboolean DBUS_purple_callback_run_request(PurpleDBusCallback *handler, guint request_id, guint choice, GError** error);
 
+#endif /* HAVE_DBUS */
 #endif /* _DBUS_CALLBACK_H_ */
============================================================
--- libpurple/dbus-prototypes/callback.xml	9bce208dc8e2f6000c8ac291d34c32ea71eae2b6
+++ libpurple/dbus-prototypes/callback.xml	eced65596170b2ac12482de77e27d323468cca0c
@@ -10,5 +10,8 @@
 			<arg type="t"  name="callback_id" />
 			<arg type="av" name="args" />
 		</signal>
+		<signal name="RequestClosed">
+			<arg type="u" name="request_id" />
+		</signal>
 	</interface>
 </node>
============================================================
--- purpled/purpled-account.c	93feb368857bb7d4b9b778e1de8e73649cbfdbdb
+++ purpled/purpled-account.c	fd94f2e1d101e208c25275570432b25e6e17d7ce
@@ -51,6 +51,18 @@ purpled_account_request_add(PurpleAccoun
 	                      remote_user, id, alias, message);
 }
 
+static void
+purpled_close_account_request(void *ui_handle)
+{
+	PurpleDBusCallback* handler = g_object_new(PURPLE_TYPE_DBUS_CALLBACK, NULL);
+	guint req_id = GPOINTER_TO_INT(ui_handle);
+
+	g_return_if_fail(req_id > 0);
+
+	/* Send the RequestClosed dbus signal with the request id */
+	g_signal_emit_by_name(handler, "request_closed", req_id);
+}
+
 /**
  * PurpleAccountUiOps.request_authorize daemon iuop.
  * Sends the RequestAuthorize dbus signal and return a unique request id
@@ -68,14 +80,21 @@ purpled_account_request_authorize(Purple
 	guint req_id;
 	GClosure *auth_closure;
 	GClosure *deny_closure;
+	GClosure *close_closure;
 
 	/* Store the callbacks for later call, by a RunRequest dbus method on
 	 * the PurpleDBusCallback object */
 	auth_closure = g_cclosure_new(G_CALLBACK(auth_cb), data, NULL);
 	deny_closure = g_cclosure_new(G_CALLBACK(deny_cb), data, NULL);
+	close_closure = g_cclosure_new(
+	                             G_CALLBACK(purpled_close_account_request),
+	                             NULL, NULL);
 	g_closure_set_marshal(auth_closure, purple_nullmarshaller);
 	g_closure_set_marshal(deny_closure, purple_nullmarshaller);
-	req_id = purple_callback_register_req(2, auth_closure, deny_closure);
+	g_closure_set_marshal(close_closure, purple_nullmarshaller);
+	req_id = purple_callback_register_req(3, close_closure, auth_closure,
+	                                      deny_closure);
+	close_closure->data = GINT_TO_POINTER(req_id);
 	g_return_val_if_fail(req_id > 0, NULL);
 
 	/* Send the RequestAuthorize dbus signal with this new request id */
@@ -91,7 +110,7 @@ static PurpleAccountUiOps purpled_accoun
 	NULL,                                         /* status_changed */
 	purpled_account_request_add,                     /* request_add */
 	purpled_account_request_authorize,         /* request_authorize */
-	NULL,                                  /* close_account_request */
+	purpled_close_account_request,         /* close_account_request */
 	NULL,                                      /* _purple_reserved1 */
 	NULL,                                      /* _purple_reserved2 */
 	NULL,                                      /* _purple_reserved3 */


More information about the Commits mailing list