gobjectification: 87960678: Use g_type_class_add_private for connect...

sadrul at pidgin.im sadrul at pidgin.im
Wed Jul 14 03:14:16 EDT 2010


----------------------------------------------------------------------
Revision: 879606785a2c9c7eb4de2a04bd4070c2f0cf55ec
Parent:   2ee71de4584d2360e9372660b697dca9957478ca
Author:   sadrul at pidgin.im
Date:     07/14/10 02:20:51
Branch:   im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/879606785a2c9c7eb4de2a04bd4070c2f0cf55ec

Changelog: 

Use g_type_class_add_private for connections.

Changes against parent 2ee71de4584d2360e9372660b697dca9957478ca

  patched  libpurple/account.h
  patched  libpurple/connection.c
  patched  libpurple/connection.h
  patched  libpurple/plugins/perl/common/Connection.xs

-------------- next part --------------
============================================================
--- libpurple/account.h	3a6f6f968ef9cd254a205d5f203a4bf7d9193650
+++ libpurple/account.h	49d9e29cc3e74c8b28ac17d965575a73fd99f9ab
@@ -176,13 +176,6 @@ PurpleAccount *purple_account_new(const 
 PurpleAccount *purple_account_new(const char *username, const char *protocol_id);
 
 /**
- * Destroys an account.
- *
- * @param account The account to destroy.
- */
-void purple_account_destroy(PurpleAccount *account);
-
-/**
  * Connects to an account.
  *
  * @param account The account to connect to.
============================================================
--- libpurple/connection.c	f4090bad89d7ef32cdc871dfcfbe1926290534f2
+++ libpurple/connection.c	1cb6159a7448e5ca479c6bd0192eab6ce87f1e1c
@@ -43,6 +43,10 @@
 /******************************************************************************
  * Structs
  *****************************************************************************/
+#define PURPLE_CONNECTION_GET_PRIVATE(gc) \
+	(G_TYPE_INSTANCE_GET_PRIVATE((gc), PURPLE_TYPE_CONNECTION, PurpleConnectionPrivate))
+typedef struct _PurpleConnectionPrivate		PurpleConnectionPrivate;
+
 struct _PurpleConnectionPrivate
 {
 	PurpleConnectionFlags flags;
@@ -118,14 +122,17 @@ send_keepalive(gpointer data)
 {
 	PurpleConnection *gc = data;
 	PurplePluginProtocolInfo *prpl_info;
+	PurpleConnectionPrivate *priv;
 
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
 	/* Only send keep-alives if we haven't heard from the
 	 * server in a while.
 	 */
-	if ((time(NULL) - gc->priv->last_received) < KEEPALIVE_INTERVAL)
+	if ((time(NULL) - priv->last_received) < KEEPALIVE_INTERVAL)
 		return TRUE;
 
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->priv->prpl);
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(priv->prpl);
 	if (prpl_info->keepalive)
 		prpl_info->keepalive(gc);
 
@@ -136,23 +143,26 @@ update_keepalive(PurpleConnection *gc, g
 update_keepalive(PurpleConnection *gc, gboolean on)
 {
 	PurplePluginProtocolInfo *prpl_info = NULL;
+	PurpleConnectionPrivate *priv;
 
-	if (gc != NULL && gc->priv->prpl != NULL)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->priv->prpl);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
+	if (gc != NULL && priv->prpl != NULL)
+		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(priv->prpl);
+
 	if (!prpl_info || !prpl_info->keepalive)
 		return;
 
-	if (on && !gc->priv->keepalive)
+	if (on && !priv->keepalive)
 	{
 		purple_debug_info("connection", "Activating keepalive.\n");
-		gc->priv->keepalive = purple_timeout_add_seconds(KEEPALIVE_INTERVAL, send_keepalive, gc);
+		priv->keepalive = purple_timeout_add_seconds(KEEPALIVE_INTERVAL, send_keepalive, gc);
 	}
-	else if (!on && gc->priv->keepalive > 0)
+	else if (!on && priv->keepalive > 0)
 	{
 		purple_debug_info("connection", "Deactivating keepalive.\n");
-		purple_timeout_remove(gc->priv->keepalive);
-		gc->priv->keepalive = 0;
+		purple_timeout_remove(priv->keepalive);
+		priv->keepalive = 0;
 	}
 }
 
@@ -168,6 +178,7 @@ _purple_connection_new(PurpleAccount *ac
 	PurpleConnection *gc;
 	PurplePlugin *prpl;
 	PurplePluginProtocolInfo *prpl_info;
+	PurpleConnectionPrivate *priv;
 
 	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
 
@@ -209,8 +220,10 @@ _purple_connection_new(PurpleAccount *ac
 	gc = g_object_new(PURPLE_TYPE_CONNECTION, "account", account, NULL);
 	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
 
-	gc->priv->password = g_strdup(password);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
+	priv->password = g_strdup(password);
+
 	g_signal_emit(G_OBJECT(gc), signals[SIG_SIGNING_ON], 0);
 
 	if (regist)
@@ -218,16 +231,14 @@ _purple_connection_new(PurpleAccount *ac
 		purple_debug_info("connection", "Registering.  gc = %p\n", gc);
 
 		/* set this so we don't auto-reconnect after registering */
-		gc->priv->wants_to_die = TRUE;
+		priv->wants_to_die = TRUE;
 
 		prpl_info->register_user(account);
 	}
 	else
 	{
 		purple_debug_info("connection", "Connecting. gc = %p\n", gc);
-
-#warning Replace with g_signal_emit when account is gobjectified
-		purple_signal_emit(purple_accounts_get_handle(), "account-connecting", account);
+		g_signal_emit_by_name(G_OBJECT(account), "connecting", gc);
 		prpl_info->login(account);
 	}
 }
@@ -244,6 +255,7 @@ _purple_connection_new_unregister(Purple
 	PurpleConnection *gc;
 	PurplePlugin *prpl;
 	PurplePluginProtocolInfo *prpl_info;
+	PurpleConnectionPrivate *priv;
 
 	g_return_if_fail(account != NULL);
 
@@ -275,12 +287,13 @@ _purple_connection_new_unregister(Purple
 		return;
 	}
 
-	gc = g_new0(PurpleConnection, 1);
+	gc = g_object_new(PURPLE_TYPE_CONNECTION, "account", account, NULL);
 	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
 
-	gc->priv->prpl = prpl;
-	gc->priv->password = g_strdup(password);
-	purple_connection_set_account(gc, account);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
+	priv->prpl = prpl;
+	priv->password = g_strdup(password);
 	purple_connection_set_state(gc, PURPLE_CONNECTION_STATE_CONNECTING);
 	connections = g_list_append(connections, gc);
 	purple_account_set_connection(account, gc);
@@ -301,8 +314,12 @@ _purple_connection_destroy(PurpleConnect
 void
 _purple_connection_destroy(PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
-	purple_account_set_connection(gc->priv->account, NULL);
+
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+	purple_account_set_connection(priv->account, NULL);
 }
 
 /*
@@ -322,12 +339,15 @@ purple_connection_set_state(PurpleConnec
 	PurpleConnectionUiOps *ops;
 #endif
 
+	PurpleConnectionPrivate *priv;
+
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	if (gc->priv->state == state)
+	if (priv->state == state)
 		return;
 
-	gc->priv->state = state;
+	priv->state = state;
 
 #if 0
 	ops = purple_connections_get_ui_ops();
@@ -340,7 +360,7 @@ purple_connection_set_state(PurpleConnec
 	}
 #endif
 
-	if (gc->priv->state == PURPLE_CONNECTION_STATE_CONNECTED) {
+	if (priv->state == PURPLE_CONNECTION_STATE_CONNECTED) {
 		PurpleAccount *account;
 		PurplePresence *presence;
 
@@ -381,7 +401,7 @@ purple_connection_set_state(PurpleConnec
 
 		update_keepalive(gc, TRUE);
 	}
-	else if (gc->priv->state == PURPLE_CONNECTION_STATE_DISCONNECTED) {
+	else if (priv->state == PURPLE_CONNECTION_STATE_DISCONNECTED) {
 		PurpleAccount *account = purple_connection_get_account(gc);
 
 		if (purple_prefs_get_bool("/purple/logging/log_system"))
@@ -410,22 +430,26 @@ void purple_connection_set_flags(PurpleC
 
 void purple_connection_set_flags(PurpleConnection *gc, PurpleConnectionFlags flags)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
-	gc->priv->flags = flags;
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+	priv->flags = flags;
 }
 
-void
+static void
 purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account)
 {
-	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
+	PurpleConnectionPrivate *priv;
 	g_return_if_fail(account != NULL);
-	g_return_if_fail(gc->priv->account == NULL); /* We set the account for a connection exactly once */
 
-	if (gc->priv->account == account)
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
+	if (priv->account == account)
 		return;
 
-	gc->priv->account = account;
-	gc->priv->prpl = account ? purple_find_prpl(purple_account_get_protocol_id(account)) : NULL;
+	priv->account = account;
+	priv->prpl = account ? purple_find_prpl(purple_account_get_protocol_id(account)) : NULL;
 
 	purple_account_set_connection(account, gc);
 }
@@ -433,58 +457,79 @@ purple_connection_set_display_name(Purpl
 void
 purple_connection_set_display_name(PurpleConnection *gc, const char *name)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	g_free(gc->priv->display_name);
-	gc->priv->display_name = g_strdup(name);
+	g_free(priv->display_name);
+	priv->display_name = g_strdup(name);
 }
 
 PurpleConnectionState
 purple_connection_get_state(const PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, PURPLE_CONNECTION_STATE_DISCONNECTED);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->state;
+	return priv->state;
 }
 
 PurpleConnectionFlags
 purple_connection_get_flags(PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, 0);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->flags;
+	return priv->flags;
 }
 
 PurpleAccount *
 purple_connection_get_account(const PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, NULL);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->account;
+	return priv->account;
 }
 
 PurplePlugin *
 purple_connection_get_prpl(const PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, NULL);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->prpl;
+	return priv->prpl;
 }
 
 const char *
 purple_connection_get_password(const PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, NULL);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->password ? gc->priv->password : purple_account_get_password(gc->priv->account);
