gobjectification: 7b3c62f0: Try using a PurpleObject. Let's see how ...

sadrul at pidgin.im sadrul at pidgin.im
Thu Mar 13 04:38:08 EDT 2008


-----------------------------------------------------------------
Revision: 7b3c62f02005a8147da4abfe431b44859ec1f82d
Ancestor: b835ec6225ea17e8883d47305d89071a31682c27
Author: sadrul at pidgin.im
Date: 2008-03-12T22:42:58
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/7b3c62f02005a8147da4abfe431b44859ec1f82d

Added files:
        libpurple/pobject.c libpurple/pobject.h
Modified files:
        libpurple/Makefile.am libpurple/connection.c
        libpurple/connection.h libpurple/dbus-server.c
        libpurple/value.c libpurple/value.h

ChangeLog: 

Try using a PurpleObject. Let's see how this goes.

-------------- next part --------------
============================================================
--- libpurple/pobject.c	59c2119273d36f3a1bdbd61544d542eb48e93c40
+++ libpurple/pobject.c	59c2119273d36f3a1bdbd61544d542eb48e93c40
@@ -0,0 +1,100 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#include "pobject.h"
+
+struct _PurpleObjectPrivate
+{
+	gpointer proto_data;
+};
+
+static GObjectClass *parent_class;
+
+static void
+purple_object_dispose(GObject *obj)
+{
+	PurpleObject *pobj = PURPLE_OBJECT(obj);
+
+	if (pobj->priv->proto_data) {
+		g_warning("Purple-Object: object destroyed without unsetting the protocol data. This may lead to memory leak.\n");
+	}
+
+	/* XXX: do _notify_close_with_handle etc here */
+
+	parent_class->dispose(obj);
+}
+
+static void
+purple_object_class_init(PurpleObjectClass *klass)
+{
+	GObjectClass *gclass= G_OBJECT_CLASS(klass);
+
+	parent_class = g_type_class_peek_parent(klass);
+
+	gclass->dispose = purple_object_dispose;
+	g_type_class_add_private(klass, sizeof(PurpleObjectPrivate));
+}
+
+static void
+purple_object_init(GTypeInstance *instance, gpointer class)
+{
+	PurpleObject *pobj = PURPLE_OBJECT(instance);
+	pobj->priv = G_TYPE_INSTANCE_GET_PRIVATE(pobj, PURPLE_TYPE_OBJECT, PurpleObjectPrivate);
+	pobj->priv->proto_data = NULL;
+}
+
+GType purple_object_get_type(void)
+{
+	static GType type = 0;
+
+	if(type == 0) {
+		static const GTypeInfo info = {
+			sizeof(PurpleObjectClass),
+			NULL,                    /* base_init        */
+			NULL,                    /* base_finalize    */
+			(GClassInitFunc)purple_object_class_init,
+			NULL,
+			NULL,                    /* class_data        */
+			sizeof(PurpleObject),
+			0,                       /* n_preallocs        */
+			purple_object_init,      /* instance_init    */
+			NULL                     /* value_table        */
+		};
+
+		type = g_type_register_static(G_TYPE_OBJECT,
+				"PurpleObject",
+				&info, G_TYPE_FLAG_ABSTRACT);
+	}
+
+	return type;
+}
+
+void purple_object_set_protocol_data(PurpleObject *pobj, gpointer proto_data)
+{
+	g_return_if_fail(pobj);
+	pobj->priv->proto_data = proto_data;
+}
+
+gpointer purple_object_get_protocol_data(PurpleObject *pobj)
+{
+	g_return_val_if_fail(pobj, NULL);
+	return pobj->priv->proto_data;
+}
+
============================================================
--- libpurple/pobject.h	adfc89ed0cfe64155ef939750e58f73ccf43e275
+++ libpurple/pobject.h	adfc89ed0cfe64155ef939750e58f73ccf43e275
@@ -0,0 +1,62 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+#ifndef PURPLE_OBJECT_H
+#define PURPLE_OBJECT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#define PURPLE_TYPE_OBJECT              (purple_object_get_type())
+#define PURPLE_OBJECT(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_OBJECT, PurpleObject))
+#define PURPLE_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_OBJECT, PurpleObjectClass))
+#define PURPLE_IS_OBJECT(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_OBJECT))
+#define PURPLE_IS_OBJECT_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_OBJECT))
+#define PURPLE_OBJECT_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_OBJECT, PurpleObjectClass))
+
+typedef struct _PurpleObject        PurpleObject;
+typedef struct _PurpleObjectPrivate PurpleObjectPrivate;
+typedef struct _PurpleObjectClass   PurpleObjectClass;
+
+struct _PurpleObject
+{
+    GObject gparent;
+    PurpleObjectPrivate *priv;
+    void (*_reserved[4])(void);
+};
+
+struct _PurpleObjectClass
+{
+	GObjectClass gparent;
+
+	void (*_purple_reserved[4])(void);
+};
+
+G_BEGIN_DECLS
+
+GType purple_object_get_type(void);
+
+void purple_object_set_protocol_data(PurpleObject *pobj, gpointer proto_data);
+
+gpointer purple_object_get_protocol_data(PurpleObject *pobj);
+
+G_END_DECLS
+
+#endif /* PURPLE_OBJECT_H */
============================================================
--- libpurple/Makefile.am	c056fb4f0773ea2581850f57d471c1115290e3bc
+++ libpurple/Makefile.am	d688ae573e34041f8d290cc72f0ce82416d71f05
@@ -65,6 +65,7 @@ purple_coresources = \
 	notify.c \
 	plugin.c \
 	pluginpref.c \
+	pobject.c \
 	pounce.c \
 	prefs.c \
 	privacy.c \
@@ -125,6 +126,7 @@ purple_coreheaders = \
 	ntlm.h \
 	plugin.h \
 	pluginpref.h \
+	pobject.h \
 	pounce.h \
 	prefs.h \
 	privacy.h \
============================================================
--- libpurple/connection.c	3e9f856da62a04b1691daf11d1abbf06ae9e300e
+++ libpurple/connection.c	e4aa7765135d78dab2db72b155a6ee5d91946ba9
@@ -949,7 +949,7 @@ purple_connection_get_gtype(void)
 			NULL,
 		};
 
-		type = g_type_register_static(G_TYPE_OBJECT,
+		type = g_type_register_static(PURPLE_TYPE_OBJECT,
 									  "PurpleConnection",
 									  &info, 0);
 	}
============================================================
--- libpurple/connection.h	a353dd2ca7f9f082dd5893055326a54ef932f95e
+++ libpurple/connection.h	ab4f9684cf419875525d20325c6b62bd57f920dc
@@ -27,8 +27,7 @@
 #ifndef PURPLE_CONNECTION_H
 #define PURPLE_CONNECTION_H
 
-#include <glib.h>
-#include <glib-object.h>
+#include "pobject.h"
 
 #define PURPLE_TYPE_CONNECTION				(purple_connection_get_gtype())
 #define PURPLE_CONNECTION(obj)				(G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_CONNECTION, PurpleConnection))
@@ -240,7 +239,7 @@ struct _PurpleConnection
 
 struct _PurpleConnection
 {
-	GObject gparent;
+	PurpleObject gparent;
 
 	PurpleConnectionPrivate *priv;
 
@@ -252,7 +251,7 @@ struct _PurpleConnectionClass
 
 struct _PurpleConnectionClass
 {
-	GObjectClass gparent;
+	PurpleObjectClass gparent;
 
 	void (*signing_on)(PurpleConnection *pc);
 	void (*signed_on)(PurpleConnection *pc);
============================================================
--- libpurple/dbus-server.c	503cf0022090cb9e4ed43e4c14c73a528dee1ed3
+++ libpurple/dbus-server.c	0dfdb0af314d30545d0d20b44f9ebada03cf6b62
@@ -723,7 +723,9 @@ purple_dbus_message_append_purple_values
 			break;
 		case PURPLE_TYPE_SUBTYPE: /* registered pointers only! */
 		case PURPLE_TYPE_POINTER:
+#if 0
 		case PURPLE_TYPE_OBJECT:
+#endif
 		case PURPLE_TYPE_BOXED:
 			val = my_arg(gpointer);
 			id = purple_dbus_pointer_to_id(val);
============================================================
--- libpurple/value.c	38e4b961b6fb92aa8b7bb27b5d1ef0ab4eab243f
+++ libpurple/value.c	cb8899c3a240a00055d2f2c21969c749e19a379f
@@ -171,9 +171,11 @@ purple_value_dup(const PurpleValue *valu
 			purple_value_set_string(new_value, purple_value_get_string(value));
 			break;
 
+#if 0
 		case PURPLE_TYPE_OBJECT:
 			purple_value_set_object(new_value, purple_value_get_object(value));
 			break;
+#endif
 
 		case PURPLE_TYPE_POINTER:
 			purple_value_set_pointer(new_value, purple_value_get_pointer(value));
============================================================
--- libpurple/value.h	3a7b6a6dd8106466d5a438203706c2bc0c2b6cd9
+++ libpurple/value.h	b5608a94aa197b7bb8790e380a81a0d1c9a25597
@@ -47,7 +47,6 @@ typedef enum
 	PURPLE_TYPE_INT64,        /**< 64-bit integer.                   */
 	PURPLE_TYPE_UINT64,       /**< 64-bit unsigned integer.          */
 	PURPLE_TYPE_STRING,       /**< String.                           */
-	PURPLE_TYPE_OBJECT,       /**< Object pointer.                   */
 	PURPLE_TYPE_POINTER,      /**< Generic pointer.                  */
 	PURPLE_TYPE_ENUM,         /**< Enum.                             */
 	PURPLE_TYPE_BOXED         /**< Boxed pointer with specific type. */


More information about the Commits mailing list