/soc/2013/ankitkv/gobjectification: be16459a68e9: Finished imple...

Ankit Vani a at nevitus.org
Fri Aug 30 16:16:06 EDT 2013


Changeset: be16459a68e9e8d46acda9feaee54a8e7bc451b3
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-31 01:45 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/be16459a68e9

Description:

Finished implementation of protocol object and interface stuff in protocol.[ch].
Moved other stuff back to protocols.[ch].

diffstat:

 libpurple/protocol.c  |  709 +++++++++++++++++++++++++++++++++++++++++++++++++-
 libpurple/protocol.h  |  266 ++----------------
 libpurple/protocols.c |   51 +---
 libpurple/protocols.h |  214 +++++++++++++++
 4 files changed, 952 insertions(+), 288 deletions(-)

diffs (truncated from 1424 to 300 lines):

diff --git a/libpurple/protocol.c b/libpurple/protocol.c
--- a/libpurple/protocol.c
+++ b/libpurple/protocol.c
@@ -20,6 +20,713 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  *
  */
-#include "internal.h"
+#include "dbus-maybe.h"
 #include "protocol.h"
 
+static GObjectClass *parent_class;
+
+/**************************************************************************
+ * Protocol Class API
+ **************************************************************************/
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+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;
+}
+
+PurpleWhiteboardPrplOps *
+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_protocol_ops;
+}
+
+/**************************************************************************
+ * GObject stuff
+ **************************************************************************/
+
+static void
+purple_protocol_init(GTypeInstance *instance, gpointer klass)
+{
+	PURPLE_DBUS_REGISTER_POINTER(PURPLE_PROTOCOL(instance), PurpleProtocol);
+}
+
+static void
+purple_protocol_dispose(GObject *object)
+{
+	PurpleProtocol *protocol = PURPLE_PROTOCOL(object);
+
+	purple_request_close_with_handle(protocol);
+	purple_notify_close_with_handle(protocol);
+
+	purple_signals_disconnect_by_handle(protocol);
+	purple_signals_unregister_by_instance(protocol);
+
+	purple_prefs_disconnect_by_handle(protocol);
+
+	PURPLE_DBUS_UNREGISTER_POINTER(protocol);
+
+	parent_class->dispose(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_destroy(klass->icon_spec);
+}
+
+GType
+purple_protocol_get_type(void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY(type == 0)) {
+		static const GTypeInfo info = {
+			.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",
+		                              &info, G_TYPE_FLAG_ABSTRACT);
+	}
+
+	return type;
+}
+
+GType
+purple_protocol_iface_get_type(void)
+{
+	static GType type = 0;
+
+	if (G_UNLIKELY(type == 0)) {
+		static const GTypeInfo info = {
+			.class_size = sizeof(PurpleProtocolInterface),
+		};
+
+		type = g_type_register_static(G_TYPE_INTERFACE,
+		                              "PurpleProtocolInterface", &info, 0);
+	}
+
+	return type;
+}
+
+/**************************************************************************
+ * Protocol Interface API
+ **************************************************************************/
+
+#define DEFINE_PROTOCOL_FUNC(protocol,funcname,...) \
+	PurpleProtocolInterface *iface = PURPLE_PROTOCOL_GET_INTERFACE(protocol); \
+	g_return_if_fail(iface != NULL); \
+	if (iface->funcname) \
+		iface->funcname(__VA_ARGS__);
+
+#define DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol,defaultreturn,funcname,...) \
+	PurpleProtocolInterface *iface = PURPLE_PROTOCOL_GET_INTERFACE(protocol); \
+	g_return_val_if_fail(iface != NULL, defaultreturn); \
+	if (iface->funcname) \
+		return iface->funcname(__VA_ARGS__); \
+	else \
+		return defaultreturn;
+
+GList *
+purple_protocol_iface_get_actions(PurpleProtocol *protocol,
+                                  PurpleConnection *gc)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, get_actions, gc);
+}
+
+const char *
+purple_protocol_iface_list_icon(PurpleProtocol *protocol,
+                                PurpleAccount *account, PurpleBuddy *buddy)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_icon, account, buddy);
+}
+
+const char *
+purple_protocol_iface_list_emblem(PurpleProtocol *protocol, PurpleBuddy *buddy)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, list_emblem, buddy);
+}
+
+char *
+purple_protocol_iface_status_text(PurpleProtocol *protocol, PurpleBuddy *buddy)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_text, buddy);
+}
+
+void
+purple_protocol_iface_tooltip_text(PurpleProtocol *protocol, PurpleBuddy *buddy,
+                                   PurpleNotifyUserInfo *user_info,
+                                   gboolean full)
+{
+	DEFINE_PROTOCOL_FUNC(protocol, tooltip_text, buddy, user_info, full);
+}
+
+GList *
+purple_protocol_iface_status_types(PurpleProtocol *protocol,
+                                   PurpleAccount *account)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, status_types, account);
+}
+
+GList *
+purple_protocol_iface_blist_node_menu(PurpleProtocol *protocol,
+                                      PurpleBlistNode *node)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, blist_node_menu, node);
+}
+
+GList *
+purple_protocol_iface_chat_info(PurpleProtocol *protocol, PurpleConnection *gc)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, chat_info, gc);
+}
+
+GHashTable *
+purple_protocol_iface_chat_info_defaults(PurpleProtocol *protocol,
+                                         PurpleConnection *gc,
+                                         const char *chat_name)
+{
+	DEFINE_PROTOCOL_FUNC_WITH_RETURN(protocol, NULL, chat_info_defaults, gc,
+	                                 chat_name);
+}
+
+void
+purple_protocol_iface_login(PurpleProtocol *protocol, PurpleAccount *account)
+{
+	DEFINE_PROTOCOL_FUNC(protocol, login, account);
+}
+
+void
+purple_protocol_iface_close(PurpleProtocol *protocol, PurpleConnection *gc)
+{
+	DEFINE_PROTOCOL_FUNC(protocol, close, gc);
+}
+
+int 
+purple_protocol_iface_send_im(PurpleProtocol *protocol, PurpleConnection *gc, 
+                              const char *who, const char *message,



More information about the Commits mailing list