soc.2012.statscollector: f4ee3efc: Add event timers to avoid slowing of eve...

sanket at sanketagarwal.com sanket at sanketagarwal.com
Mon May 14 13:28:10 EDT 2012


----------------------------------------------------------------------
Revision: f4ee3efc2f4ba4b4454523a880d22e2319b3f665
Parent:   003eec1d7af1ba5154275fde41ef07f3ee3cace9
Author:   sanket at sanketagarwal.com
Date:     05/14/12 01:21:05
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/f4ee3efc2f4ba4b4454523a880d22e2319b3f665

Changelog: 

Add event timers to avoid slowing of event processing; remove extrenous warnings

Changes against parent 003eec1d7af1ba5154275fde41ef07f3ee3cace9

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	07b784ef72c4c99edbb24f6a768503b585eee9cc
+++ pidgin/plugins/statscollector.c	ed33c8898f25c70f385323b43eaee850a70a0f0d
@@ -1,14 +1,16 @@
-#define PURPLE_PLUGINS
+/* Log the activity of users */
 
-#include <glib.h>
+#include "internal.h"
+#include "pidgin.h"
 
+#include "debug.h"
+#include "log.h"
 #include "notify.h"
-#include "plugin.h"
+#include "signals.h"
+#include "util.h"
 #include "version.h"
-#include "debug.h"
 
-#include "internal.h"
-
+#include <glib.h>
 #include <gtkplugin.h>
 
 #define STATS_MAJOR_VERSION 1
@@ -16,6 +18,7 @@ GHashTable *stats_acc_ht, *stats_plugins
 
 xmlnode *root_stats;
 GHashTable *stats_acc_ht, *stats_plugins_ht;
+int save_timer = 0;
 
 static void
 save_xml(){
@@ -27,7 +30,7 @@ save_xml(){
 
   GHashTableIter iter;
   gpointer key, value;
-  xmlnode *nroot, *nacc, *nplugins, *node, *node1, *node2;
+  xmlnode *nroot, *nacc, *nplugins, *node;
   char *data;
 
   nroot = xmlnode_new("stats");
@@ -61,7 +64,20 @@ save_xml(){
 
 }
 
+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){
 
   /* Store information about logging on of an account. The following
@@ -70,7 +86,7 @@ sign_on_event(PurpleAccount *account){
    * 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 @@ sign_on_event(PurpleAccount *account){
 
     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 @@ plugin_load_event(PurplePlugin *plugin){
    * 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 @@ plugin_load_event(PurplePlugin *plugin){
     /* 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 @@ init_stats(){
    * 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 @@ init_stats(){
 
     }
 
-    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 @@ init_stats(){
 
     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