[Galago-commits] r2842 - in trunk/libgalago: . libgalago tests
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Mon Jun 12 02:07:46 PDT 2006
Author: chipx86
Date: 2006-06-12 02:07:38 -0700 (Mon, 12 Jun 2006)
New Revision: 2842
Modified:
trunk/libgalago/ChangeLog
trunk/libgalago/libgalago/galago-account.c
trunk/libgalago/libgalago/galago-account.h
trunk/libgalago/tests/check-libgalago.c
Log:
Added galago_account_get_presence_async().
Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog 2006-06-12 08:52:29 UTC (rev 2841)
+++ trunk/libgalago/ChangeLog 2006-06-12 09:07:38 UTC (rev 2842)
@@ -1,3 +1,10 @@
+Mon Jun 12 02:05:46 PDT 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-account.c:
+ * libgalago/galago-account.h:
+ * tests/check-libgalago.c:
+ - Added galago_account_get_presence_async().
+
Mon Jun 12 01:51:43 PDT 2006 Christian Hammond <chipx86 at chipx86.com>
* libgalago/galago-core.c:
Modified: trunk/libgalago/libgalago/galago-account.c
===================================================================
--- trunk/libgalago/libgalago/galago-account.c 2006-06-12 08:52:29 UTC (rev 2841)
+++ trunk/libgalago/libgalago/galago-account.c 2006-06-12 09:07:38 UTC (rev 2842)
@@ -1015,25 +1015,98 @@
GalagoPresence *
galago_account_get_presence(const GalagoAccount *account, gboolean query)
{
+ GalagoPresence *presence;
+
g_return_val_if_fail(account != NULL, NULL);
g_return_val_if_fail(GALAGO_IS_ACCOUNT(account), NULL);
- if (account->priv->presence == NULL && query &&
+ presence = account->priv->presence;
+
+ if (presence == NULL && query &&
GALAGO_OBJECT_IS_REMOTE(account) && !galago_is_daemon() &&
galago_is_connected())
{
- account->priv->presence =
+ presence =
galago_dbus_send_message_with_reply(GALAGO_OBJECT(account),
"GetPresence",
galago_value_new_object(GALAGO_TYPE_PRESENCE, NULL),
NULL);
- g_object_notify(G_OBJECT(account), "presence");
}
- return account->priv->presence;
+ return presence;
}
/**
+ * galago_account_get_presence_async
+ * @account: The account.
+ * @cb: The callback function that will be passed the presence.
+ * @user_data: Custom data to pass to the callback function.
+ * @free_func: Optional function to free @user_data when the request completes.
+ *
+ * Asynchronously retrieves the presence associated with the specified
+ * account.
+ *
+ * For example:
+ * <informalexample>
+ * <programlisting>
+ * static void
+ * presence_received_cb(GalagoAccount *account,
+ * GalagoPresence *presence,
+ * gpointer user_data)
+ * {
+ * }
+ *
+ * static void
+ * get_presence(GalagoAccount *account)
+ * {
+ * GalagoCallHandle handle;
+ *
+ * handle = galago_account_get_presence_async(account,
+ * presence_received_cb,
+ * NULL, NULL);
+ * }
+ * </programlisting>
+ * </informalexample>
+ *
+ * Returns: A valid #GalagoCallHandle on success. On error, this will return
+ * %GALAGO_CALL_HANDLE_INVALID.
+ *
+ * Since: 0.5.2
+ */
+GalagoCallHandle
+galago_account_get_presence_async(const GalagoAccount *account,
+ GalagoAccountPresenceCb cb,
+ gpointer user_data,
+ GFreeFunc free_func)
+{
+ GalagoPresence *presence;
+ GalagoCallHandle handle = GALAGO_CALL_HANDLE_INVALID;
+
+ g_return_val_if_fail(account != NULL, handle);
+ g_return_val_if_fail(GALAGO_IS_ACCOUNT(account), handle);
+ g_return_val_if_fail(cb != NULL, handle);
+
+ presence = galago_account_get_presence(account, FALSE);
+
+ if (presence != NULL)
+ {
+ cb((GalagoAccount *)account, presence, user_data);
+ handle = galago_calls_request_dummy_handle();
+ }
+ else if (GALAGO_OBJECT_IS_REMOTE(account) && !galago_is_daemon() &&
+ galago_is_connected())
+ {
+ handle = galago_dbus_send_message_with_reply_async(
+ GALAGO_OBJECT(account), "GetPresence", G_CALLBACK(cb),
+ user_data, free_func, g_cclosure_marshal_VOID__POINTER,
+ galago_value_new_object(GALAGO_TYPE_PRESENCE, NULL),
+ NULL);
+ }
+
+ return handle;
+}
+
+/**
* galago_account_set_avatar
* @account: The account.
* @avatar: The avatar to set.
Modified: trunk/libgalago/libgalago/galago-account.h
===================================================================
--- trunk/libgalago/libgalago/galago-account.h 2006-06-12 08:52:29 UTC (rev 2841)
+++ trunk/libgalago/libgalago/galago-account.h 2006-06-12 09:07:38 UTC (rev 2842)
@@ -31,6 +31,9 @@
#include <libgalago/galago-presence.h>
#include <libgalago/galago-service.h>
+typedef void (*GalagoAccountPresenceCb)(GalagoAccount *, GalagoPresence *,
+ gpointer);
+
struct _GalagoAccount
{
GalagoObject parent_object;
@@ -113,6 +116,11 @@
GalagoPresence *galago_account_create_presence(GalagoAccount *account);
GalagoPresence *galago_account_get_presence(const GalagoAccount *account,
gboolean query);
+GalagoCallHandle galago_account_get_presence_async(
+ const GalagoAccount *account,
+ GalagoAccountPresenceCb cb,
+ gpointer user_data,
+ GFreeFunc free_func);
void galago_account_set_avatar(GalagoAccount *account, GalagoImage *avatar);
GalagoImage *galago_account_get_avatar(const GalagoAccount *account,
Modified: trunk/libgalago/tests/check-libgalago.c
===================================================================
--- trunk/libgalago/tests/check-libgalago.c 2006-06-12 08:52:29 UTC (rev 2841)
+++ trunk/libgalago/tests/check-libgalago.c 2006-06-12 09:07:38 UTC (rev 2842)
@@ -440,6 +440,47 @@
}
END_TEST
+static void
+presence_received_cb(GalagoAccount *account, GalagoPresence *presence,
+ gpointer user_data)
+{
+ GMainLoop *loop = (GMainLoop *)user_data;
+
+ fail_unless(account != NULL && GALAGO_IS_ACCOUNT(account) &&
+ !strcmp(galago_account_get_username(account), "GalagoAIMUser"),
+ "Retrieved incorrect account parameter.");
+
+ fail_unless(presence != NULL && GALAGO_IS_PRESENCE(presence),
+ "Retrieved incorrect presence parameter.");
+
+ g_main_loop_quit(loop);
+}
+
+START_TEST(test_account_get_presence_async)
+{
+ GalagoService *service;
+ GalagoAccount *account;
+ GMainLoop *loop;
+
+ loop = g_main_loop_new(NULL, FALSE);
+
+ galago_init("check-libgalago", GALAGO_INIT_CLIENT);
+
+ service = galago_get_service("aim", GALAGO_REMOTE, TRUE);
+ fail_unless(service != NULL,
+ "Couldn't fetch aim service. Is presence-feed running?");
+
+ account = galago_service_get_account(service, "GalagoAIMUser", TRUE);
+ fail_unless(service != NULL,
+ "Couldn't fetch GalagoAIMUser. Is presence-feed running?");
+
+ galago_account_get_presence_async(account, presence_received_cb, loop,
+ NULL);
+
+ g_main_loop_run(loop);
+}
+END_TEST
+
/**************************************************************************
* Core tests
**************************************************************************/
@@ -495,6 +536,7 @@
/* Test asynchronous queries */
ADD_TCASE("core_get_service_async", test_core_get_service_async);
ADD_TCASE("service_get_account_async", test_service_get_account_async);
+ ADD_TCASE("account_get_presence_async", test_account_get_presence_async);
return s;
}
More information about the galago-commits
mailing list