soc.2010.msn-tlc: 71d3514f: Add ref/unref support to MsnUser.

masca at cpw.pidgin.im masca at cpw.pidgin.im
Thu May 27 16:31:10 EDT 2010


-----------------------------------------------------------------
Revision: 71d3514f80b4158dab2aad099e7cb9919dfb8417
Ancestor: 5eb9520d23ca46522f0a2dd19fc6e3a10b31cd39
Author: masca at cpw.pidgin.im
Date: 2010-05-26T23:25:39
Branch: im.pidgin.soc.2010.msn-tlc
URL: http://d.pidgin.im/viewmtn/revision/info/71d3514f80b4158dab2aad099e7cb9919dfb8417

Modified files:
        libpurple/protocols/msn/user.c
        libpurple/protocols/msn/user.h

ChangeLog: 

Add ref/unref support to MsnUser.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/user.c	0d4395b0e92ca16fa015b55d2f758ed63b2bb658
+++ libpurple/protocols/msn/user.c	89335876fdb66a391f6020805857c53d2b89ed8b
@@ -46,7 +46,7 @@ msn_user_new(MsnUserList *userlist, cons
 	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 @@ msn_user_destroy(MsnUser *user)
 {
 	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,7 +99,28 @@ msn_user_destroy(MsnUser *user)
 	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)
 {
 	PurpleAccount *account;
============================================================
--- libpurple/protocols/msn/user.h	4721cde95d26a9b19930d675f2930fdda31a222e
+++ libpurple/protocols/msn/user.h	ffddb45ccea21b33c929341dd1c64fa53291bacb
@@ -79,6 +79,8 @@ struct _MsnUser
 {
 	MsnUserList *userlist;
 
+	guint8 refcount;        /**< The reference count of this object */
+
 	char *passport;         /**< The passport account.          */
 	char *friendly_name;    /**< The friendly name.             */
 
@@ -154,8 +156,25 @@ void msn_user_destroy(MsnUser *user);
  */
 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.
  *
  * Communicates with the core to update the ui, etc.


More information about the Commits mailing list