/soc/2013/ankitkv/gobjectification: 8ed701a7333e: Added a protoc...

Ankit Vani a at nevitus.org
Mon Jul 29 11:10:26 EDT 2013


Changeset: 8ed701a7333e5c180619049a01388755b3244569
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-29 20:40 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/8ed701a7333e

Description:

Added a protocols subsystem API and a protocols API to add/remove protocols.
* Added purple_protocols_add(), adds a protocol to the protocols list
* Added purple_protocols_remove(), removes a protocol from the protocols list
* Added purple_protocols_init(), initializes protocols hash table
* Added purple_protocols_uninit(), destroys protocols hash table
* Added purple_protocols_get_handle()

init and uninit are done in the core just before and after that of plugins subsystem respectively.
This API needs a sanity check and more careful insight.
For now, this can be considered temporary till I get to working on the protocol API.

diffstat:

 libpurple/core.c |   3 ++
 libpurple/prpl.c |  78 +++++++++++++++++++++++++++++++++++++------------------
 libpurple/prpl.h |  44 ++++++++++++++++++++++++++++++-
 3 files changed, 98 insertions(+), 27 deletions(-)

diffs (238 lines):

diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -141,6 +141,7 @@ purple_core_init(const char *ui)
 #endif
 
 	purple_cmds_init();
+	purple_protocols_init();
 
 	/* Since plugins get probed so early we should probably initialize their
 	 * subsystem right away too.
@@ -255,6 +256,8 @@ purple_core_quit(void)
 	/* Everything after prefs_uninit must not try to read any prefs */
 	purple_prefs_uninit();
 	purple_plugins_uninit();
+	purple_protocols_uninit();
+
 #ifdef HAVE_DBUS
 	purple_dbus_uninit();
 #endif
diff --git a/libpurple/prpl.c b/libpurple/prpl.c
--- a/libpurple/prpl.c
+++ b/libpurple/prpl.c
@@ -29,6 +29,8 @@
 #include "request.h"
 #include "util.h"
 
+static GHashTable *protocols = NULL;
+
 /**************************************************************************/
 /** @name Attention Type API                                              */
 /**************************************************************************/
