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.
cleanup tasks. There is no need to unregister the
counter, because when this method gets called it has
already been unregistered.
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.
int __connman_agent_register(const char *sender, const char *path);
int __connman_agent_unregister(const char *sender, const char *path);
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);
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);
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);
int __connman_counter_init(void);
void __connman_counter_cleanup(void);
typedef void (* passphrase_cb_t) (struct connman_service *service,
const char *passphrase, void *user_data);
typedef void (* passphrase_cb_t) (struct connman_service *service,
const char *passphrase, void *user_data);
static GHashTable *counter_table;
static GHashTable *owner_mapping;
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;
struct connman_counter {
char *owner;
char *path;
-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;
static void remove_counter(gpointer user_data)
{
struct connman_counter *counter = user_data;
}
static void send_usage(struct connman_counter *counter,
}
static void send_usage(struct connman_counter *counter,
- struct connman_stats *stats)
+ struct connman_service *service)
{
DBusMessage *message;
DBusMessageIter array, dict;
{
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");
message = dbus_message_new_method_call(counter->owner, counter->path,
CONNMAN_COUNTER_INTERFACE, "Usage");
dbus_message_set_no_reply(message, TRUE);
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);
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);
}
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)
{
unsigned int rx_bytes, unsigned int tx_bytes)
{
- struct connman_stats *stats;
+ struct connman_service *service;
GHashTableIter iter;
gpointer key, value;
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)
- 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);
g_hash_table_iter_init(&iter, counter_table);
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
struct connman_counter *counter = value;
while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
struct connman_counter *counter = value;
- send_usage(counter, stats);
+ send_usage(counter, service);
g_dbus_send_message(connection, message);
}
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("");
int __connman_counter_init(void)
{
DBG("");
if (connection == NULL)
return -1;
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);
counter_table = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, remove_counter);
ipdevice->rx_bytes = stats->rx_bytes;
ipdevice->tx_bytes = stats->tx_bytes;
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);
}
ipdevice->rx_bytes, ipdevice->tx_bytes);
}
service->stats.time_start = service->stats.time;
g_timer_start(service->stats.timer);
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)
}
static void __connman_service_stats_stop(struct connman_service *service)
if (service->stats.timer == NULL)
return;
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);
g_timer_stop(service->stats.timer);
seconds = g_timer_elapsed(service->stats.timer, NULL);
mainloop.quit()
@dbus.service.method("org.moblin.connman.Counter",
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)
- 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)
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)