summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2010-07-07 14:43:38 +0200
committerMarcel Holtmann <marcel@holtmann.org>2010-07-07 10:18:56 -0300
commitfda8614ef6375431082109a587b416faf9e02707 (patch)
tree76b3111bbb8253bd05acf34cf79008310ac07c8c /src
parentbf2082ded0ec063428357355c4938a0712628848 (diff)
downloadconnman-fda8614ef6375431082109a587b416faf9e02707.tar.gz
connman-fda8614ef6375431082109a587b416faf9e02707.tar.bz2
connman-fda8614ef6375431082109a587b416faf9e02707.zip
Initialize offset counters
The Service object needs the the first update of the statistic counters to know the offset for its calculation. Until now, the first timeout of timer was used to update this values. This fix triggers an update only for initialiting the offset values and does not notify the counter clients.
Diffstat (limited to 'src')
-rw-r--r--src/counter.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/src/counter.c b/src/counter.c
index f290179f..a4613ca1 100644
--- a/src/counter.c
+++ b/src/counter.c
@@ -40,6 +40,11 @@ struct connman_counter {
guint watch;
};
+struct counter_data {
+ struct connman_service *service;
+ connman_bool_t first_update;
+};
+
static void remove_counter(gpointer user_data)
{
struct connman_counter *counter = user_data;
@@ -56,6 +61,13 @@ static void remove_counter(gpointer user_data)
g_free(counter);
}
+static void remove_data(gpointer user_data)
+{
+ struct counter_data *data = user_data;
+
+ g_free(data);
+}
+
static void owner_disconnect(DBusConnection *connection, void *user_data)
{
struct connman_counter *counter = user_data;
@@ -159,21 +171,26 @@ static void send_usage(struct connman_counter *counter,
void __connman_counter_notify(struct connman_ipconfig *config,
unsigned int rx_bytes, unsigned int tx_bytes)
{
- struct connman_service *service;
+ struct counter_data *data;
GHashTableIter iter;
gpointer key, value;
- service = g_hash_table_lookup(stats_table, config);
- if (service == NULL)
+ data = g_hash_table_lookup(stats_table, config);
+ if (data == NULL)
return;
- __connman_service_stats_update(service, rx_bytes, tx_bytes);
+ __connman_service_stats_update(data->service, rx_bytes, tx_bytes);
+
+ if (data->first_update == TRUE) {
+ data->first_update = FALSE;
+ return;
+ }
g_hash_table_iter_init(&iter, counter_table);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
struct connman_counter *counter = value;
- send_usage(counter, service);
+ send_usage(counter, data->service);
}
}
@@ -197,9 +214,23 @@ static void release_counter(gpointer key, gpointer value, gpointer user_data)
int __connman_counter_add_service(struct connman_service *service)
{
struct connman_ipconfig *config;
+ struct counter_data *data;
+
+ data = g_try_new0(struct counter_data, 1);
+ if (data == NULL)
+ return -ENOMEM;
+
+ data->service = service;
+ data->first_update = TRUE;
config = __connman_service_get_ipconfig(service);
- g_hash_table_replace(stats_table, config, service);
+ g_hash_table_replace(stats_table, config, data);
+
+ /*
+ * Trigger a first update to intialize the offset counters
+ * in the service.
+ */
+ __connman_rtnl_request_update();
return 0;
}
@@ -221,7 +252,7 @@ int __connman_counter_init(void)
return -1;
stats_table = g_hash_table_new_full(g_direct_hash, g_str_equal,
- NULL, NULL);
+ NULL, remove_data);
counter_table = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, remove_counter);