[next] telepathy-glib: Make the start() API sync and report errors using a signal
Simon McVittie
smcv at kemper.freedesktop.org
Mon Apr 30 11:04:00 PDT 2012
Module: telepathy-glib
Branch: next
Commit: c5e4e467091a1a578a79e46c0e63456cb31be43c
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c5e4e467091a1a578a79e46c0e63456cb31be43c
Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date: Tue Apr 17 16:48:26 2012 +0200
Make the start() API sync and report errors using a signal
---
docs/reference/telepathy-glib-sections.txt | 3 +-
telepathy-glib/room-list.c | 66 ++++++++++++----------------
telepathy-glib/room-list.h | 8 +---
tests/dbus/room-list.c | 20 +--------
4 files changed, 32 insertions(+), 65 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 2f5716b..44dfabe 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -7244,8 +7244,7 @@ tp_room_list_new_finish
tp_room_list_get_listing
tp_room_list_get_server
tp_room_list_get_account
-tp_room_list_start_listing_async
-tp_room_list_start_listing_finish
+tp_room_list_start
<SUBSECTION Standard>
TP_IS_ROOM_LIST
TP_IS_ROOM_LIST_CLASS
diff --git a/telepathy-glib/room-list.c b/telepathy-glib/room-list.c
index 46a0338..080cb64 100644
--- a/telepathy-glib/room-list.c
+++ b/telepathy-glib/room-list.c
@@ -82,6 +82,7 @@ enum
enum {
SIG_GOT_ROOMS,
+ SIG_FAILED,
LAST_SIGNAL
};
@@ -272,8 +273,11 @@ tp_room_list_class_init (TpRoomListClass *klass)
/**
* TpRoomList::got-rooms:
* @self: a #TpRoomList
+ * @room: a #TpRoomInfo
*
- * TODO
+ * Fired each time a room is found during the listing process.
+ * User should take his own reference on @room if he plans to
+ * continue using it once the signal callback has returned.
*
* Since: UNRELEASED
*/
@@ -284,6 +288,23 @@ tp_room_list_class_init (TpRoomListClass *klass)
G_TYPE_NONE,
1, TP_TYPE_ROOM_INFO);
+ /**
+ * TpRoomList::failed:
+ * @self: a #TpRoomList
+ * @error: a #GError indicating the reason of the error
+ *
+ * Fired when something goes wrong while listing the channels; see @error
+ * for details.
+ *
+ * Since: UNRELEASED
+ */
+ signals[SIG_FAILED] = g_signal_new ("failed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 1, G_TYPE_ERROR);
+
g_type_class_add_private (gobject_class, sizeof (TpRoomListPrivate));
}
@@ -348,62 +369,31 @@ list_rooms_cb (TpChannel *channel,
gpointer user_data,
GObject *weak_object)
{
- GSimpleAsyncResult *result = user_data;
+ TpRoomList *self = TP_ROOM_LIST (weak_object);
if (error != NULL)
{
- g_simple_async_result_set_from_error (result, error);
+ g_signal_emit (self, signals[SIG_FAILED], 0, error);
}
-
- g_simple_async_result_complete (result);
}
/**
- * tp_room_list_start_listing_async:
+ * tp_room_list_start:
* @self: a #TpRoomList
- * @callback: a callback to call when room listing have been started
- * @user_data: data to pass to @callback
*
* Start listing rooms using @self. Use the TpRoomList::got-rooms
* signal to get the rooms found.
+ * Errors will be reported using the TpRoomList::failed signal.
*
* Since: UNRELEASED
*/
void
-tp_room_list_start_listing_async (TpRoomList *self,
- GAsyncReadyCallback callback,
- gpointer user_data)
+tp_room_list_start (TpRoomList *self)
{
- GSimpleAsyncResult *result;
-
g_return_if_fail (self->priv->channel != NULL);
- result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
- tp_room_list_start_listing_async);
-
tp_cli_channel_type_room_list_call_list_rooms (self->priv->channel, -1,
- list_rooms_cb, result, g_object_unref, G_OBJECT (self));
-}
-
-/**
- * tp_room_list_start_listing_finish:
- * @self: a #TpRoomList
- * @result: a #GAsyncResult
- * @error: a #GError to fill
- *
- * <!-- -->
- *
- * Returns: %TRUE if the room listing process has been started,
- * %FALSE otherwise.
- *
- * Since: UNRELEASED
- */
-gboolean
-tp_room_list_start_listing_finish (TpRoomList *self,
- GAsyncResult *result,
- GError **error)
-{
- _tp_implement_finish_void (self, tp_room_list_start_listing_async)
+ list_rooms_cb, NULL, NULL, G_OBJECT (self));
}
static void
diff --git a/telepathy-glib/room-list.h b/telepathy-glib/room-list.h
index 2cb9cc5..5774c6b 100644
--- a/telepathy-glib/room-list.h
+++ b/telepathy-glib/room-list.h
@@ -67,13 +67,7 @@ const gchar * tp_room_list_get_server (TpRoomList *self);
gboolean tp_room_list_get_listing (TpRoomList *self);
-void tp_room_list_start_listing_async (TpRoomList *self,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-gboolean tp_room_list_start_listing_finish (TpRoomList *self,
- GAsyncResult *result,
- GError **error);
+void tp_room_list_start (TpRoomList *self);
G_END_DECLS
diff --git a/tests/dbus/room-list.c b/tests/dbus/room-list.c
index 8d5cb4e..cbc3935 100644
--- a/tests/dbus/room-list.c
+++ b/tests/dbus/room-list.c
@@ -164,21 +164,6 @@ test_properties (Test *test,
}
static void
-start_listing_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- Test *test = user_data;
-
- tp_room_list_start_listing_finish (TP_ROOM_LIST (source),
- result, &test->error);
-
- test->wait--;
- if (test->wait <= 0)
- g_main_loop_quit (test->mainloop);
-}
-
-static void
notify_cb (GObject *object,
GParamSpec *spec,
Test *test)
@@ -215,10 +200,9 @@ test_listing (Test *test,
g_signal_connect (test->room_list, "got-rooms",
G_CALLBACK (got_rooms_cb), test);
- tp_room_list_start_listing_async (test->room_list, start_listing_cb,
- test);
+ tp_room_list_start (test->room_list);
- test->wait = 5;
+ test->wait = 4;
g_main_loop_run (test->mainloop);
g_assert_no_error (test->error);
More information about the telepathy-commits
mailing list