+	return priv->password ? priv->password : purple_account_get_password(priv->account);
 }
 
 const char *
 purple_connection_get_display_name(const PurpleConnection *gc)
 {
+	PurpleConnectionPrivate *priv;
+
 	g_return_val_if_fail(gc != NULL, NULL);
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
-	return gc->priv->display_name;
+	return priv->display_name;
 }
 
 void
@@ -511,7 +556,10 @@ purple_connection_received_now(PurpleCon
 void
 purple_connection_received_now(PurpleConnection *conn)
 {
-    conn->priv->last_received = time(NULL);
+	PurpleConnectionPrivate *priv;
+
+	priv = PURPLE_CONNECTION_GET_PRIVATE(conn);
+    priv->last_received = time(NULL);
 }
 
 void
@@ -535,6 +583,8 @@ purple_connection_disconnect_cb(gpointer
 static gboolean
 purple_connection_disconnect_cb(gpointer data)
 {
+	PurpleConnectionPrivate *priv;
+
 	PurpleAccount *account;
 	PurpleConnection *gc;
 	char *password;
@@ -542,8 +592,10 @@ purple_connection_disconnect_cb(gpointer
 	account = data;
 	gc = purple_account_get_connection(account);
 
-	if (gc != NULL)
-		gc->priv->disconnect_timeout = 0;
+	if (gc != NULL) {
+		priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+		priv->disconnect_timeout = 0;
+	}
 
 	password = g_strdup(purple_account_get_password(account));
 	purple_account_disconnect(account);
@@ -556,13 +608,15 @@ purple_connection_error(PurpleConnection
 void
 purple_connection_error(PurpleConnection *gc, const char *text)
 {
+	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
 	/* prpls that have not been updated to use disconnection reasons will
 	 * be setting wants_to_die before calling this function, so choose
 	 * PURPLE_CONNECTION_ERROR_OTHER_ERROR (which is fatal) if it's true,
 	 * and PURPLE_CONNECTION_ERROR_NETWORK_ERROR (which isn't) if not.  See
 	 * the documentation in connection.h.
 	 */
-	PurpleConnectionError reason = gc->priv->wants_to_die
+	PurpleConnectionError reason = priv->wants_to_die
 	                             ? PURPLE_CONNECTION_ERROR_OTHER_ERROR
 	                             : PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
 	purple_connection_error_reason (gc, reason, text);
@@ -576,8 +630,11 @@ purple_connection_error_reason (PurpleCo
 #if 0
 	PurpleConnectionUiOps *ops;
 #endif
+	PurpleConnectionPrivate *priv;
 
 	g_return_if_fail(PURPLE_IS_CONNECTION(gc));
+	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
 	/* This sanity check relies on PURPLE_CONNECTION_ERROR_OTHER_ERROR
 	 * being the last member of the PurpleConnectionError enum in
 	 * connection.h; if other reasons are added after it, this check should
@@ -596,10 +653,10 @@ purple_connection_error_reason (PurpleCo
 	}
 
 	/* If we've already got one error, we don't need any more */
-	if (gc->priv->disconnect_timeout > 0)
+	if (priv->disconnect_timeout > 0)
 		return;
 
-	gc->priv->wants_to_die = purple_connection_error_is_fatal (reason);
+	priv->wants_to_die = purple_connection_error_is_fatal (reason);
 
 	purple_debug_info("connection", "Connection error on %p (reason: %u description: %s)\n",
 	                  gc, reason, description);
@@ -618,7 +675,7 @@ purple_connection_error_reason (PurpleCo
 #endif
 	g_signal_emit(G_OBJECT(gc), signals[SIG_ERROR], 0, reason, description);
 
-	gc->priv->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb,
+	priv->disconnect_timeout = purple_timeout_add(0, purple_connection_disconnect_cb,
 			purple_connection_get_account(gc));
 }
 
@@ -685,10 +742,13 @@ purple_connection_get_property(GObject *
 							   GParamSpec *pspec)
 {
 	PurpleConnection *pc = PURPLE_CONNECTION(obj);
+	PurpleConnectionPrivate *priv;
 
+	priv = PURPLE_CONNECTION_GET_PRIVATE(pc);
+
 	switch(param_id) {
 		case PROP_FLAGS:
-			g_value_set_flags(value, pc->priv->flags);
+			g_value_set_flags(value, priv->flags);
 			break;
 		case PROP_STATE:
 			g_value_set_enum(value, purple_connection_get_state(pc));
@@ -697,7 +757,7 @@ purple_connection_get_property(GObject *
 			g_value_set_object(value, purple_connection_get_account(pc));
 			break;
 		case PROP_INPUT_WATCHER:
-			g_value_set_int(value, pc->priv->inpa);
+			g_value_set_int(value, priv->inpa);
 			break;
 #if 0
 		case PROP_BUDDY_CHATS:
@@ -725,10 +785,13 @@ purple_connection_set_property(GObject *
 							   const GValue *value, GParamSpec *pspec)
 {
 	PurpleConnection *pc = PURPLE_CONNECTION(obj);
+	PurpleConnectionPrivate *priv;
 
+	priv = PURPLE_CONNECTION_GET_PRIVATE(pc);
+
 	switch(param_id) {
 		case PROP_FLAGS:
-			pc->priv->flags = g_value_get_flags(value);
+			priv->flags = g_value_get_flags(value);
 			break;
 		case PROP_STATE:
 			purple_connection_set_state(pc, g_value_get_enum(value));
@@ -737,7 +800,7 @@ purple_connection_set_property(GObject *
 			purple_connection_set_account(pc, g_value_get_object(value));
 			break;
 		case PROP_INPUT_WATCHER:
-			pc->priv->inpa = g_value_get_int(value);
+			priv->inpa = g_value_get_int(value);
 			break;
 #if 0
 		case PROP_BUDDY_CHATS:
@@ -767,20 +830,23 @@ purple_connection_dispose(GObject *obj)
 	PurpleAccount *account;
 	GSList *buddies;
 	PurplePluginProtocolInfo *prpl_info = NULL;
+	PurpleConnectionPrivate *priv;
 
 	g_return_if_fail(PURPLE_IS_CONNECTION(pc));
 
+	priv = PURPLE_CONNECTION_GET_PRIVATE(pc);
+
 	account = purple_connection_get_account(pc);
 
 	purple_debug_info("connection", "Disconnecting connection %p\n", pc);
 
 	g_signal_emit(G_OBJECT(pc), signals[SIG_SIGNING_OFF], 0);
 
-	while (pc->priv->buddy_chats)
+	while (priv->buddy_chats)
 	{
-		PurpleConversation *b = pc->priv->buddy_chats->data;
+		PurpleConversation *b = priv->buddy_chats->data;
 
-		pc->priv->buddy_chats = g_slist_remove(pc->priv->buddy_chats, b);
+		priv->buddy_chats = g_slist_remove(priv->buddy_chats, b);
 		purple_conv_chat_left(PURPLE_CONV_CHAT(b));
 	}
 
@@ -788,7 +854,7 @@ purple_connection_dispose(GObject *obj)
 
 	purple_proxy_connect_cancel_with_handle(pc);
 
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(pc->priv->prpl);
+	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(priv->prpl);
 	if (prpl_info->close)
 		(prpl_info->close)(pc);
 
@@ -810,7 +876,8 @@ purple_connection_finalize(GObject *obj)
 purple_connection_finalize(GObject *obj)
 {
 	PurpleConnection *pc = PURPLE_CONNECTION(obj);
-	PurpleAccount *account = pc->priv->account;
+	PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(pc);
+	PurpleAccount *account = priv->account;
 	gboolean remove = FALSE;
 
 	connections = g_list_remove(connections, pc);
@@ -831,14 +898,14 @@ purple_connection_finalize(GObject *obj)
 
 	purple_account_set_connection(account, NULL);
 
-	g_free(pc->priv->password);
-	g_free(pc->priv->display_name);
+	g_free(priv->password);
+	g_free(priv->display_name);
 
-	if (pc->priv->disconnect_timeout)
-		purple_timeout_remove(pc->priv->disconnect_timeout);
+	if (priv->disconnect_timeout)
+		purple_timeout_remove(priv->disconnect_timeout);
 
 	PURPLE_DBUS_UNREGISTER_POINTER(pc);
-	g_free(pc->priv);
+	g_free(priv);
 
 	G_OBJECT_CLASS(parent_class)->finalize(obj);
 }
@@ -848,7 +915,7 @@ purple_connection_init(GTypeInstance *in
 {
 	PurpleConnection *pc = PURPLE_CONNECTION(instance);
 
-	pc->priv = g_new0(PurpleConnectionPrivate, 1);
+	g_type_class_add_private(klass, sizeof(PurpleConnectionPrivate));
 	purple_connection_set_state(pc, PURPLE_CONNECTION_STATE_CONNECTING);
 }
 
============================================================
--- libpurple/connection.h	f6ae2e66994a825846b3044ab5d13320302eda2e
+++ libpurple/connection.h	525e25e5c9926e93c5d64d27411fecfe6cb30c3a
@@ -37,7 +37,6 @@ typedef struct _PurpleConnection			Purpl
 #define PURPLE_CONNECTION_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_CONNECTION, PurpleConnectionClass))
 
 typedef struct _PurpleConnection			PurpleConnection;
-typedef struct _PurpleConnectionPrivate		PurpleConnectionPrivate;
 typedef struct _PurpleConnectionClass		PurpleConnectionClass;
 
 #define PURPLE_TYPE_CONNECTION_FLAGS		(purple_connection_flags_get_gtype())
@@ -261,8 +260,6 @@ struct _PurpleConnection
 {
 	PurpleObject gparent;
 
-	PurpleConnectionPrivate *priv;
-
 	void (*_purple_reserved1)(void);
 	void (*_purple_reserved2)(void);
 	void (*_purple_reserved3)(void);
@@ -370,14 +367,6 @@ void purple_connection_set_flags(PurpleC
 void purple_connection_set_flags(PurpleConnection *gc, PurpleConnectionFlags flags);
 
 /**
- * Sets the connection's account.
- *
- * @param gc      The connection.
- * @param account The account.
- */
-void purple_connection_set_account(PurpleConnection *gc, PurpleAccount *account);
-
-/**
  * Sets the connection's displayed name.
  *
  * @param gc   The connection.
============================================================
--- libpurple/plugins/perl/common/Connection.xs	725e72ea87def75d49d5adb2a815d1d6069dbd21
+++ libpurple/plugins/perl/common/Connection.xs	6b3a73f36cc216e660ec98538d8081a669bb0139
@@ -50,11 +50,6 @@ void
 	Purple::ConnectionState state
 
 void
-purple_connection_set_account(gc, account)
-	Purple::Connection gc
-	Purple::Account account
-
-void
 purple_connection_set_display_name(gc, name)
 	Purple::Connection gc
 	const char *name


More information about the Commits mailing list