summaryrefslogtreecommitdiff
path: root/src/counter.c
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2010-06-30 19:22:55 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-06-30 19:28:16 +0200
commit5de3cf4ef49b9a66866bd8bd0cdcfaaf767577c9 (patch)
tree18aff7ae941d9716f51eb0fcaa3091c985f0aca9 /src/counter.c
parent14236b2a2b6121963d1fc1e1eead753a380498f2 (diff)
downloadconnman-5de3cf4ef49b9a66866bd8bd0cdcfaaf767577c9.tar.gz
connman-5de3cf4ef49b9a66866bd8bd0cdcfaaf767577c9.tar.bz2
connman-5de3cf4ef49b9a66866bd8bd0cdcfaaf767577c9.zip
Update service statistics
Instead of collecting statistics on interface name base and storing it local in counter.c, update the Service object. counter.c maps interface names to Service objects. The assumption is made that there is a 1:1 mapping between Service objects and interface name. A Counter object will only show Service object statistics for services in the ready state. There is no interface (yet) for retrieving information on Service objects in idle/failure/configuration/.. state.
Diffstat (limited to 'src/counter.c')
-rw-r--r--src/counter.c88
1 files changed, 45 insertions, 43 deletions
diff --git a/src/counter.c b/src/counter.c
index bf9da902..f290179f 100644
--- a/src/counter.c
+++ b/src/counter.c
@@ -33,12 +33,6 @@ static GHashTable *stats_table;
static GHashTable *counter_table;
static GHashTable *owner_mapping;
-struct connman_stats {
- char *interface;
- unsigned int rx_bytes;
- unsigned int tx_bytes;
-};
-
struct connman_counter {
char *owner;
char *path;
@@ -46,14 +40,6 @@ struct connman_counter {
guint watch;
};
-static void remove_stats(gpointer user_data)
-{
- struct connman_stats *stats = user_data;
-
- g_free(stats->interface);
- g_free(stats);
-}
-
static void remove_counter(gpointer user_data)
{
struct connman_counter *counter = user_data;
@@ -130,10 +116,14 @@ int __connman_counter_unregister(const char *owner, const char *path)
}
static void send_usage(struct connman_counter *counter,
- struct connman_stats *stats)
+ struct connman_service *service)
{
DBusMessage *message;
DBusMessageIter array, dict;
+ const char *service_path;
+ unsigned long rx_bytes;
+ unsigned long tx_bytes;
+ unsigned long time;
message = dbus_message_new_method_call(counter->owner, counter->path,
CONNMAN_COUNTER_INTERFACE, "Usage");
@@ -142,54 +132,48 @@ static void send_usage(struct connman_counter *counter,
dbus_message_set_no_reply(message, TRUE);
+ service_path = __connman_service_get_path(service);
+ dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
+ &service_path, DBUS_TYPE_INVALID);
+
dbus_message_iter_init_append(message, &array);
connman_dbus_dict_open(&array, &dict);
- connman_dbus_dict_append_basic(&dict, "Interface",
- DBUS_TYPE_STRING, &stats->interface);
- connman_dbus_dict_append_basic(&dict, "RX.Bytes",
- DBUS_TYPE_UINT32, &stats->rx_bytes);
- connman_dbus_dict_append_basic(&dict, "TX.Bytes",
- DBUS_TYPE_UINT32, &stats->tx_bytes);
+ rx_bytes = __connman_service_stats_get_rx_bytes(service);
+ tx_bytes = __connman_service_stats_get_tx_bytes(service);
+ time = __connman_service_stats_get_time(service);
+
+ connman_dbus_dict_append_basic(&dict, "RX.Bytes", DBUS_TYPE_UINT32,
+ &rx_bytes);
+ connman_dbus_dict_append_basic(&dict, "TX.Bytes", DBUS_TYPE_UINT32,
+ &tx_bytes);
+ connman_dbus_dict_append_basic(&dict, "Time", DBUS_TYPE_UINT32,
+ &time);
connman_dbus_dict_close(&array, &dict);
g_dbus_send_message(connection, message);
}
-void __connman_counter_notify(const char *interface,
+void __connman_counter_notify(struct connman_ipconfig *config,
unsigned int rx_bytes, unsigned int tx_bytes)
{
- struct connman_stats *stats;
+ struct connman_service *service;
GHashTableIter iter;
gpointer key, value;
- stats = g_hash_table_lookup(stats_table, interface);
- if (stats != NULL)
- goto update;
-
- stats = g_try_new0(struct connman_stats, 1);
- if (stats == NULL)
- return;
-
- stats->interface = g_strdup(interface);
-
- g_hash_table_replace(stats_table, stats->interface, stats);
-
-update:
- if (stats->rx_bytes == rx_bytes && stats->tx_bytes == tx_bytes)
+ service = g_hash_table_lookup(stats_table, config);
+ if (service == NULL)
return;
- stats->rx_bytes = rx_bytes;
- stats->tx_bytes = tx_bytes;
+ __connman_service_stats_update(service, rx_bytes, tx_bytes);
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, stats);
+ send_usage(counter, service);
}
}
@@ -210,6 +194,24 @@ static void release_counter(gpointer key, gpointer value, gpointer user_data)
g_dbus_send_message(connection, message);
}
+int __connman_counter_add_service(struct connman_service *service)
+{
+ struct connman_ipconfig *config;
+
+ config = __connman_service_get_ipconfig(service);
+ g_hash_table_replace(stats_table, config, service);
+
+ return 0;
+}
+
+void __connman_counter_remove_service(struct connman_service *service)
+{
+ struct connman_ipconfig *config;
+
+ config = __connman_service_get_ipconfig(service);
+ g_hash_table_remove(stats_table, config);
+}
+
int __connman_counter_init(void)
{
DBG("");
@@ -218,8 +220,8 @@ int __connman_counter_init(void)
if (connection == NULL)
return -1;
- stats_table = g_hash_table_new_full(g_str_hash, g_str_equal,
- NULL, remove_stats);
+ stats_table = g_hash_table_new_full(g_direct_hash, g_str_equal,
+ NULL, NULL);
counter_table = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, remove_counter);