/soc/2013/ankitkv/gobjectification: 9c38716c8eb7: Moved protocol...
Ankit Vani
a at nevitus.org
Wed Sep 4 07:39:20 EDT 2013
Changeset: 9c38716c8eb7fd94dea568442d49094b83679480
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-04 16:09 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/9c38716c8eb7
Description:
Moved protocol class members to instance. Protocol definitions now require *_init, *_class_init instead of *_base_init.
diffstat:
libpurple/protocol.c | 116 +++++++++++++++++++++-----------------------------
libpurple/protocol.h | 41 ++++++++---------
2 files changed, 70 insertions(+), 87 deletions(-)
diffs (297 lines):
diff --git a/libpurple/protocol.c b/libpurple/protocol.c
--- a/libpurple/protocol.c
+++ b/libpurple/protocol.c
@@ -32,78 +32,57 @@ static GObjectClass *parent_class;
const char *
purple_protocol_get_id(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->id;
+ return protocol->id;
}
const char *
purple_protocol_get_name(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->name;
+ return protocol->name;
}
PurpleProtocolOptions
purple_protocol_get_options(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), 0);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->options;
+ return protocol->options;
}
GList *
purple_protocol_get_user_splits(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->user_splits;
+ return protocol->user_splits;
}
GList *
purple_protocol_get_protocol_options(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->protocol_options;
+ return protocol->protocol_options;
}
PurpleBuddyIconSpec *
purple_protocol_get_icon_spec(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->icon_spec;
+ return protocol->icon_spec;
}
PurpleWhiteboardOps *
purple_protocol_get_whiteboard_ops(const PurpleProtocol *protocol)
{
- PurpleProtocolClass *klass;
-
g_return_val_if_fail(PURPLE_IS_PROTOCOL(protocol), NULL);
- klass = PURPLE_PROTOCOL_GET_CLASS(protocol);
- return klass->whiteboard_ops;
+ return protocol->whiteboard_ops;
}
/**************************************************************************
@@ -120,6 +99,20 @@ static void
purple_protocol_dispose(GObject *object)
{
PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
+ GList *accounts, *l;
+
+ accounts = purple_accounts_get_all_active();
+ for (l = accounts; l != NULL; l = l->next) {
+ PurpleAccount *account = PURPLE_ACCOUNT(l->data);
+ if (purple_account_is_disconnected(account))
+ continue;
+
+ if (purple_strequal(protocol->id,
+ purple_account_get_protocol_id(account)))
+ purple_account_disconnect(account);
+ }
+
+ g_list_free(accounts);
purple_request_close_with_handle(protocol);
purple_notify_close_with_handle(protocol);
@@ -135,47 +128,39 @@ purple_protocol_dispose(GObject *object)
}
static void
+purple_protocol_finalize(GObject *object)
+{
+ PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
+
+ while (protocol->user_splits) {
+ PurpleAccountUserSplit *split = protocol->user_splits->data;
+ purple_account_user_split_destroy(split);
+ protocol->user_splits = g_list_delete_link(protocol->user_splits,
+ protocol->user_splits);
+ }
+
+ while (protocol->protocol_options) {
+ PurpleAccountOption *option = protocol->protocol_options->data;
+ purple_account_option_destroy(option);
+ protocol->protocol_options =
+ g_list_delete_link(protocol->protocol_options,
+ protocol->protocol_options);
+ }
+
+ purple_buddy_icon_spec_free(protocol->icon_spec);
+
+ parent_class->finalize(object);
+}
+
+static void
purple_protocol_class_init(PurpleProtocolClass *klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_peek_parent(klass);
- obj_class->dispose = purple_protocol_dispose;
-}
-
-static void
-purple_protocol_base_finalize(PurpleProtocolClass *klass)
-{
- GList *accounts, *l;
-
- accounts = purple_accounts_get_all_active();
- for (l = accounts; l != NULL; l = l->next) {
- PurpleAccount *account = PURPLE_ACCOUNT(l->data);
- if (purple_account_is_disconnected(account))
- continue;
-
- if (purple_strequal(klass->id, purple_account_get_protocol_id(account)))
- purple_account_disconnect(account);
- }
-
- g_list_free(accounts);
-
- while (klass->user_splits) {
- PurpleAccountUserSplit *split = klass->user_splits->data;
- purple_account_user_split_destroy(split);
- klass->user_splits = g_list_delete_link(klass->user_splits,
- klass->user_splits);
- }
-
- while (klass->protocol_options) {
- PurpleAccountOption *option = klass->protocol_options->data;
- purple_account_option_destroy(option);
- klass->protocol_options = g_list_delete_link(klass->protocol_options,
- klass->protocol_options);
- }
-
- purple_buddy_icon_spec_free(klass->icon_spec);
+ obj_class->dispose = purple_protocol_dispose;
+ obj_class->finalize = purple_protocol_finalize;
}
GType
@@ -185,11 +170,10 @@ purple_protocol_get_type(void)
if (G_UNLIKELY(type == 0)) {
static const GTypeInfo info = {
+ .class_size = sizeof(PurpleProtocolClass),
+ .class_init = (GClassInitFunc)purple_protocol_class_init,
.instance_size = sizeof(PurpleProtocol),
.instance_init = (GInstanceInitFunc)purple_protocol_init,
- .class_size = sizeof(PurpleProtocolClass),
- .class_init = (GClassInitFunc)purple_protocol_class_init,
- .base_finalize = (GBaseFinalizeFunc)purple_protocol_base_finalize,
};
type = g_type_register_static(G_TYPE_OBJECT, "PurpleProtocol",
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -1,5 +1,5 @@
/**
- * @file protocol.h Protocol class and interface API
+ * @file protocol.h Protocol object and interface API
* @ingroup core
*/
@@ -64,24 +64,12 @@ typedef struct _PurpleProtocolInterface
/**
* Represents an instance of a protocol registered with the protocols
- * subsystem.
+ * subsystem. Protocols must initialize the members to appropriate values.
*/
struct _PurpleProtocol
{
/*< private >*/
GObject gparent;
-};
-
-/**
- * The base class for all protocols.
- *
- * Protocols must set the members of this class to appropriate values upon
- * class initialization.
- */
-struct _PurpleProtocolClass
-{
- /*< private >*/
- GObjectClass parent_class;
const char *id; /**< Protocol ID */
const char *name; /**< Translated name of the protocol */
@@ -102,6 +90,15 @@ struct _PurpleProtocolClass
};
/**
+ * The base class for all protocols.
+ */
+struct _PurpleProtocolClass
+{
+ /*< private >*/
+ GObjectClass parent_class;
+};
+
+/**
* The protocol interface.
*
* Every protocol implements this interface. It is the gateway between purple
@@ -535,8 +532,8 @@ struct _PurpleProtocolInterface
/**
* Defines a protocol type in a plugin (given as a PurplePlugin *) by using the
* CamelCase type name of the protocol and the function prefix for the
- * *_get_type(), *_base_init(), *_base_finalize() and *_interface_init()
- * functions of the protocol.
+ * generated *_get_type(), and the *_init(), *_class_init() and
+ * *_interface_init() functions used by the protocol.
*
* The type may be registered statically or dynamically.
*/
@@ -570,9 +567,10 @@ struct _PurpleProtocolInterface
static GType type = 0; \
if (G_UNLIKELY(type == 0)) { \
static const GTypeInfo info = { \
+ .class_size = sizeof(TypeName##Class), \
+ .class_init = (GClassInitFunc)func_prefix##_class_init, \
.instance_size = sizeof(TypeName), \
- .class_size = sizeof(TypeName##Class), \
- .base_init = (GBaseInitFunc)func_prefix##_base_init, \
+ .instance_init = (GInstanceInitFunc)func_prefix##_init, \
}; \
static const GInterfaceInfo iface_info = { \
.interface_init = (GInterfaceInitFunc)func_prefix##_interface_init, \
@@ -596,9 +594,10 @@ struct _PurpleProtocolInterface
static GType type = 0; \
if (G_UNLIKELY(type == 0)) { \
static const GTypeInfo info = { \
+ .class_size = sizeof(TypeName##Class), \
+ .class_init = (GClassInitFunc)func_prefix##_class_init, \
.instance_size = sizeof(TypeName), \
- .class_size = sizeof(TypeName##Class), \
- .base_init = (GBaseInitFunc)func_prefix##_base_init, \
+ .instance_init = (GInstanceInitFunc)func_prefix##_init, \
}; \
static const GInterfaceInfo iface_info = { \
.interface_init = (GInterfaceInitFunc)func_prefix##_interface_init, \
@@ -620,7 +619,7 @@ struct _PurpleProtocolInterface
G_BEGIN_DECLS
/**************************************************************************/
-/** @name Protocol Class API */
+/** @name Protocol Object API */
/**************************************************************************/
/*@{*/
More information about the Commits
mailing list