[Galago-commits] r2366 - in trunk/libgalago: . libgalago tests
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Sun Dec 4 04:37:18 PST 2005
Author: chipx86
Date: 2005-12-04 04:37:14 -0800 (Sun, 04 Dec 2005)
New Revision: 2366
Modified:
trunk/libgalago/ChangeLog
trunk/libgalago/NEWS
trunk/libgalago/libgalago/galago-core.c
trunk/libgalago/libgalago/galago-marshal.list
trunk/libgalago/libgalago/galago-person.c
trunk/libgalago/tests/check-libgalago.c
Log:
- Added support for setting a custom priority account calculation function. To set this, connect to the "calc_priority_account" signal on galago_get_core() and return the priority account. If the handlers return NULL, the default calculation function is used.
- Added unit tests for priority account calculation.
Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/ChangeLog 2005-12-04 12:37:14 UTC (rev 2366)
@@ -1,3 +1,16 @@
+Sun Dec 04 04:36:39 PST 2005 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-core.c:
+ * libgalago/galago-marshal.list:
+ * libgalago/galago-person.c:
+ * tests/check-libgalago.c:
+ * NEWS:
+ - Added support for setting a custom priority account calculation
+ function. To set this, connect to the "calc_priority_account"
+ signal on galago_get_core() and return the priority account. If
+ the handlers return NULL, the default calculation function is used.
+ - Added unit tests for priority account calculation.
+
Sun Dec 04 02:58:27 PST 2005 Christian Hammond <chipx86 at chipx86.com>
* docs/protocol/protocol.hh:
Modified: trunk/libgalago/NEWS
===================================================================
--- trunk/libgalago/NEWS 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/NEWS 2005-12-04 12:37:14 UTC (rev 2366)
@@ -61,6 +61,10 @@
property should be used,
- Re-implemented the "account-added" and "account-removed" signals.
- galago_person_{set,get}_photo() now takes/returns a GalagoImage *.
+ - Added support for setting a custom priority account calculation
+ function. To set this, connect to the "calc_priority_account" signal
+ on galago_get_core() and return the priority account. If the
+ handlers return NULL, the default calculation function is used.
GalagoPhoto:
- Removed in favor of GalagoImage.
Modified: trunk/libgalago/libgalago/galago-core.c
===================================================================
--- trunk/libgalago/libgalago/galago-core.c 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/libgalago/galago-core.c 2005-12-04 12:37:14 UTC (rev 2366)
@@ -71,6 +71,8 @@
void (*service_removed)(GalagoCore *core, GalagoService *service);
void (*person_added)(GalagoCore *core, GalagoPerson *person);
void (*person_removed)(GalagoCore *core, GalagoPerson *person);
+ GalagoAccount *(*calc_priority_account)(GalagoCore *core,
+ GalagoPerson *person);
} GalagoCoreClass;
@@ -82,11 +84,16 @@
SERVICE_REMOVED,
PERSON_ADDED,
PERSON_REMOVED,
+ CALC_PRIORITY_ACCOUNT,
LAST_SIGNAL
};
#define GALAGO_DAEMON_ID "#galago-daemon#"
+/* galago-person.c */
+GalagoAccount *_galago_person_real_calc_priority_account(GalagoCore *unused,
+ GalagoPerson *person);
+
static void _galago_core_disconnect(void);
static gboolean _galago_dbus_register_connection(void);
static void _galago_dbus_unregister_connection(void);
@@ -118,6 +125,28 @@
G_DEFINE_TYPE(GalagoCore, galago_core, GALAGO_TYPE_OBJECT);
+static gboolean
+_galago_accumulator_account_handled(GSignalInvocationHint *ihint,
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer unused)
+{
+ gboolean continue_emission = FALSE;
+ GalagoAccount *account;
+
+ account = g_value_get_object(handler_return);
+
+ if (account == NULL || !GALAGO_IS_ACCOUNT(account))
+ {
+ account = NULL;
+ continue_emission = TRUE;
+ }
+
+ g_value_set_object(return_accu, account);
+
+ return continue_emission;
+}
+
static void
galago_core_class_init(GalagoCoreClass *klass)
{
@@ -130,6 +159,8 @@
gobject_class->finalize = galago_core_finalize;
+ klass->calc_priority_account = _galago_person_real_calc_priority_account;
+
signals[REGISTERED] =
g_signal_new("registered",
G_TYPE_FROM_CLASS(klass),
@@ -154,9 +185,9 @@
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(GalagoCoreClass, service_added),
NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
+ g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ GALAGO_TYPE_SERVICE);
signals[SERVICE_REMOVED] =
g_signal_new("service_removed",
@@ -164,9 +195,9 @@
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(GalagoCoreClass, service_removed),
NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
+ g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ GALAGO_TYPE_SERVICE);
signals[PERSON_ADDED] =
g_signal_new("person_added",
@@ -174,9 +205,9 @@
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(GalagoCoreClass, person_added),
NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
+ g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ GALAGO_TYPE_SERVICE);
signals[PERSON_REMOVED] =
g_signal_new("person_removed",
@@ -184,9 +215,20 @@
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(GalagoCoreClass, person_removed),
NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
+ g_cclosure_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- G_TYPE_POINTER);
+ GALAGO_TYPE_SERVICE);
+
+ signals[CALC_PRIORITY_ACCOUNT] =
+ g_signal_new("calc_priority_account",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GalagoCoreClass, calc_priority_account),
+ _galago_accumulator_account_handled,
+ NULL,
+ galago_marshal_OBJECT__OBJECT,
+ GALAGO_TYPE_ACCOUNT, 1,
+ GALAGO_TYPE_PERSON);
}
static void
@@ -748,6 +790,14 @@
g_signal_emit(_core, signals[UNREGISTERED], 0);
}
+GalagoAccount *
+_galago_core_calc_priority_account(const GalagoPerson *person)
+{
+ GalagoAccount *account = NULL;
+ g_signal_emit(_core, signals[CALC_PRIORITY_ACCOUNT], 0, person, &account);
+ return account;
+}
+
static void
_exit_galago(void)
{
Modified: trunk/libgalago/libgalago/galago-marshal.list
===================================================================
--- trunk/libgalago/libgalago/galago-marshal.list 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/libgalago/galago-marshal.list 2005-12-04 12:37:14 UTC (rev 2366)
@@ -1,2 +1,3 @@
VOID:BOOLEAN,ULONG
VOID:POINTER,STRING
+OBJECT:OBJECT
Modified: trunk/libgalago/libgalago/galago-person.c
===================================================================
--- trunk/libgalago/libgalago/galago-person.c 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/libgalago/galago-person.c 2005-12-04 12:37:14 UTC (rev 2366)
@@ -62,6 +62,9 @@
LAST_SIGNAL
};
+/* galago-core.c */
+GalagoAccount *_galago_core_calc_priority_account(const GalagoPerson *person);
+
static GalagoPerson *_galago_create_person_common(const char *id,
GalagoOrigin origin,
const char *obj_path);
@@ -567,15 +570,13 @@
}
GalagoAccount *
-galago_person_get_priority_account(const GalagoPerson *person)
+_galago_person_real_calc_priority_account(GObject *unused,
+ GalagoPerson *person)
{
GList *l, *accounts;
GalagoPresence *priority_presence = NULL;
GalagoAccount *account = NULL;
- g_return_val_if_fail(person != NULL, NULL);
- g_return_val_if_fail(GALAGO_IS_PERSON(person), NULL);
-
for (l = accounts = galago_person_get_accounts(person, TRUE);
l != NULL;
l = l->next)
@@ -599,6 +600,18 @@
return account;
}
+GalagoAccount *
+galago_person_get_priority_account(const GalagoPerson *person)
+{
+ g_return_val_if_fail(person != NULL, NULL);
+ g_return_val_if_fail(GALAGO_IS_PERSON(person), NULL);
+
+ if (galago_person_get_accounts(person, TRUE) == NULL)
+ return NULL;
+
+ return _galago_core_calc_priority_account(person);
+}
+
void
galago_person_add_account(GalagoPerson *person, GalagoAccount *account)
{
Modified: trunk/libgalago/tests/check-libgalago.c
===================================================================
--- trunk/libgalago/tests/check-libgalago.c 2005-12-04 11:24:05 UTC (rev 2365)
+++ trunk/libgalago/tests/check-libgalago.c 2005-12-04 12:37:14 UTC (rev 2366)
@@ -66,6 +66,22 @@
/**************************************************************************
* libgalago tests
**************************************************************************/
+START_TEST(test_init_reinit)
+{
+ fail_unless(galago_init("check-libgalago", FALSE),
+ "Unable to initialize libgalago");
+
+ galago_uninit();
+
+ fail_unless(galago_init("check-libgalago", FALSE),
+ "Unable to re-initialize libgalago");
+}
+END_TEST
+
+
+/**************************************************************************
+ * Test object creation
+ **************************************************************************/
START_TEST(test_create_person)
{
galago_init("check-libgalago", FALSE);
@@ -87,6 +103,10 @@
}
END_TEST
+
+/**************************************************************************
+ * Test D-BUS object signature support
+ **************************************************************************/
static void
test_signature(GType type, GalagoObject *object)
{
@@ -164,19 +184,76 @@
}
END_TEST
-START_TEST(test_init_reinit)
+
+/**************************************************************************
+ * Test the Person object
+ **************************************************************************/
+static GalagoAccount *
+dummy_calc_priority_account(GObject *unused, GalagoPerson *person)
{
- fail_unless(galago_init("check-libgalago", FALSE),
- "Unable to initialize libgalago");
+ return NULL;
+}
- galago_uninit();
+static GalagoAccount *
+custom_calc_priority_account(GObject *unused, GalagoPerson *person)
+{
+ GList *accounts = galago_person_get_accounts(person, TRUE);
- fail_unless(galago_init("check-libgalago", FALSE),
- "Unable to re-initialize libgalago");
+ fail_unless(accounts != NULL, "Account list of person is missing!");
+ return accounts->data;
}
+
+START_TEST(test_person_priority_accounts)
+{
+ GalagoPerson *person;
+ GalagoService *service;
+ GalagoPresence *presence;
+ GalagoAccount *account1, *account2;
+ GalagoAccount *priority_account;
+ gulong conn_id;
+
+ galago_init("check-libgalago", FALSE);
+
+ person = make_dummy_person();
+ service = make_dummy_service();
+
+ account1 = galago_service_create_account(service, person, "account-1");
+ presence = galago_account_create_presence(account1);
+ galago_presence_set_idle(presence, TRUE, time(NULL));
+
+ account2 = galago_service_create_account(service, person, "account-2");
+ presence = galago_account_create_presence(account2);
+
+ priority_account = galago_person_get_priority_account(person);
+
+ fail_unless(priority_account != NULL,
+ "Returned priority account was NULL");
+ fail_unless(priority_account == account2,
+ "Default priority account calculation failed");
+
+ /* Test with a dummy handler. */
+ conn_id = g_signal_connect(galago_get_core(), "calc_priority_account",
+ G_CALLBACK(dummy_calc_priority_account), NULL);
+ priority_account = galago_person_get_priority_account(person);
+ fail_unless(priority_account != NULL,
+ "Returned priority account was NULL");
+ fail_unless(priority_account == account2,
+ "Dummy priority account fallback calculation failed");
+ g_signal_handler_disconnect(galago_get_core(), conn_id);
+
+
+ /* Test with a real handler. */
+ conn_id = g_signal_connect(galago_get_core(), "calc_priority_account",
+ G_CALLBACK(custom_calc_priority_account), NULL);
+ priority_account = galago_person_get_priority_account(person);
+ fail_unless(priority_account != NULL,
+ "Returned priority account was NULL");
+ fail_unless(priority_account == account1,
+ "Custom priority account calculation failed");
+ g_signal_handler_disconnect(galago_get_core(), conn_id);
+}
END_TEST
-
/**************************************************************************
* Core tests
**************************************************************************/
@@ -218,6 +295,9 @@
ADD_TCASE("dbus_signature_service", test_dbus_signature_service);
ADD_TCASE("dbus_signature_status", test_dbus_signature_status);
+ /* Test the Person object */
+ ADD_TCASE("person_priority_accounts", test_person_priority_accounts);
+
return s;
}
More information about the galago-commits
mailing list