/soc/2013/ankitkv/gobjectification: c76013b145f4: Added PURPLE_P...

Ankit Vani a at nevitus.org
Sat Aug 31 13:49:28 EDT 2013


Changeset: c76013b145f45d03bc634fc231e376193b3344cc
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-31 22:26 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/c76013b145f4

Description:

Added PURPLE_PROTOCOL_IMPLEMENTS(protocol,func) to check if a protocol implements a function

diffstat:

 libpurple/account.c        |  12 ++++++------
 libpurple/blistnodetypes.c |   4 ++--
 libpurple/buddylist.c      |   2 +-
 libpurple/connection.c     |   4 ++--
 libpurple/protocol.h       |  12 ++++++------
 libpurple/protocols.c      |   2 +-
 6 files changed, 18 insertions(+), 18 deletions(-)

diffs (153 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -1023,7 +1023,7 @@ purple_account_set_public_alias(PurpleAc
 	gc = purple_account_get_connection(account);
 	protocol = purple_connection_get_protocol_info(gc);
 
-	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->set_public_alias)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, set_public_alias))
 		purple_protocol_iface_set_public_alias(protocol, gc, alias, success_cb, failure_cb);
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
@@ -1061,7 +1061,7 @@ purple_account_get_public_alias(PurpleAc
 	gc = purple_account_get_connection(account);
 	protocol = purple_connection_get_protocol_info(gc);
 
-	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->get_public_alias)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, get_public_alias))
 		purple_protocol_iface_get_public_alias(protocol, gc, success_cb, failure_cb);
 	else if (failure_cb) {
 		struct public_alias_closure *closure =
@@ -2243,9 +2243,9 @@ purple_account_add_buddies(PurpleAccount
 			groups = g_list_append(groups, purple_buddy_get_group(buddy));
 		}
 
-		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->add_buddies)
+		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, add_buddies))
 			purple_protocol_iface_add_buddies(protocol, gc, buddies, groups, message);
-		else if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->add_buddy) {
+		else if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, add_buddy)) {
 			GList *curb = buddies, *curg = groups;
 
 			while ((curb != NULL) && (curg != NULL)) {
@@ -2283,7 +2283,7 @@ purple_account_remove_buddies(PurpleAcco
 		protocol = purple_connection_get_protocol_info(gc);
 
 	if (protocol) {
-		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->remove_buddies)
+		if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, remove_buddies))
 			purple_protocol_iface_remove_buddies(protocol, gc, buddies, groups);
 		else {
 			GList *curb = buddies;
@@ -2889,7 +2889,7 @@ purple_account_constructed(GObject *obje
 		return;
 	}
 
-	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->status_types != NULL)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, status_types))
 		purple_account_set_status_types(account,
 				purple_protocol_iface_status_types(protocol, account));
 
diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -1122,7 +1122,7 @@ const char *purple_chat_get_name_only(Pu
 
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(priv->account));
 
-	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->chat_info) {
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, chat_info)) {
 		PurpleProtocolChatEntry *pce;
 		GList *parts = purple_protocol_iface_chat_info(protocol, purple_account_get_connection(priv->account));
 		pce = parts->data;
@@ -1534,7 +1534,7 @@ void purple_group_set_name(PurpleGroup *
 					buddies = g_list_append(buddies, (PurpleBlistNode *)buddy);
 			}
 
-			if(PURPLE_PROTOCOL_GET_INTERFACE(protocol)->rename_group) {
+			if(PURPLE_PROTOCOL_IMPLEMENTS(protocol, rename_group)) {
 				purple_protocol_iface_rename_group(protocol, gc, old_name, source, buddies);
 			} else {
 				GList *cur, *groups = NULL;
diff --git a/libpurple/buddylist.c b/libpurple/buddylist.c
--- a/libpurple/buddylist.c
+++ b/libpurple/buddylist.c
@@ -1636,7 +1636,7 @@ purple_blist_find_chat(PurpleAccount *ac
 
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(account));
 
-	if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->find_blist_chat != NULL)
+	if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, find_blist_chat))
 		return purple_protocol_iface_find_blist_chat(protocol, account, name);
 
 	normname = g_strdup(purple_normalize(account, name));
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -132,7 +132,7 @@ update_keepalive(PurpleConnection *gc, g
 
 	g_return_if_fail(priv != NULL);
 
-	if (!PURPLE_PROTOCOL_GET_INTERFACE(priv->protocol)->keepalive)
+	if (!PURPLE_PROTOCOL_IMPLEMENTS(priv->protocol, keepalive))
 		return;
 
 	if (on && !priv->keepalive)
@@ -897,7 +897,7 @@ void
 
 	if (regist)
 	{
-		if (PURPLE_PROTOCOL_GET_INTERFACE(protocol)->register_user == NULL)
+		if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, register_user))
 			return;
 	}
 	else
diff --git a/libpurple/protocol.h b/libpurple/protocol.h
--- a/libpurple/protocol.h
+++ b/libpurple/protocol.h
@@ -524,8 +524,12 @@ struct _PurpleProtocolInterface
 };
 
 /**
- * PURPLE_PROTOCOL_DEFINE:
- *
+ * Returns TRUE if a protocol implements a function, FALSE otherwise.
+ */
+#define PURPLE_PROTOCOL_IMPLEMENTS(protocol,func) \
+	(PURPLE_PROTOCOL_GET_INTERFACE(protocol)->func != NULL)
+
+/**
  * 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()
@@ -554,8 +558,6 @@ struct _PurpleProtocolInterface
 #endif
 
 /**
- * PURPLE_PROTOCOL_DEFINE_STATIC:
- *
  * Defines a protocol type statically using the type name, function prefix,
  * base type and type flags.
  */
@@ -583,8 +585,6 @@ struct _PurpleProtocolInterface
 	}
 
 /**
- * PURPLE_PROTOCOL_DEFINE_DYNAMIC:
- *
  * Defines a protocol type dynamically using the plugin, type name,
  * function prefix, base type and type flags.
  */
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -445,7 +445,7 @@ purple_protocol_send_attention(PurpleCon
 	g_return_if_fail(who != NULL);
 
 	protocol = purple_find_protocol_info(purple_account_get_protocol_id(purple_connection_get_account(gc)));
-	g_return_if_fail(PURPLE_PROTOCOL_GET_INTERFACE(protocol)->send_attention != NULL);
+	g_return_if_fail(PURPLE_PROTOCOL_IMPLEMENTS(protocol, send_attention));
 
 	mtime = time(NULL);
 



More information about the Commits mailing list