diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-01-13 11:49:43 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-05-12 12:30:38 +0200 |
commit | bd04c89e24d573974c8f05c05f3a9c6cb6805725 (patch) | |
tree | 6963f1080574cf2addab3773837f98cbcbfbef54 /telepathy-glib/text-channel.c | |
parent | e76a18cff9e4ccec7d871486b0d20e59560b606f (diff) | |
download | telepathy-glib-bd04c89e24d573974c8f05c05f3a9c6cb6805725.tar.gz |
TpTextChanne: implement prepare_async instead of start_preparing
Diffstat (limited to 'telepathy-glib/text-channel.c')
-rw-r--r-- | telepathy-glib/text-channel.c | 78 |
1 files changed, 58 insertions, 20 deletions
diff --git a/telepathy-glib/text-channel.c b/telepathy-glib/text-channel.c index dec83cdd9..2bebba83d 100644 --- a/telepathy-glib/text-channel.c +++ b/telepathy-glib/text-channel.c @@ -662,6 +662,33 @@ free_parts_list (gpointer data) g_list_free (parts_list); } +typedef struct +{ + GList *parts_list; + GSimpleAsyncResult *result; +} IdentifyMessagesCtx; + +/* Take the ref on @parts_list */ +static IdentifyMessagesCtx * +identify_messages_ctx_new (GList *parts_list, + GSimpleAsyncResult *result) +{ + IdentifyMessagesCtx *ctx = g_slice_new (IdentifyMessagesCtx); + + ctx->parts_list = parts_list; + ctx->result = g_object_ref (result); + return ctx; +} + +static void +identify_messages_free (IdentifyMessagesCtx *ctx) +{ + free_parts_list (ctx->parts_list); + g_object_unref (ctx->result); + + g_slice_free (IdentifyMessagesCtx, ctx); +} + /* There is no TP_ARRAY_TYPE_PENDING_TEXT_MESSAGE_LIST_LIST (fdo #32433) */ #define ARRAY_TYPE_PENDING_TEXT_MESSAGE_LIST_LIST dbus_g_type_get_collection (\ "GPtrArray", TP_ARRAY_TYPE_MESSAGE_PART_LIST) @@ -673,7 +700,8 @@ get_pending_messages_cb (TpProxy *proxy, gpointer user_data, GObject *weak_object) { - TpTextChannel *self = user_data; + TpTextChannel *self = (TpTextChannel *) weak_object; + GSimpleAsyncResult *result = user_data; guint i; GPtrArray *messages; TpIntSet *senders; @@ -686,18 +714,20 @@ get_pending_messages_cb (TpProxy *proxy, { DEBUG ("Failed to get PendingMessages property: %s", error->message); - _tp_proxy_set_feature_prepared (proxy, - TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, FALSE); - return; + g_simple_async_result_set_error (result, error->domain, error->code, + "Failed to get PendingMessages property: %s", error->message); + + g_simple_async_result_complete (result); } if (!G_VALUE_HOLDS (value, ARRAY_TYPE_PENDING_TEXT_MESSAGE_LIST_LIST)) { DEBUG ("PendingMessages property is of the wrong type"); - _tp_proxy_set_feature_prepared (proxy, - TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, FALSE); - return; + g_simple_async_result_set_error (result, TP_ERRORS, TP_ERROR_CONFUSED, + "PendingMessages property is of the wrong type"); + + g_simple_async_result_complete (result); } senders = tp_intset_new (); @@ -739,12 +769,13 @@ get_pending_messages_cb (TpProxy *proxy, if (tp_intset_size (senders) == 0) { - _tp_proxy_set_feature_prepared (proxy, - TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, TRUE); + g_simple_async_result_complete (result); } else { TpConnection *conn; + IdentifyMessagesCtx *ctx = identify_messages_ctx_new (parts_list, + result); parts_list = g_list_reverse (parts_list); @@ -758,8 +789,8 @@ get_pending_messages_cb (TpProxy *proxy, /* Use the sender ID rather than the handles */ tp_connection_get_contacts_by_id (conn, sender_ids->len, (const gchar * const *) sender_ids->pdata, - 0, NULL, got_pending_senders_contact_by_id_cb, parts_list, - free_parts_list, G_OBJECT (self)); + 0, NULL, got_pending_senders_contact_by_id_cb, ctx, + (GDestroyNotify) identify_messages_free, G_OBJECT (self)); } else { @@ -767,8 +798,8 @@ get_pending_messages_cb (TpProxy *proxy, tp_connection_get_contacts_by_handle (conn, tmp->len, (TpHandle *) tmp->data, - 0, NULL, got_pending_senders_contact_by_handle_cb, parts_list, - free_parts_list, G_OBJECT (self)); + 0, NULL, got_pending_senders_contact_by_handle_cb, ctx, + (GDestroyNotify) identify_messages_free, G_OBJECT (self)); g_array_unref (tmp); } @@ -779,10 +810,17 @@ get_pending_messages_cb (TpProxy *proxy, } static void -tp_text_channel_prepare_pending_messages (TpProxy *proxy) +tp_text_channel_prepare_pending_messages_async (TpProxy *proxy, + const TpProxyFeature *feature, + GAsyncReadyCallback callback, + gpointer user_data) { TpChannel *channel = (TpChannel *) proxy; GError *error = NULL; + GSimpleAsyncResult *result; + + result = g_simple_async_result_new ((GObject *) proxy, callback, user_data, + tp_text_channel_prepare_pending_messages_async); tp_cli_channel_interface_messages_connect_to_message_received (channel, message_received_cb, proxy, NULL, G_OBJECT (proxy), &error); @@ -804,15 +842,15 @@ tp_text_channel_prepare_pending_messages (TpProxy *proxy) tp_cli_dbus_properties_call_get (proxy, -1, TP_IFACE_CHANNEL_INTERFACE_MESSAGES, "PendingMessages", - get_pending_messages_cb, proxy, NULL, G_OBJECT (proxy)); + get_pending_messages_cb, result, g_object_unref, G_OBJECT (proxy)); return; fail: - g_error_free (error); + g_simple_async_result_take_error (result, error); - _tp_proxy_set_feature_prepared (proxy, - TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES, FALSE); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } enum { @@ -830,8 +868,8 @@ tp_text_channel_list_features (TpProxyClass *cls G_GNUC_UNUSED) features[FEAT_PENDING_MESSAGES].name = TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES; - features[FEAT_PENDING_MESSAGES].start_preparing = - tp_text_channel_prepare_pending_messages; + features[FEAT_PENDING_MESSAGES].prepare_async = + tp_text_channel_prepare_pending_messages_async; /* assert that the terminator at the end is there */ g_assert (features[N_FEAT].name == 0); |