diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2010-06-30 19:22:55 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2010-06-30 19:28:16 +0200 |
commit | 5de3cf4ef49b9a66866bd8bd0cdcfaaf767577c9 (patch) | |
tree | 18aff7ae941d9716f51eb0fcaa3091c985f0aca9 | |
parent | 14236b2a2b6121963d1fc1e1eead753a380498f2 (diff) | |
download | connman-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.
-rw-r--r-- | doc/counter-api.txt | 19 | ||||
-rw-r--r-- | src/connman.h | 9 | ||||
-rw-r--r-- | src/counter.c | 88 | ||||
-rw-r--r-- | src/ipconfig.c | 2 | ||||
-rw-r--r-- | src/service.c | 4 | ||||
-rwxr-xr-x | test/test-counter | 12 |
6 files changed, 81 insertions, 53 deletions
diff --git a/doc/counter-api.txt b/doc/counter-api.txt index 593e932d..14e5a010 100644 --- a/doc/counter-api.txt +++ b/doc/counter-api.txt @@ -12,3 +12,22 @@ Methods void Release() cleanup tasks. There is no need to unregister the counter, because when this method gets called it has already been unregistered. + + Usage(object service, dict) + + This signal indicates a change in the counter values + for the service object. The counter is reset by calling + the service ResetCounters method. + + The dict argument contains following entries: + + TX.Bytes + + Total number of bytes sent. + + RX.Bytes + + Total number of bytes received. + + Time + Total number of seconds online. diff --git a/src/connman.h b/src/connman.h index 81eda658..1fdada37 100644 --- a/src/connman.h +++ b/src/connman.h @@ -66,17 +66,22 @@ void __connman_agent_cleanup(void); int __connman_agent_register(const char *sender, const char *path); int __connman_agent_unregister(const char *sender, const char *path); +struct connman_service; +struct connman_ipconfig; + int __connman_counter_register(const char *owner, const char *path, unsigned int interval); int __connman_counter_unregister(const char *owner, const char *path); -void __connman_counter_notify(const char *interface, +void __connman_counter_notify(struct connman_ipconfig *config, unsigned int rx_bytes, unsigned int tx_bytes); +int __connman_counter_add_service(struct connman_service *service); +void __connman_counter_remove_service(struct connman_service *service); + int __connman_counter_init(void); void __connman_counter_cleanup(void); -struct connman_service; typedef void (* passphrase_cb_t) (struct connman_service *service, const char *passphrase, void *user_data); 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); diff --git a/src/ipconfig.c b/src/ipconfig.c index ac26203c..51c4619f 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -367,7 +367,7 @@ static void update_stats(struct connman_ipdevice *ipdevice, ipdevice->rx_bytes = stats->rx_bytes; ipdevice->tx_bytes = stats->tx_bytes; - __connman_counter_notify(ipdevice->ifname, + __connman_counter_notify(ipdevice->config, ipdevice->rx_bytes, ipdevice->tx_bytes); } diff --git a/src/service.c b/src/service.c index ff3e8c86..fd694e80 100644 --- a/src/service.c +++ b/src/service.c @@ -371,6 +371,8 @@ static void __connman_service_stats_start(struct connman_service *service) service->stats.time_start = service->stats.time; g_timer_start(service->stats.timer); + + __connman_counter_add_service(service); } static void __connman_service_stats_stop(struct connman_service *service) @@ -382,6 +384,8 @@ static void __connman_service_stats_stop(struct connman_service *service) if (service->stats.timer == NULL) return; + __connman_counter_remove_service(service); + g_timer_stop(service->stats.timer); seconds = g_timer_elapsed(service->stats.timer, NULL); diff --git a/test/test-counter b/test/test-counter index 70a30273..c32cb9ef 100755 --- a/test/test-counter +++ b/test/test-counter @@ -15,14 +15,12 @@ class Counter(dbus.service.Object): mainloop.quit() @dbus.service.method("org.moblin.connman.Counter", - in_signature='a{sv}', out_signature='') - def Usage(self, stats): + in_signature='oa{sv}', out_signature='') + def Usage(self, path, stats): + print "%s" % (path) for key in stats.keys(): - if key in ["Interface"]: - val = str(stats[key]) - else: - val = int(stats[key]) - print "%s = %s" % (key, val) + val = int(stats[key]) + print " %s = %s" % (key, val) if __name__ == '__main__': dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |