Mercurial > pidgin.yaz
changeset 31176:0c090a41522c
Add ref/unref support to MsnUser.
author | masca@cpw.pidgin.im |
---|---|
date | Wed, 26 May 2010 23:25:39 +0000 |
parents | 1ba9f3167de0 |
children | f89094d6f8d5 |
files | libpurple/protocols/msn/user.c libpurple/protocols/msn/user.h |
diffstat | 2 files changed, 46 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/user.c Wed May 26 20:01:05 2010 +0000 +++ b/libpurple/protocols/msn/user.c Wed May 26 23:25:39 2010 +0000 @@ -46,7 +46,7 @@ msn_user_set_passport(user, passport); msn_user_set_friendly_name(user, friendly_name); - return user; + return msn_user_ref(user); } /*destroy a user object*/ @@ -55,6 +55,11 @@ { g_return_if_fail(user != NULL); + if (user->refcount > 1) { + msn_user_unref(user); + return; + } + while (user->endpoints != NULL) { free_user_endpoint(user->endpoints->data); user->endpoints = g_slist_delete_link(user->endpoints, user->endpoints); @@ -94,6 +99,27 @@ g_free(user); } +MsnUser * +msn_user_ref(MsnUser *user) +{ + g_return_val_if_fail(user != NULL, NULL); + + user->refcount++; + + return user; +} + +void +msn_user_unref(MsnUser *user) +{ + g_return_if_fail(user != NULL); + + user->refcount--; + + if(user->refcount == 0) + msn_user_destroy(user); +} + void msn_user_update(MsnUser *user) {
--- a/libpurple/protocols/msn/user.h Wed May 26 20:01:05 2010 +0000 +++ b/libpurple/protocols/msn/user.h Wed May 26 23:25:39 2010 +0000 @@ -79,6 +79,8 @@ { MsnUserList *userlist; + guint8 refcount; /**< The reference count of this object */ + char *passport; /**< The passport account. */ char *friendly_name; /**< The friendly name. */ @@ -154,6 +156,23 @@ */ void msn_user_destroy(MsnUser *user); +/** + * Increment the reference count. + * + * @param user The user. + * + * @return user. + */ +MsnUser * +msn_user_ref(MsnUser *user); + +/** + * Decrement the reference count. + * + * @param user The user + */ +void +msn_user_unref(MsnUser *user); /** * Updates the user.