telepathy-glib: TpHandleRepoIface: add tp_handle_ensure_async()
Xavier Claessens
xclaesse at kemper.freedesktop.org
Thu Jun 28 04:52:14 PDT 2012
Module: telepathy-glib
Branch: master
Commit: 25a3af6923d9e17ff4d6ae3e1bcf9322e7da3731
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=25a3af6923d9e17ff4d6ae3e1bcf9322e7da3731
Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date: Tue May 29 12:49:39 2012 +0200
TpHandleRepoIface: add tp_handle_ensure_async()
A default implementation is provided that just use tp_handle_ensure()
and return the handle in an idle callback.
https://bugs.freedesktop.org/show_bug.cgi?id=50341
---
docs/reference/telepathy-glib-sections.txt | 2 +
telepathy-glib/handle-repo-internal.h | 10 +++
telepathy-glib/handle-repo.c | 99 ++++++++++++++++++++++++++++
telepathy-glib/handle-repo.h | 17 +++++
4 files changed, 128 insertions(+), 0 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index edf30c9..a2fabbc 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -257,6 +257,8 @@ tp_handle_set_qdata
tp_handle_get_qdata
tp_handle_ensure
tp_handle_lookup
+tp_handle_ensure_async
+tp_handle_ensure_finish
<SUBSECTION Standard>
TP_HANDLE_REPO_IFACE
TP_IS_HANDLE_REPO_IFACE
diff --git a/telepathy-glib/handle-repo-internal.h b/telepathy-glib/handle-repo-internal.h
index 9441fc0..931a51c 100644
--- a/telepathy-glib/handle-repo-internal.h
+++ b/telepathy-glib/handle-repo-internal.h
@@ -74,6 +74,16 @@ struct _TpHandleRepoIfaceClass {
TpHandle (*lookup_handle) (TpHandleRepoIface *self, const char *id,
gpointer context, GError **error);
+ void (*ensure_handle_async) (TpHandleRepoIface *self,
+ TpBaseConnection *connection,
+ const gchar *id,
+ gpointer context,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ TpHandle (*ensure_handle_finish) (TpHandleRepoIface *self,
+ GAsyncResult *result,
+ GError **error);
+
void (*set_qdata) (TpHandleRepoIface *repo, TpHandle handle,
GQuark key_id, gpointer data, GDestroyNotify destroy);
gpointer (*get_qdata) (TpHandleRepoIface *repo, TpHandle handle,
diff --git a/telepathy-glib/handle-repo.c b/telepathy-glib/handle-repo.c
index 4918831..f58f975 100644
--- a/telepathy-glib/handle-repo.c
+++ b/telepathy-glib/handle-repo.c
@@ -37,6 +37,7 @@
#include <telepathy-glib/handle-repo.h>
#include <telepathy-glib/handle-repo-internal.h>
+#include <telepathy-glib/util-internal.h>
G_DEFINE_INTERFACE (TpHandleRepoIface, tp_handle_repo_iface, G_TYPE_OBJECT);
@@ -302,6 +303,54 @@ tp_handle_ensure (TpHandleRepoIface *self,
id, context, error);
}
+/**
+ * tp_handle_ensure_async: (skip)
+ * @self: A handle repository implementation
+ * @connection: the #TpBaseConnection using this handle repo
+ * @id: A string whose handle is required
+ * @context: User data to be passed to the normalization callback
+ * @callback: a callback to call when the operation finishes
+ * @user_data: data to pass to @callback
+ *
+ * Asyncronously normalize an identifier and create an handle for it. This could
+ * involve a server round-trip. This should be used instead of
+ * tp_handle_ensure() for user provided contact identifiers, but it is not
+ * necessary for identifiers from the server.
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_handle_ensure_async (TpHandleRepoIface *self,
+ TpBaseConnection *connection,
+ const gchar *id,
+ gpointer context,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ return TP_HANDLE_REPO_IFACE_GET_CLASS (self)->ensure_handle_async (self,
+ connection, id, context, callback, user_data);
+}
+
+/**
+ * tp_handle_ensure_finish: (skip)
+ * @self: A handle repository implementation
+ * @result: a #GAsyncResult
+ * @error: a #GError to fill
+ *
+ * Finishes tp_handle_ensure_async()
+ *
+ * Returns: non-0 #TpHandle if the operation was successful, otherwise 0.
+ *
+ * Since: 0.UNRELEASED
+ */
+TpHandle
+tp_handle_ensure_finish (TpHandleRepoIface *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ return TP_HANDLE_REPO_IFACE_GET_CLASS (self)->ensure_handle_finish (self,
+ result, error);
+}
/**
* tp_handle_lookup: (skip)
@@ -378,10 +427,60 @@ tp_handle_get_qdata (TpHandleRepoIface *repo, TpHandle handle,
}
static void
+default_ensure_handle_async (TpHandleRepoIface *self,
+ TpBaseConnection *connection,
+ const gchar *id,
+ gpointer context,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ TpHandle handle;
+ GError *error = NULL;
+
+ result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+ default_ensure_handle_async);
+
+ handle = tp_handle_ensure (self, id, context, &error);
+ if (handle == 0)
+ {
+ g_simple_async_result_take_error (result, error);
+ }
+ else
+ {
+ g_simple_async_result_set_op_res_gpointer (result,
+ GUINT_TO_POINTER (handle), NULL);
+ }
+
+ g_simple_async_result_complete_in_idle (result);
+
+ g_object_unref (result);
+}
+
+static TpHandle
+default_ensure_handle_finish (TpHandleRepoIface *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple = (GSimpleAsyncResult *) result;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (self), NULL), 0);
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return 0;
+
+ return GPOINTER_TO_UINT (g_simple_async_result_get_op_res_gpointer (simple));
+}
+
+static void
tp_handle_repo_iface_default_init (TpHandleRepoIfaceInterface *iface)
{
GParamSpec *param_spec;
+ iface->ensure_handle_async = default_ensure_handle_async;
+ iface->ensure_handle_finish = default_ensure_handle_finish;
+
param_spec = g_param_spec_uint ("handle-type", "Handle type",
"The TpHandleType held in this handle repository.",
0, G_MAXUINT32, 0,
diff --git a/telepathy-glib/handle-repo.h b/telepathy-glib/handle-repo.h
index 99d9933..ec6f1ad 100644
--- a/telepathy-glib/handle-repo.h
+++ b/telepathy-glib/handle-repo.h
@@ -30,11 +30,16 @@
#include <glib-object.h>
+#include <gio/gio.h>
+
#include <telepathy-glib/intset.h>
#include <telepathy-glib/handle.h>
G_BEGIN_DECLS
+/* Forward declaration to avoid circular includes */
+typedef struct _TpBaseConnection TpBaseConnection;
+
/* Forward declaration because it's in the HandleRepo API */
#define TP_TYPE_HANDLE_SET (tp_handle_set_get_type ())
@@ -115,6 +120,18 @@ TpHandle tp_handle_ensure (TpHandleRepoIface *self,
const gchar *id, gpointer context, GError **error)
G_GNUC_WARN_UNUSED_RESULT;
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_handle_ensure_async (TpHandleRepoIface *self,
+ TpBaseConnection *connection,
+ const gchar *id,
+ gpointer context,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+_TP_AVAILABLE_IN_UNRELEASED
+TpHandle tp_handle_ensure_finish (TpHandleRepoIface *self,
+ GAsyncResult *result,
+ GError **error);
+
void tp_handle_set_qdata (TpHandleRepoIface *repo, TpHandle handle,
GQuark key_id, gpointer data, GDestroyNotify destroy);
gpointer tp_handle_get_qdata (TpHandleRepoIface *repo, TpHandle handle,
More information about the telepathy-commits
mailing list