/soc/2012/sanket/statscollector-2.x.y: ba1d8112c576: Sign-on sig...
Sanket Agarwal
sanket at soc.pidgin.im
Tue Jul 10 00:36:21 EDT 2012
Changeset: ba1d8112c5769debba746eca3963a930d9a724c4
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2012-05-12 19:23 +0000
Branch: soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/ba1d8112c576
Description:
Sign-on signal handled
The functionality is as: each sign-on will either trigger adding
an extra account in stats.xml OR it will leave it unchanged.
There are some strucutural differences in the code in terms of
handling of the Hash Table efficiently.
diffstat:
pidgin/plugins/statscollector.c | 80 +++++++++++++++++++++++++++++++++-------
1 files changed, 66 insertions(+), 14 deletions(-)
diffs (142 lines):
diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -18,6 +18,41 @@
GHashTable *stats_acc_ht, *stats_plugins_ht;
static void
+save_xml(){
+
+ /* Uses the Hash tables and other XML nodes
+ * that have been saved/modified and create
+ * final modified XML out of it to be flushed
+ */
+
+ GHashTableIter iter;
+ gpointer key, value;
+ xmlnode *nroot, *nacc, *nplugins, *node, *node1, *node2;
+ char *data;
+
+ nroot = xmlnode_new("stats");
+ nacc = xmlnode_new_child(nroot, "accounts");
+ nplugins = xmlnode_new_child(nroot, "plugins");
+
+ /* Use the hash tables to populate acc and plugins */
+
+ g_hash_table_iter_init(&iter, stats_acc_ht);
+
+ while(g_hash_table_iter_next(&iter, &key, &value)){
+
+ node = xmlnode_from_str(value, -1);
+ xmlnode_insert_child(nacc, node);
+
+ }
+
+ // purple_debug_info("STATS", "SAVE %s", xmlnode_to_formatted_str(nroot, NULL));
+
+ data = xmlnode_to_formatted_str(nroot, NULL);
+ purple_util_write_data_to_file("stats.xml", data, -1);
+
+}
+
+static void
sign_on_event(PurpleAccount *account){
/* Store information about logging on of an account. The following
@@ -26,8 +61,9 @@
* 1.1 If no, then add the account to the list of accounts used
*/
- char *username, *protocol;
+ char *username, *protocol, *data;
+ xmlnode *acc, *u_node, *p_node;
username = purple_account_get_username(account);
protocol = purple_account_get_protocol_id(account);
@@ -35,13 +71,23 @@
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);
+ else{
+ acc = xmlnode_new("account");
- purple_debug_info("XX-STATS",
- "Logged into a account %s with protocol %s",
- purple_account_get_username(account),
- purple_account_get_protocol_id(account));
+ u_node = xmlnode_new_child(acc, "username");
+ xmlnode_insert_data(u_node, username, -1);
+
+ p_node = xmlnode_new_child(acc, "protocol");
+ xmlnode_insert_data(p_node, protocol, -1);
+
+ data = xmlnode_to_str(acc, NULL);
+
+ g_hash_table_insert(stats_acc_ht, username, data);
+
+ }
+
+ save_xml();
}
@@ -55,6 +101,8 @@
*/
/* Load the xml */
+ GHashTableIter *iter;
+ char *key, *value;
char *data;
xmlnode *stats_acc_xml, *stats_plugins_xml;
xmlnode *start, *u_node, *p_node;
@@ -68,7 +116,6 @@
/* 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, "plugins");
@@ -95,13 +142,21 @@
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));
+ (char *)xmlnode_to_formatted_str(start, NULL));
}
+ g_hash_table_iter_init(&iter, stats_acc_ht);
+
+ while(g_hash_table_iter_next(&iter, &key, &value)){
+
+ purple_debug_info("STATS", "HASH %s\n", value);
+
+ }
+
+
start = xmlnode_get_child(stats_acc_xml, "plugins");
for(;start;start = xmlnode_get_next_twin(start)){
@@ -127,13 +182,10 @@
root_stats = init_stats();
- /* Spit the current stats */
- purple_debug_info("STATS", "%s",xmlnode_to_formatted_str(root_stats, NULL));
-
/* Register the account signals for sign-on/off */
- /* purple_signal_connect(purple_accounts_get_handle(), "account-signed-on", */
- /* plugin, PURPLE_CALLBACK(sign_on_event), NULL); */
+ purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
+ plugin, PURPLE_CALLBACK(sign_on_event), NULL);
return TRUE;
}
More information about the Commits
mailing list