soc.2012.statscollector: 4d612f4b: Load Account info in a hash-table

sanket at sanketagarwal.com sanket at sanketagarwal.com
Mon May 14 13:27:59 EDT 2012


----------------------------------------------------------------------
Revision: 4d612f4b1c83ea1c7268d5f840a05b6279017e32
Parent:   333323d642e81d7caaafcfda6b0979a7513b8b76
Author:   sanket at sanketagarwal.com
Date:     05/12/12 14:20:45
Branch:   im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/4d612f4b1c83ea1c7268d5f840a05b6279017e32

Changelog: 

Load Account info in a hash-table

It is required to store information initially in a Hash table to
facilitate further updates to stats. Though this seems initally
harsh as too much coding, in the long run it's a better practice.

Once the scheme for accounts is established we can move to more
stats such as plugins or CPU info etc.

Changes against parent 333323d642e81d7caaafcfda6b0979a7513b8b76

  patched  pidgin/plugins/statscollector.c

-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c	3e8ae838ef14f58691b2cd7397341e51d67492d3
+++ pidgin/plugins/statscollector.c	8fb4b55bd8f469bbfc34208e8d6c3dbe2471f5e4
@@ -15,6 +15,7 @@ xmlnode *root_stats;
 #define STATS_MINOR_VERSION 0
 
 xmlnode *root_stats;
+GHashTable *stats_acc_ht, *stats_plugins_ht;
 
 static void
 sign_on_event(PurpleAccount *account){
@@ -25,8 +26,18 @@ sign_on_event(PurpleAccount *account){
    * 1.1 If no, then add the account to the list of accounts used
    */
 
-  xmlnode *fetch;
+  char *username, *protocol;
 
+  username = purple_account_get_username(account);
+  protocol = purple_account_get_protocol_id(account);
+
+  /* check if the account already exist in our XML file */
+
+  if(g_hash_table_lookup(stats_acc_ht, username))
+    purple_debug_info("STATS", "Account already exists!");
+  else g_hash_table_insert(stats_acc_ht, username, protocol);
+
+
   purple_debug_info("XX-STATS",
       "Logged into a account %s with protocol %s",
       purple_account_get_username(account),
@@ -45,6 +56,8 @@ init_stats(){
 
   /* Load the xml */
   char *data;
+  xmlnode *stats_acc_xml, *stats_plugins_xml;
+  xmlnode *start, *u_node, *p_node;
   xmlnode *root = purple_util_read_xml_from_file("stats.xml",
       "stats-collection");
 
@@ -55,8 +68,8 @@ init_stats(){
     /* Create an empty structure for the XML */
     root = xmlnode_new("stats");
 
+    xmlnode_new_child(root, "cpuinfo");
     xmlnode_new_child(root, "accounts");
-    xmlnode_new_child(root, "cpuinfo");
     xmlnode_new_child(root, "plugins");
 
     /* Write the structure back (init) */
@@ -65,8 +78,40 @@ init_stats(){
 
   }
 
-  /* Check if the XML format version is compatible with current XML */
+  else{
 
+    /* Populate the hash tables with account and plugin information */
+
+    stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
+    stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
+
+    stats_acc_xml = xmlnode_get_child(root, "accounts");
+    stats_plugins_xml = xmlnode_get_child(root, "plugins");
+
+    purple_debug_info("STATS", "Accounts: %s", xmlnode_to_formatted_str(stats_acc_xml, NULL));
+
+    start = xmlnode_get_child(stats_acc_xml, "account");
+
+    for(;start;start = xmlnode_get_next_twin(start)){
+
+      u_node = xmlnode_get_child(start, "username");
+      p_node = xmlnode_get_child(start, "protocol");
+
+      g_hash_table_insert(stats_acc_ht, (char *)xmlnode_get_data(u_node),
+          (char *)xmlnode_get_data(p_node));
+
+    }
+
+    start = xmlnode_get_child(stats_acc_xml, "plugins");
+
+    for(;start;start = xmlnode_get_next_twin(start)){
+
+      /* Logic to be still filled up */
+
+     }
+
+  }
+
   /* Return the structure for modification */
   return root;
 }


More information about the Commits mailing list