Skip to content

Instantly share code, notes, and snippets.

@pgrandin
Created October 31, 2014 22:48
Show Gist options
  • Save pgrandin/d2adb89cd2fae73f5636 to your computer and use it in GitHub Desktop.
Save pgrandin/d2adb89cd2fae73f5636 to your computer and use it in GitHub Desktop.
#include <glib.h>
#include "debug.h"
#include "navit.h"
#include "metrics.h"
struct metriclist;
GHashTable *
metriclist_init(void)
{
dbg(0,"metrics_hash is null, initializing\n");
return g_hash_table_new(g_str_hash, g_str_equal);
}
int
//metrics_update(GHashTable * metrics_hash,char *name,int value)
metrics_update(struct navit *navit,char *name,int value)
{
char *key=g_strdup(name);
GHashTable *hash_table = navit_get_metrics_hash(navit);
if (!hash_table) {
dbg(0,"Hash is null\n");
return -1;
}
dbg(1,"write : Hash is at 0x%x from object %x\n", hash_table, navit);
if (g_hash_table_insert (hash_table, key, &value)) {
dbg(0,"%s [%i] is new in the hash\n",key,value);
} else {
dbg(1,"%s [%i] was updated in the hash\n",key,value);
}
}
int
get_metrics(struct navit *navit,char *name)
{
GHashTable *hash_table = navit_get_metrics_hash(navit);
if (!hash_table) {
dbg(0,"Hash is null\n");
return -1;
}
dbg(1,"read : Hash is at 0x%x from object %x\n", hash_table, navit);
int *value_from_hash=g_hash_table_lookup (hash_table, name);
dbg(1,"Fetched value %i for key %s\n", *value_from_hash, name);
return *value_from_hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment