+static void __connman_service_stats_start(struct connman_service *service)
+{
+ DBG("service %p", service);
+
+ if (service->stats.timer == NULL)
+ return;
+
+ service->stats.time_start = service->stats.time;
+
+ g_timer_start(service->stats.timer);
+}
+
+static void __connman_service_stats_stop(struct connman_service *service)
+{
+ unsigned int seconds;
+
+ DBG("service %p", service);
+
+ if (service->stats.timer == NULL)
+ return;
+
+ g_timer_stop(service->stats.timer);
+
+ seconds = g_timer_elapsed(service->stats.timer, NULL);
+ service->stats.time = service->stats.time_start + seconds;
+}
+
+static int __connman_service_stats_load(struct connman_service *service,
+ GKeyFile *keyfile, const char *identifier)
+{
+ service->stats.rx_bytes = g_key_file_get_integer(keyfile,
+ identifier, "rx_bytes", NULL);
+ service->stats.tx_bytes = g_key_file_get_integer(keyfile,
+ identifier, "tx_bytes", NULL);
+ service->stats.time = g_key_file_get_integer(keyfile,
+ identifier, "time", NULL);
+
+ return 0;
+}
+
+static int __connman_service_stats_save(struct connman_service *service,
+ GKeyFile *keyfile, const char *identifier)
+{
+ g_key_file_set_integer(keyfile, identifier, "rx_bytes",
+ service->stats.rx_bytes);
+ g_key_file_set_integer(keyfile, identifier, "tx_bytes",
+ service->stats.tx_bytes);
+ g_key_file_set_integer(keyfile, identifier, "time",
+ service->stats.time);
+
+ return 0;
+}
+
+static void __connman_service_reset_stats(struct connman_service *service)
+{
+ DBG("service %p", service);
+
+ service->stats.valid = FALSE;
+ service->stats.rx_bytes = 0;
+ service->stats.tx_bytes = 0;
+ service->stats.time = 0;
+ service->stats.time_start = 0;
+ g_timer_reset(service->stats.timer);
+
+}
+
+unsigned long __connman_service_stats_get_tx_bytes(struct connman_service *service)
+{
+ return service->stats.tx_bytes;
+}
+
+unsigned long __connman_service_stats_get_rx_bytes(struct connman_service *service)
+{
+ return service->stats.rx_bytes;
+}
+
+unsigned long __connman_service_stats_get_time(struct connman_service *service)
+{
+ return service->stats.time;
+}
+