@@ -343,7 +345,6 @@ static void
 do_prpl_change_account_status(PurpleAccount *account,
 								PurpleStatus *old_status, PurpleStatus *new_status)
 {
-	PurplePlugin *prpl;
 	PurplePluginProtocolInfo *prpl_info;
 
 	if (purple_status_is_online(new_status) &&
@@ -373,13 +374,11 @@ do_prpl_change_account_status(PurpleAcco
 		 */
 		return;
 
-	prpl = purple_find_protocol_info(purple_account_get_protocol_id(account));
+	prpl_info = purple_find_protocol_info(purple_account_get_protocol_id(account));
 
-	if (prpl == NULL)
+	if (prpl_info == NULL)
 		return;
 
-	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-
 	if (!purple_account_is_disconnected(account) && prpl_info->set_status != NULL)
 	{
 		prpl_info->set_status(account, new_status);
@@ -436,7 +435,7 @@ purple_prpl_send_attention(PurpleConnect
 {
 	PurpleAttentionType *attn;
 	PurpleMessageFlags flags;
-	PurplePlugin *prpl;
+	PurplePluginProtocolInfo *prpl_info;
 	PurpleIMConversation *im;
 	gboolean (*send_attention)(PurpleConnection *, const char *, guint);
 	PurpleBuddy *buddy;
@@ -447,8 +446,8 @@ purple_prpl_send_attention(PurpleConnect
 	g_return_if_fail(gc != NULL);
 	g_return_if_fail(who != NULL);
 
-	prpl = purple_find_protocol_info(purple_account_get_protocol_id(purple_connection_get_account(gc)));
-	send_attention = PURPLE_PLUGIN_PROTOCOL_INFO(prpl)->send_attention;
+	prpl_info = purple_find_protocol_info(purple_account_get_protocol_id(purple_connection_get_account(gc)));
+	send_attention = prpl_info->send_attention;
 	g_return_if_fail(send_attention != NULL);
 
 	mtime = time(NULL);
@@ -552,15 +551,12 @@ purple_prpl_initiate_media(PurpleAccount
 {
 #ifdef USE_VV
 	PurpleConnection *gc = NULL;
-	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 
 	if (account)
 		gc = purple_account_get_connection(account);
 	if (gc)
-		prpl = purple_connection_get_protocol_info(gc);
-	if (prpl)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+		prpl_info = purple_connection_get_protocol_info(gc);
 
 	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, initiate_media)) {
 		/* should check that the protocol supports this media type here? */
@@ -575,15 +571,12 @@ purple_prpl_get_media_caps(PurpleAccount
 {
 #ifdef USE_VV
 	PurpleConnection *gc = NULL;
-	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 
 	if (account)
 		gc = purple_account_get_connection(account);
 	if (gc)
-		prpl = purple_connection_get_protocol_info(gc);
-	if (prpl)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
+		prpl_info = purple_connection_get_protocol_info(gc);
 
 	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info,
 			get_media_caps)) {
@@ -627,23 +620,56 @@ purple_prpl_got_media_caps(PurpleAccount
 }
 
 /**************************************************************************
- * Protocol Plugin Subsystem API
+ * Protocols API
  **************************************************************************/
 
 PurplePluginProtocolInfo *
 purple_find_protocol_info(const char *id)
 {
-	GList *l;
-	PurplePlugin *plugin;
+	return g_hash_table_lookup(protocols, id);
+}
 
-	g_return_val_if_fail(id != NULL, NULL);
+gboolean
+purple_protocols_add(PurplePluginProtocolInfo *prpl_info)
+{
+	if (purple_find_protocol_info(prpl_info->id))
+		return FALSE;
 
-	for (l = purple_plugins_get_protocols(); l != NULL; l = l->next) {
-		plugin = (PurplePlugin *)l->data;
+	g_hash_table_insert(protocols, g_strdup(prpl_info->id), prpl_info);
+	return TRUE;
+}
 
-		if (purple_strequal(plugin->info->id, id))
-			return plugin;
-	}
+gboolean purple_protocols_remove(PurplePluginProtocolInfo *prpl_info)
+{
+	if (purple_find_protocol_info(prpl_info->id) == NULL)
+		return FALSE;
 
-	return NULL;
+	g_hash_table_remove(protocols, prpl_info->id);
+	return TRUE;
 }
+
+/**************************************************************************
+ * Protocols Subsystem API
+ **************************************************************************/
+
+void
+purple_protocols_init(void)
+{
+	/* TODO Use g_object_unref for value destroy when PurpleProtocol is a GObject */
+	protocols = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+}
+
+void *
+purple_protocols_get_handle(void)
+{
+	static int handle;
+
+	return &handle;
+}
+
+void
+purple_protocols_uninit(void) 
+{
+	g_hash_table_destroy(protocols);
+}
+
diff --git a/libpurple/prpl.h b/libpurple/prpl.h
--- a/libpurple/prpl.h
+++ b/libpurple/prpl.h
@@ -952,7 +952,7 @@ void purple_prpl_got_media_caps(PurpleAc
 /*@}*/
 
 /**************************************************************************/
-/** @name Protocol Plugin Subsystem API                                   */
+/** @name Protocols API                                                   */
 /**************************************************************************/
 /*@{*/
 
@@ -963,6 +963,48 @@ void purple_prpl_got_media_caps(PurpleAc
  */
 PurplePluginProtocolInfo *purple_find_protocol_info(const char *id);
 
+/** TODO A sanity check is needed
+ * Adds a protocol to the list of protocols.
+ *
+ * @param prpl_info  The protocol to add.
+ *
+ * @return TRUE if the protocol was added, else FALSE.
+ */
+gboolean purple_protocols_add(PurplePluginProtocolInfo *prpl_info);
+
+/** TODO A sanity check is needed
+ * Removes a protocol from the list of protocols.
+ *
+ * @param prpl_info  The protocol to remove.
+ *
+ * @return TRUE if the protocol was removed, else FALSE.
+ */
+gboolean purple_protocols_remove(PurplePluginProtocolInfo *prpl_info);
+
+/*@}*/
+
+/**************************************************************************/
+/** @name Protocols Subsytem API                                          */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Initializes the protocols subsystem.
+ */
+void purple_protocols_init(void);
+
+/** TODO Make protocols use this handle, instead of plugins handle
+ * Returns the protocols subsystem handle.
+ *
+ * @return The protocols subsystem handle.
+ */
+void *purple_protocols_get_handle(void);
+
+/**
+ * Uninitializes the protocols subsystem.
+ */
+void purple_protocols_uninit(void);
+
 /*@}*/
 
 G_END_DECLS



More information about the Commits mailing list