summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-01-13 11:46:18 +0100
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-05-12 12:30:38 +0200
commite76a18cff9e4ccec7d871486b0d20e59560b606f (patch)
tree2a48efabc2f1750edbfc07886472ff3d681c02c2
parent39807f88f0ee729f2dcdf75ba2b73538f4e4b77b (diff)
Add an async variant of start_preparing
-rw-r--r--telepathy-glib/proxy-internal.h8
-rw-r--r--telepathy-glib/proxy.c40
2 files changed, 46 insertions, 2 deletions
diff --git a/telepathy-glib/proxy-internal.h b/telepathy-glib/proxy-internal.h
index 4571735f..2007c271 100644
--- a/telepathy-glib/proxy-internal.h
+++ b/telepathy-glib/proxy-internal.h
@@ -27,13 +27,21 @@ GError *_tp_proxy_take_and_remap_error (TpProxy *self, GError *error)
typedef void (*TpProxyProc) (TpProxy *);
+typedef void (* TpProxyPrepareAsync) (TpProxy *proxy,
+ const TpProxyFeature *feature,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
typedef struct _TpProxyFeaturePrivate TpProxyFeaturePrivate;
struct _TpProxyFeature {
/*<public>*/
GQuark name;
gboolean core;
+
TpProxyProc start_preparing;
+ TpProxyPrepareAsync prepare_async;
+
/*<private>*/
GCallback _reserved[4];
TpProxyFeaturePrivate *priv;
diff --git a/telepathy-glib/proxy.c b/telepathy-glib/proxy.c
index 420a86ea..3fc10870 100644
--- a/telepathy-glib/proxy.c
+++ b/telepathy-glib/proxy.c
@@ -292,7 +292,7 @@ typedef enum {
/* Want to prepare, waiting for dependencies to be satisfied (or maybe
* just poll_features being called) */
FEATURE_STATE_WANTED,
- /* Want to prepare, have called start_preparing */
+ /* Want to prepare, have called start_preparing or prepare_async */
FEATURE_STATE_TRYING,
/* Couldn't prepare, gave up */
FEATURE_STATE_FAILED,
@@ -1775,11 +1775,47 @@ start_preparing_in_idle_cb (gpointer data)
return FALSE;
}
+static gboolean
+prepare_finish (TpProxy *self,
+ GAsyncResult *result,
+ gpointer source,
+ GError **error)
+{
+ _tp_implement_finish_void (self, source);
+}
+
+static void
+feature_prepared_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpProxy *self = (TpProxy *) source;
+ TpProxyFeature *feature = user_data;
+ GError *error = NULL;
+ gboolean prepared = TRUE;
+
+ if (!prepare_finish (self, result, feature->prepare_async, &error))
+ {
+ DEBUG ("Failed to prepare %s: %s", g_quark_to_string (feature->name),
+ error->message);
+
+ prepared = FALSE;
+ g_error_free (error);
+ }
+
+ _tp_proxy_set_feature_prepared (self, feature->name, prepared);
+}
+
static void
prepare_feature (TpProxy *self,
const TpProxyFeature *feature)
{
- if (feature->start_preparing != NULL)
+ if (feature->prepare_async != NULL)
+ {
+ feature->prepare_async (self, feature, feature_prepared_cb,
+ (gpointer) feature);
+ }
+ else if (feature->start_preparing != NULL)
{
/* start_preparing should be async, use an idle for now */
start_preparing_ctx *ctx = start_preparing_ctx_new (self, feature);