/soc/2012/sanket/statscollector-2.x.y: 252d2a5935e4: Add event t...
Sanket Agarwal
sanket at soc.pidgin.im
Tue Jul 10 00:36:21 EDT 2012
Changeset: 252d2a5935e4dd2b1175cc7d81bd53d5d4eb796d
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2012-05-14 05:21 +0000
Branch: soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/252d2a5935e4
Description:
Add event timers to avoid slowing of event processing; remove extrenous warnings
diffstat:
pidgin/plugins/statscollector.c | 64 ++++++++++++++++++++++++----------------
1 files changed, 39 insertions(+), 25 deletions(-)
diffs (155 lines):
diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -1,14 +1,16 @@
-#define PURPLE_PLUGINS
+/* Log the activity of users */
+
+#include "internal.h"
+#include "pidgin.h"
+
+#include "debug.h"
+#include "log.h"
+#include "notify.h"
+#include "signals.h"
+#include "util.h"
+#include "version.h"
#include <glib.h>
-
-#include "notify.h"
-#include "plugin.h"
-#include "version.h"
-#include "debug.h"
-
-#include "internal.h"
-
#include <gtkplugin.h>
#define STATS_MAJOR_VERSION 1
@@ -16,6 +18,7 @@
xmlnode *root_stats;
GHashTable *stats_acc_ht, *stats_plugins_ht;
+int save_timer = 0;
static void
save_xml(){
@@ -27,7 +30,7 @@
GHashTableIter iter;
gpointer key, value;
- xmlnode *nroot, *nacc, *nplugins, *node, *node1, *node2;
+ xmlnode *nroot, *nacc, *nplugins, *node;
char *data;
nroot = xmlnode_new("stats");
@@ -61,6 +64,19 @@
}
+static gboolean
+save_cb(gpointer data){
+ save_xml();
+ save_timer = 0;
+ return FALSE;
+}
+
+static void
+schedule_stats_save(void){
+ if(save_timer == 0)
+ save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
+}
+
static void
sign_on_event(PurpleAccount *account){
@@ -70,7 +86,7 @@
* 1.1 If no, then add the account to the list of accounts used
*/
- char *username, *protocol, *data;
+ const char *username, *protocol, *data;
xmlnode *acc, *u_node, *p_node;
username = purple_account_get_username(account);
@@ -92,11 +108,11 @@
data = xmlnode_to_str(acc, NULL);
- g_hash_table_insert(stats_acc_ht, username, data);
+ g_hash_table_insert(stats_acc_ht, (void *)username, (void *)data);
}
- save_xml();
+ schedule_stats_save();
}
@@ -109,7 +125,7 @@
* 1.1 If no, then add the account to the list of accounts used
*/
- char *plugin_id, *data;
+ const char *plugin_id, *data;
xmlnode *plugin_xml, *p_id;
PurplePluginType plugin_type;
@@ -141,11 +157,11 @@
/* purple_debug_info("STATS", "PLGN %s %s\\n", */
/* plugin_id, data); */
- g_hash_table_insert(stats_plugins_ht, plugin_id, data);
+ g_hash_table_insert(stats_plugins_ht, (void *)plugin_id, (void *)data);
}
- save_xml();
+ schedule_stats_save();
}
static xmlnode *
@@ -157,13 +173,11 @@
* 2. In case plugin versions change the XML format, handle that
*/
- GHashTableIter *iter;
+ /* GHashTableIter *iter; */
GList *loaded_plugins;
- char *key, *value;
char *data;
xmlnode *stats_acc_xml, *stats_plugins_xml;
- xmlnode *start, *u_node, *p_node;
-
+ xmlnode *start, *u_node;
/* Load the xml */
xmlnode *root = purple_util_read_xml_from_file("stats.xml",
"stats-collection");
@@ -207,13 +221,13 @@
}
- g_hash_table_iter_init(&iter, stats_acc_ht);
+ /* g_hash_table_iter_init(&iter, stats_acc_ht); */
- while(g_hash_table_iter_next(&iter, &key, &value)){
+ /* while(g_hash_table_iter_next(&iter, &key, &value)){ */
- purple_debug_info("STATS", "HASH %s\n", value);
+ /* purple_debug_info("STATS", "HASH %s\\n", value); */
- }
+ /* } */
start = xmlnode_get_child(stats_acc_xml, "plugin");
@@ -234,7 +248,7 @@
loaded_plugins = purple_plugins_get_loaded();
- g_list_foreach(loaded_plugins, plugin_load_event, NULL);
+ g_list_foreach(loaded_plugins, (GFunc)plugin_load_event, NULL);
More information about the Commits
mailing list