[Galago-commits] r2569 - in trunk/libgalago: . docs/protocol
libgalago tests
galago-commits at freedesktop.org
galago-commits at freedesktop.org
Wed Feb 8 01:44:01 PST 2006
Author: chipx86
Date: 2006-02-08 01:43:56 -0800 (Wed, 08 Feb 2006)
New Revision: 2569
Modified:
trunk/libgalago/ChangeLog
trunk/libgalago/docs/protocol/protocol.hh
trunk/libgalago/libgalago/galago-account.c
trunk/libgalago/libgalago/galago-account.h
trunk/libgalago/libgalago/galago-core.c
trunk/libgalago/libgalago/galago-person.c
trunk/libgalago/libgalago/galago-presence.c
trunk/libgalago/libgalago/galago-private.h
trunk/libgalago/libgalago/galago-service.c
trunk/libgalago/tests/check-libgalago.c
Log:
Merge back from protocol-cleanup (r2568) to trunk.
Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/ChangeLog 2006-02-08 09:43:56 UTC (rev 2569)
@@ -1,3 +1,86 @@
+Tue Feb 07 10:14:48 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * docs/protocol/protocol.hh:
+ - Update the protocol documentation.
+
+Tue Feb 07 02:02:46 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-account.c:
+ * libgalago/galago-presence.c:
+ * libgalago/galago-private.h:
+ - Fix the pushing of a GalagoAccount's presence. This seems to
+ be the last fix for the re-registration problems.
+
+Tue Feb 07 01:57:41 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-core.c:
+ - Remove some asserts that were preventing re-registration from
+ working. It's still buggy, but works better now.
+
+Tue Feb 07 01:37:12 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-core.c:
+ * libgalago/galago-service.c:
+ - Pass the correct values to galago_get_people() and
+ galago_get_services(). This is another case of passing TRUE/FALSE
+ when an enum value should have been passed.
+
+Tue Feb 07 01:04:02 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * tests/check-libgalago.c:
+ - Beef up the unit tests by registering as a feed and ensuring that
+ objects can be created with valid returned object paths.
+
+Tue Feb 07 00:48:17 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-presence.c:
+ - Retrieve the GalagoStatus's object path from the daemon, rather than
+ setting it in libgalago. This is the last occurrence of libgalago
+ setting object paths.
+
+Mon Feb 06 00:18:31 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-core.c:
+ * libgalago/galago-person.c:
+ - Set the object path on the GalagoPerson based on the result from
+ the daemon when a feed adds an object.
+
+Fri Feb 03 02:25:55 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-account.c:
+ * libgalago/galago-presence.c:
+ - Fix the GalagoAccount and GalagoPresence D-BUS signatures, now
+ that we're passing object paths in. Note that in the future, we're
+ going to want to move the Object Path part of it into the
+ galago_object_* functions, as it will be universal to all objects.
+
+Fri Feb 03 02:13:42 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-account.c:
+ * libgalago/galago-account.h:
+ * libgalago/galago-core.c:
+ * libgalago/galago-presence.c:
+ * libgalago/galago-private.h:
+ - Replace SetPresence/UnsetPresence calls with
+ CreatePresence/RemovePresence. CreatePresence now returns the
+ object path of the presence object, so we no longer compute this
+ ourselves.
+ - Listen for PresenceCreated and PresenceDeleted D-BUS signals instead
+ of PresenceSet and PresenceUnset signals.
+ - Change the GalagoAccount presence signals to be presence_created
+ and presence_deleted.
+ - Remove _galago_account_set_person().
+
+Thu Feb 02 23:57:48 PST 2006 Christian Hammond <chipx86 at chipx86.com>
+
+ * libgalago/galago-account.c:
+ * libgalago/galago-core.c:
+ * libgalago/galago-presence.c:
+ * libgalago/galago-private.h:
+ * libgalago/galago-service.c:
+ - Begin work on having AddPerson and SetPresence return object paths.
+ - Do some little cleanups and API changes. A lot of this is in flux.
+
Wed Feb 01 20:51:34 PST 2006 Christian Hammond <chipx86 at chipx86.com>
* libgalago/galago-account.c:
Modified: trunk/libgalago/docs/protocol/protocol.hh
===================================================================
--- trunk/libgalago/docs/protocol/protocol.hh 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/docs/protocol/protocol.hh 2006-02-08 09:43:56 UTC (rev 2569)
@@ -84,13 +84,25 @@
uint32 GetContactsCount();
/**
- * Sets the account's presence.
+ * Creates an account's presence.
*
+ * An account only has one presence. If this is called multiple times,
+ * the first presence object's path will be returned.
+ *
* @param presence The presence to set.
+ *
+ * @return The object path of the presence.
*/
- void SetPresence(Presence presence);
+ string SetPresence();
/**
+ * Destroys the account's presence.
+ *
+ * This removes the presence from the account.
+ */
+ void DestroyPresence();
+
+ /**
* Returns the account's presence.
*
* @return The presence, or org.freedesktop.Galago.Error.ObjectNotFound
@@ -100,11 +112,6 @@
Presence GetPresence();
/**
- * Unsets the account's presence.
- */
- void UnsetPresence();
-
- /**
* Sets the account's avatar.
*
* @param avatar The avatar to set.
@@ -225,16 +232,13 @@
void RemoveService(Service service);
/**
- * Clears all services from Galago's services cache.
- */
- void ClearServices(); /* DBUS_HANDLER_RESULT_NOT_YET_HANDLED */
-
- /**
* Adds a person to Galago's person cache.
*
* @param person The person to add.
+ *
+ * @return The person's new object path.
*/
- void AddPerson(Person person);
+ string AddPerson(Person person);
/**
* Removes a person from Galago's person cache.
@@ -244,11 +248,6 @@
void RemovePerson(Person person);
/**
- * Clears all people from Galago's person cache.
- */
- void ClearPeople();
-
- /**
* Registers a Galago connection to the daemon.
*
* @param appName The ID name used for this connection. It's often
@@ -516,8 +515,10 @@
* Adds a single status to a presence.
*
* @param status The status.
+ *
+ * @return The status's new object path.
*/
- void AddStatus(Status status);
+ string AddStatus(Status status);
/**
* Removes a single status from a presence.
Modified: trunk/libgalago/libgalago/galago-account.c
===================================================================
--- trunk/libgalago/libgalago/galago-account.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-account.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -57,15 +57,14 @@
{
CONNECTION_STATE_CHANGED,
DISPLAY_NAME_CHANGED,
- PRESENCE_SET,
+ PRESENCE_CREATED,
+ PRESENCE_DELETED,
AVATAR_SET,
CONTACT_ADDED,
CONTACT_REMOVED,
LAST_SIGNAL
};
-static void _galago_dbus_account_set_presence(GalagoAccount *account,
- GalagoPresence *presence);
static void _galago_dbus_account_set_avatar(GalagoAccount *account,
GalagoImage *avatar);
static void _galago_dbus_account_add_contact(GalagoAccount *account,
@@ -130,16 +129,25 @@
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- signals[PRESENCE_SET] =
- g_signal_new("presence_set",
+ signals[PRESENCE_CREATED] =
+ g_signal_new("presence_created",
G_TYPE_FROM_CLASS(klass),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET(GalagoAccountClass, presence_set),
+ G_STRUCT_OFFSET(GalagoAccountClass, presence_created),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
+ signals[PRESENCE_DELETED] =
+ g_signal_new("presence_deleted",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET(GalagoAccountClass, presence_deleted),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
signals[AVATAR_SET] =
g_signal_new("avatar_set",
G_TYPE_FROM_CLASS(klass),
@@ -185,7 +193,7 @@
g_object_class_install_property(gobject_class, PROP_PRESENCE,
g_param_spec_object("presence", "Presence",
"The account's presence",
- GALAGO_TYPE_PRESENCE, G_PARAM_READWRITE));
+ GALAGO_TYPE_PRESENCE, G_PARAM_READABLE));
g_object_class_install_property(gobject_class, PROP_AVATAR,
g_param_spec_object("avatar", "Avatar",
@@ -343,13 +351,16 @@
static void
galago_account_dbus_push_full(GalagoObject *object)
{
- GalagoAccount *account;
+ GalagoAccount *account = GALAGO_ACCOUNT(object);
+ GalagoPresence *presence = galago_account_get_presence(account, FALSE);
GList *l;
- account = (GalagoAccount *)object;
+ if (presence != NULL)
+ {
+ _galago_dbus_account_create_presence(account, presence);
+ galago_dbus_object_push_full(GALAGO_OBJECT(presence));
+ }
- _galago_dbus_account_set_presence(account,
- galago_account_get_presence(account, FALSE));
_galago_dbus_account_set_avatar(account,
galago_account_get_avatar(account, FALSE));
@@ -368,6 +379,7 @@
galago_account_dbus_get_signature(void)
{
return g_strconcat(
+ DBUS_TYPE_STRING_AS_STRING, // object path
galago_object_type_get_dbus_signature(GALAGO_TYPE_SERVICE), // service
galago_object_type_get_dbus_signature(GALAGO_TYPE_PERSON), // person
DBUS_TYPE_STRING_AS_STRING, // username
@@ -393,11 +405,6 @@
account->priv->person = (GalagoPerson *)g_value_get_object(value);
break;
- case PROP_PRESENCE:
- _galago_account_set_presence(account,
- (GalagoPresence *)g_value_get_object(value));
- break;
-
case PROP_AVATAR:
galago_account_set_avatar(account,
(GalagoImage *)g_value_get_object(value));
@@ -479,6 +486,7 @@
g_return_val_if_fail(GALAGO_IS_SERVICE(service), NULL);
g_return_val_if_fail(GALAGO_IS_PERSON(person), NULL);
g_return_val_if_fail(username != NULL && *username != '\0', NULL);
+ g_return_val_if_fail(obj_path == NULL || *obj_path != '\0', NULL);
service_origin = galago_object_get_origin(GALAGO_OBJECT(service));
person_origin = galago_object_get_origin(GALAGO_OBJECT(person));
@@ -498,7 +506,8 @@
NULL);
/* Set the object path, if specified. */
- galago_object_set_dbus_path(GALAGO_OBJECT(account), obj_path);
+ if (service_origin == GALAGO_REMOTE)
+ galago_object_set_dbus_path(GALAGO_OBJECT(account), obj_path);
_galago_person_add_account(person, account);
_galago_service_add_account(service, account);
@@ -815,71 +824,14 @@
return account->priv->contacts;
}
-void
-_galago_account_set_presence(GalagoAccount *account, GalagoPresence *presence)
-{
- g_return_if_fail(account != NULL);
- g_return_if_fail(GALAGO_IS_ACCOUNT(account));
-
- if (account->priv->presence == presence)
- return;
-
- if (account->priv->presence != NULL)
- {
- GalagoPresence *old_presence = account->priv->presence;
-
- account->priv->presence = NULL;
-
- if (!GALAGO_OBJECT_HAS_FLAG(old_presence,
- GALAGO_OBJECT_IN_DESTRUCTION))
- {
- g_object_unref(old_presence);
- }
- }
-
- account->priv->presence = presence;
-
- if (GALAGO_OBJECT_IS_LOCAL(account))
- _galago_dbus_account_set_presence(account, presence);
-
- g_signal_emit(account, signals[PRESENCE_SET], 0, presence);
-}
-
GalagoPresence *
galago_account_create_presence(GalagoAccount *account)
{
- GalagoPresence *presence;
-
g_return_val_if_fail(galago_is_initted(), NULL);
g_return_val_if_fail(account != NULL, NULL);
g_return_val_if_fail(GALAGO_IS_ACCOUNT(account), NULL);
- presence = galago_account_get_presence(account, FALSE);
-
- if (presence == NULL)
- {
- const char *obj_prefix;
-
- galago_context_push(galago_object_get_context(GALAGO_OBJECT(account)));
- presence = g_object_new(GALAGO_TYPE_PRESENCE,
- "origin", galago_object_get_origin(GALAGO_OBJECT(account)),
- "account", account,
- NULL);
- galago_context_pop();
-
- obj_prefix = galago_object_get_dbus_path(GALAGO_OBJECT(account));
-
- if (obj_prefix != NULL)
- {
- char *obj_path = g_strdup_printf("%s/presence", obj_prefix);
- galago_object_set_dbus_path(GALAGO_OBJECT(presence), obj_path);
- g_free(obj_path);
- }
-
- _galago_account_set_presence(account, presence);
- }
-
- return presence;
+ return _galago_presence_new(account, NULL);
}
GalagoPresence *
@@ -949,31 +901,64 @@
return account->priv->avatar;
}
-
-/**************************************************************************
- * D-BUS Functions
- **************************************************************************/
-static void
-_galago_dbus_account_set_presence(GalagoAccount *account,
- GalagoPresence *presence)
+void
+_galago_account_set_presence(GalagoAccount *account, GalagoPresence *presence)
{
- if (!galago_is_connected() || !galago_is_feed())
- return;
+ g_return_if_fail(account != NULL);
+ g_return_if_fail(GALAGO_IS_ACCOUNT(account));
- if (presence == NULL)
+ if (account->priv->presence != NULL)
{
- galago_dbus_send_message(GALAGO_OBJECT(account),
- "UnsetPresence", NULL);
+ GalagoPresence *old_presence = account->priv->presence;
+
+ account->priv->presence = NULL;
+
+ if (!GALAGO_OBJECT_HAS_FLAG(old_presence,
+ GALAGO_OBJECT_IN_DESTRUCTION))
+ {
+ g_object_unref(old_presence);
+ }
+
+ account->priv->presence = NULL;
}
- else
- {
- galago_dbus_send_message(GALAGO_OBJECT(account), "SetPresence",
- galago_value_new_object(GALAGO_TYPE_PRESENCE,
- G_OBJECT(presence)),
- NULL);
- }
+
+ account->priv->presence = presence;
+
+ g_signal_emit(account, signals[PRESENCE_DELETED], 0);
}
+void
+_galago_account_presence_created(GalagoAccount *account,
+ GalagoPresence *presence)
+{
+ g_return_if_fail(account != NULL);
+ g_return_if_fail(GALAGO_IS_ACCOUNT(account));
+ g_return_if_fail(presence != NULL);
+ g_return_if_fail(GALAGO_IS_PRESENCE(presence));
+
+ /*
+ * We should already have account->priv->presence set, since that's
+ * done in the constructor.
+ */
+
+ g_signal_emit(account, signals[PRESENCE_CREATED], 0, presence);
+}
+
+void
+_galago_account_presence_deleted(GalagoAccount *account)
+{
+ g_return_if_fail(account != NULL);
+ g_return_if_fail(GALAGO_IS_ACCOUNT(account));
+
+ _galago_account_set_presence(account, NULL);
+
+ g_signal_emit(account, signals[PRESENCE_DELETED], 0);
+}
+
+
+/**************************************************************************
+ * D-BUS Functions
+ **************************************************************************/
static void
_galago_dbus_account_set_avatar(GalagoAccount *account, GalagoImage *avatar)
{
Modified: trunk/libgalago/libgalago/galago-account.h
===================================================================
--- trunk/libgalago/libgalago/galago-account.h 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-account.h 2006-02-08 09:43:56 UTC (rev 2569)
@@ -2,10 +2,10 @@
* @file libgalago/galago-account.h Galago Account API
* @ingroup Presence
*
+ * @Copyright (C) 2004-2005 Christian Hammond
+ *
* #GalagoAccount models a single account a #GalagoPerson has with a
* provider (a #GalagoService).
- *
- * @Copyright (C) 2004-2005 Christian Hammond
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -62,7 +62,8 @@
/* Signals */
void (*connection_state_changed)(GalagoAccount *account);
void (*display_name_changed)(GalagoAccount *account);
- void (*presence_set)(GalagoAccount *account, GalagoPresence *presence);
+ void (*presence_created)(GalagoAccount *account, GalagoPresence *presence);
+ void (*presence_deleted)(GalagoAccount *account);
void (*avatar_set)(GalagoAccount *account, GalagoImage *image);
void (*contact_added)(GalagoAccount *account, GalagoAccount *contact);
void (*contact_removed)(GalagoAccount *account, GalagoAccount *contact);
Modified: trunk/libgalago/libgalago/galago-core.c
===================================================================
--- trunk/libgalago/libgalago/galago-core.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-core.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -288,17 +288,17 @@
if (!galago_is_feed())
return;
- for (l = galago_get_people(TRUE, FALSE); l != NULL; l = l->next)
+ for (l = galago_get_people(GALAGO_LOCAL, FALSE); l != NULL; l = l->next)
{
- GalagoPerson *person = (GalagoPerson *)l->data;
+ GalagoPerson *person = GALAGO_PERSON(l->data);
_galago_dbus_core_add_person(person);
galago_dbus_object_push_full(GALAGO_OBJECT(person));
}
- for (l = galago_get_services(TRUE, FALSE); l != NULL; l = l->next)
+ for (l = galago_get_services(GALAGO_LOCAL, FALSE); l != NULL; l = l->next)
{
- GalagoService *service = (GalagoService *)l->data;
+ GalagoService *service = GALAGO_SERVICE(l->data);
_galago_dbus_core_add_service(service);
galago_dbus_object_push_full(GALAGO_OBJECT(service));
@@ -536,19 +536,27 @@
* Account
*/
else if (dbus_message_is_signal(message, GALAGO_DBUS_ACCOUNT_INTERFACE,
- "PresenceSet"))
+ "PresenceCreated"))
{
- galago_dbus_message_iter_get_object(&iter, GALAGO_TYPE_PRESENCE);
+ GalagoAccount *account;
+ GalagoPresence *presence;
+
+ account = GALAGO_ACCOUNT(galago_context_get_object(path));
+ presence = galago_dbus_message_iter_get_object(&iter,
+ GALAGO_TYPE_PRESENCE);
+ g_assert(galago_account_get_presence(account, FALSE) == presence);
+
+ _galago_account_presence_created(account, presence);
}
else if (dbus_message_is_signal(message, GALAGO_DBUS_ACCOUNT_INTERFACE,
- "PresenceUnset"))
+ "PresenceDeleted"))
{
GalagoAccount *account;
account = GALAGO_ACCOUNT(galago_context_get_object(path));
if (account != NULL)
- _galago_account_set_presence(account, NULL);
+ _galago_account_presence_deleted(account);
}
else if (dbus_message_is_signal(message, GALAGO_DBUS_ACCOUNT_INTERFACE,
"Connected"))
@@ -1368,8 +1376,10 @@
_galago_dbus_core_add_person(GalagoPerson *person)
{
DBusConnection *dbus_conn;
- DBusMessage *message;
+ DBusMessage *message, *reply;
DBusMessageIter iter;
+ const char *obj_path;
+ DBusError error;
g_signal_emit(_core, signals[PERSON_ADDED], 0, person);
@@ -1388,13 +1398,26 @@
g_return_if_fail(message != NULL);
- dbus_message_set_no_reply(message, TRUE);
-
dbus_message_iter_init_append(message, &iter);
galago_dbus_message_iter_append_object(&iter, GALAGO_OBJECT(person));
- dbus_connection_send(dbus_conn, message, NULL);
+ dbus_error_init(&error);
+ reply = dbus_connection_send_with_reply_and_block(dbus_conn, message, -1,
+ &error);
dbus_message_unref(message);
+
+ if (dbus_error_is_set(&error))
+ {
+ g_warning("Error sending AddPerson: %s", error.message);
+ return;
+ }
+
+ g_assert(reply != NULL);
+
+ dbus_message_iter_init(reply, &iter);
+ dbus_message_iter_get_basic(&iter, &obj_path);
+
+ galago_object_set_dbus_path(GALAGO_OBJECT(person), obj_path);
}
static void
Modified: trunk/libgalago/libgalago/galago-person.c
===================================================================
--- trunk/libgalago/libgalago/galago-person.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-person.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -61,9 +61,8 @@
/* 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);
+static GalagoPerson *_galago_person_new(const char *id, GalagoOrigin origin,
+ const char *obj_path);
static void _galago_dbus_person_set_photo(GalagoPerson *person,
GalagoImage *photo);
@@ -233,7 +232,7 @@
id = galago_person_get_id(person);
is_me = galago_person_is_me(person);
- dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &obj_path);
+ galago_dbus_message_iter_append_string_or_nil(iter, obj_path);
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &id);
dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &is_me);
}
@@ -245,7 +244,7 @@
const char *obj_path, *uid;
gboolean me;
- dbus_message_iter_get_basic(iter, &obj_path);
+ obj_path = galago_dbus_message_iter_get_string_or_nil(iter);
dbus_message_iter_next(iter);
dbus_message_iter_get_basic(iter, &uid);
@@ -256,7 +255,7 @@
if (me)
uid = GALAGO_ME_ID;
- person = _galago_create_person_common(uid, GALAGO_REMOTE, obj_path);
+ person = _galago_person_new(uid, GALAGO_REMOTE, obj_path);
return person;
}
@@ -331,8 +330,7 @@
* GalagoPerson API
**************************************************************************/
static GalagoPerson *
-_galago_create_person_common(const char *uid, GalagoOrigin origin,
- const char *obj_path)
+_galago_person_new(const char *uid, GalagoOrigin origin, const char *obj_path)
{
GalagoPerson *person;
@@ -343,35 +341,15 @@
if (person == NULL)
{
- const char *obj_prefix;
-
person = g_object_new(GALAGO_TYPE_PERSON,
"id", uid,
"origin", origin,
NULL);
- if (obj_path != NULL)
- {
+ /* Set the object path, if specified. */
+ if (origin == GALAGO_REMOTE)
galago_object_set_dbus_path(GALAGO_OBJECT(person), obj_path);
- }
- else if ((obj_prefix = galago_context_get_obj_path_prefix()) != NULL)
- {
- char *new_obj_path;
- const char *escaped_id;
- if (!strcmp(uid, GALAGO_ME_ID))
- escaped_id = GALAGO_ME_ID;
- else
- escaped_id = galago_dbus_normalize_name(uid);
-
- new_obj_path = g_strdup_printf("%s/people/%s",
- obj_prefix, escaped_id);
-
- galago_object_set_dbus_path(GALAGO_OBJECT(person), new_obj_path);
-
- g_free(new_obj_path);
- }
-
galago_context_add_person(person);
}
@@ -384,7 +362,7 @@
g_return_val_if_fail(galago_is_initted(), NULL);
g_return_val_if_fail(uid != NULL && *uid != '\0', NULL);
- return _galago_create_person_common(uid, GALAGO_LOCAL, NULL);
+ return _galago_person_new(uid, GALAGO_LOCAL, NULL);
}
void
Modified: trunk/libgalago/libgalago/galago-presence.c
===================================================================
--- trunk/libgalago/libgalago/galago-presence.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-presence.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -54,6 +54,8 @@
LAST_SIGNAL
};
+static void _galago_dbus_account_destroy_presence(GalagoAccount *account,
+ GalagoPresence *presence);
static void _galago_presence_remove_status(GalagoPresence *presence,
GalagoStatus *status);
@@ -176,10 +178,11 @@
account = galago_presence_get_account(presence);
- if (account != NULL &&
+ if (account != NULL && GALAGO_OBJECT_IS_LOCAL(presence) &&
galago_account_get_presence(account, FALSE) == presence)
{
_galago_account_set_presence(account, NULL);
+ _galago_dbus_account_destroy_presence(account, presence);
}
if (presence->priv != NULL)
@@ -207,6 +210,9 @@
gboolean is_idle;
dbus_uint32_t idle_time;
+ galago_dbus_message_iter_append_string_or_nil(iter,
+ galago_object_get_dbus_path(object));
+
galago_dbus_message_iter_append_object(iter,
GALAGO_OBJECT(galago_presence_get_account(presence)));
@@ -226,9 +232,13 @@
GalagoPresence *presence;
GalagoAccount *account;
GList *l, *statuses;
+ const char *obj_path;
gboolean idle;
time_t idle_start_time = 0;
+ obj_path = galago_dbus_message_iter_get_string_or_nil(iter);
+ dbus_message_iter_next(iter);
+
account = galago_dbus_message_iter_get_object(iter, GALAGO_TYPE_ACCOUNT);
dbus_message_iter_next(iter);
@@ -238,7 +248,7 @@
dbus_message_iter_get_basic(iter, &idle_start_time);
dbus_message_iter_next(iter);
- presence = galago_account_create_presence(account);
+ presence = _galago_presence_new(account, obj_path);
galago_presence_set_idle(presence, idle, idle_start_time);
statuses = galago_dbus_message_iter_get_object_list(iter,
@@ -254,6 +264,7 @@
galago_presence_dbus_get_signature(void)
{
return g_strconcat(
+ DBUS_TYPE_STRING_AS_STRING, // object path
galago_object_type_get_dbus_signature(GALAGO_TYPE_ACCOUNT), // account
DBUS_TYPE_BOOLEAN_AS_STRING, // idle flag
DBUS_TYPE_UINT32_AS_STRING, // idle time
@@ -283,7 +294,7 @@
static void
galago_presence_get_property(GObject *object, guint prop_id,
- GValue *value, GParamSpec *pspec)
+ GValue *value, GParamSpec *pspec)
{
GalagoPresence *presence = GALAGO_PRESENCE(object);
@@ -299,7 +310,39 @@
}
}
+GalagoPresence *
+_galago_presence_new(GalagoAccount *account, const char *obj_path)
+{
+ GalagoPresence *presence;
+ g_return_val_if_fail(galago_is_initted(), NULL);
+ g_return_val_if_fail(account != NULL, NULL);
+ g_return_val_if_fail(GALAGO_IS_ACCOUNT(account), NULL);
+ g_return_val_if_fail(obj_path == NULL || *obj_path != '\0', NULL);
+
+ presence = galago_account_get_presence(account, FALSE);
+
+ if (presence == NULL)
+ {
+ galago_context_push(galago_object_get_context(GALAGO_OBJECT(account)));
+ presence = g_object_new(GALAGO_TYPE_PRESENCE,
+ "origin", galago_object_get_origin(GALAGO_OBJECT(account)),
+ "account", account,
+ NULL);
+ galago_context_pop();
+
+ if (obj_path == NULL)
+ _galago_dbus_account_create_presence(account, presence);
+ else
+ galago_object_set_dbus_path(GALAGO_OBJECT(presence), obj_path);
+
+ _galago_account_set_presence(account, presence);
+ }
+
+ return presence;
+}
+
+
/**************************************************************************
* GalagoPresence API
**************************************************************************/
@@ -417,10 +460,17 @@
return;
}
- if (GALAGO_OBJECT_IS_LOCAL(person) && galago_is_connected())
+ if (GALAGO_OBJECT_IS_LOCAL(person) && galago_is_connected() &&
+ galago_is_feed())
{
- char *obj_path = g_strdup_printf("%s/%s",
- galago_object_get_dbus_path(GALAGO_OBJECT(presence)), status_id);
+ char *obj_path = galago_dbus_send_message_with_reply(
+ GALAGO_OBJECT(presence), "AddStatus",
+ galago_value_new(GALAGO_VALUE_TYPE_STRING, NULL, NULL),
+ galago_value_new_object(GALAGO_TYPE_STATUS, G_OBJECT(status)),
+ NULL);
+
+ g_assert(obj_path != NULL);
+
galago_object_set_dbus_path(GALAGO_OBJECT(status), obj_path);
g_free(obj_path);
}
@@ -441,14 +491,6 @@
galago_status_set_presence(status, presence);
- if (GALAGO_OBJECT_IS_LOCAL(person) && galago_is_connected() &&
- galago_is_feed())
- {
- galago_dbus_send_message(GALAGO_OBJECT(presence), "AddStatus",
- galago_value_new_object(GALAGO_TYPE_STATUS, G_OBJECT(status)),
- NULL);
- }
-
g_signal_emit(presence, signals[STATUS_ADDED], 0, status);
g_signal_emit(presence, signals[CHANGED], 0);
}
@@ -737,3 +779,33 @@
}
}
}
+
+void
+_galago_dbus_account_create_presence(GalagoAccount *account,
+ GalagoPresence *presence)
+{
+ char *obj_path;
+
+ if (!galago_is_connected() || !galago_is_feed())
+ return;
+
+ obj_path = galago_dbus_send_message_with_reply(
+ GALAGO_OBJECT(account), "CreatePresence",
+ galago_value_new(GALAGO_VALUE_TYPE_STRING, NULL, NULL),
+ NULL);
+
+ g_assert(obj_path != NULL);
+
+ galago_object_set_dbus_path(GALAGO_OBJECT(presence), obj_path);
+ g_free(obj_path);
+}
+
+static void
+_galago_dbus_account_destroy_presence(GalagoAccount *account,
+ GalagoPresence *presence)
+{
+ if (!galago_is_connected() || !galago_is_feed())
+ return;
+
+ galago_dbus_send_message(GALAGO_OBJECT(account), "DestroyPresence", NULL);
+}
Modified: trunk/libgalago/libgalago/galago-private.h
===================================================================
--- trunk/libgalago/libgalago/galago-private.h 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-private.h 2006-02-08 09:43:56 UTC (rev 2569)
@@ -55,6 +55,13 @@
GalagoPerson *person,
const char *username,
const char *obj_path);
+
+void _galago_account_presence_created(GalagoAccount *account,
+ GalagoPresence *presence);
+void _galago_account_presence_deleted(GalagoAccount *account);
+void _galago_dbus_account_create_presence(GalagoAccount *account,
+ GalagoPresence *presence);
+
/**
* Sets the account's presence.
*
@@ -109,4 +116,7 @@
void _galago_person_remove_account(GalagoPerson *person,
GalagoAccount *account);
+GalagoPresence *_galago_presence_new(GalagoAccount *account,
+ const char *obj_path);
+
#endif /* _GALAGO_PRIVATE_H_ */
Modified: trunk/libgalago/libgalago/galago-service.c
===================================================================
--- trunk/libgalago/libgalago/galago-service.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/libgalago/galago-service.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -230,7 +230,7 @@
static void
galago_service_dbus_push_full(GalagoObject *object)
{
- GalagoService *service = (GalagoService *)object;
+ GalagoService *service = GALAGO_SERVICE(object);
GalagoAccount *account;
GList *l;
@@ -248,7 +248,7 @@
{
account = (GalagoAccount *)l->data;
- galago_dbus_object_push_full(GALAGO_OBJECT(account));
+ galago_dbus_object_push_full(GALAGO_OBJECT(l->data));
}
}
@@ -422,7 +422,8 @@
NULL);
/* Set the object path, if specified. */
- galago_object_set_dbus_path(GALAGO_OBJECT(service), obj_path);
+ if (origin == GALAGO_REMOTE)
+ galago_object_set_dbus_path(GALAGO_OBJECT(service), obj_path);
galago_context_add_service(service);
}
@@ -651,6 +652,9 @@
{
char *obj_path;
+ g_assert(service != NULL);
+ g_assert(account != NULL);
+
if (!galago_is_connected() || !galago_is_feed())
return;
Modified: trunk/libgalago/tests/check-libgalago.c
===================================================================
--- trunk/libgalago/tests/check-libgalago.c 2006-02-07 18:15:07 UTC (rev 2568)
+++ trunk/libgalago/tests/check-libgalago.c 2006-02-08 09:43:56 UTC (rev 2569)
@@ -84,26 +84,57 @@
**************************************************************************/
START_TEST(test_create_person)
{
- galago_init("check-libgalago", FALSE);
- fail_unless(make_dummy_person() != NULL, "Unable to create person");
+ GalagoPerson *person;
+
+ galago_init("check-libgalago", TRUE);
+
+ person = make_dummy_person();
+ fail_unless(person != NULL, "Unable to create person");
+ fail_unless(galago_object_get_dbus_path(GALAGO_OBJECT(person)) != NULL,
+ "Object path not set on the new person");
}
END_TEST
START_TEST(test_create_service)
{
- galago_init("check-libgalago", FALSE);
- fail_unless(make_dummy_service() != NULL, "Unable to create service");
+ GalagoService *service;
+
+ galago_init("check-libgalago", TRUE);
+
+ service = make_dummy_service();
+ fail_unless(service != NULL, "Unable to create service");
+ fail_unless(galago_object_get_dbus_path(GALAGO_OBJECT(service)) != NULL,
+ "Object path not set on the new service");
}
END_TEST
START_TEST(test_create_account)
{
- galago_init("check-libgalago", FALSE);
- fail_unless(make_dummy_account() != NULL, "Unable to create account");
+ GalagoAccount *account;
+
+ galago_init("check-libgalago", TRUE);
+
+ account = make_dummy_account();
+ fail_unless(account != NULL, "Unable to create account");
+ fail_unless(galago_object_get_dbus_path(GALAGO_OBJECT(account)) != NULL,
+ "Object path not set on the new account");
}
END_TEST
+START_TEST(test_create_presence)
+{
+ GalagoPresence *presence;
+ galago_init("check-libgalago", TRUE);
+
+ presence = make_dummy_presence();
+ fail_unless(presence != NULL, "Unable to create presence");
+ fail_unless(galago_object_get_dbus_path(GALAGO_OBJECT(presence)) != NULL,
+ "Object path not set on the new presence");
+}
+END_TEST
+
+
/**************************************************************************
* Test D-BUS object signature support
**************************************************************************/
@@ -286,6 +317,7 @@
ADD_TCASE("create_person", test_create_person);
ADD_TCASE("create_service", test_create_service);
ADD_TCASE("create_account", test_create_account);
+ ADD_TCASE("create_presence", test_create_presence);
/* Test D-BUS object signature support */
ADD_TCASE("dbus_signature_account", test_dbus_signature_account);
More information about the galago-commits
mailing list