actually print the stats when we call dkp_client_device_print()

This commit is contained in:
Richard Hughes 2008-08-11 13:26:45 +01:00
parent f776b73d8d
commit c9d3c59ad3
2 changed files with 32 additions and 5 deletions

View file

@ -191,6 +191,35 @@ dkp_client_device_get_object (const DkpClientDevice *device)
return device->priv->obj;
}
/**
* dkp_client_device_print_stats:
**/
static gboolean
dkp_client_device_print_stats (const DkpClientDevice *device, const gchar *type)
{
guint i;
GPtrArray *array;
DkpHistoryObj *obj;
gboolean ret = FALSE;
/* get a fair chunk of data */
array = dkp_client_device_get_statistics (device, type, 120);
if (array == NULL)
goto out;
/* pretty print */
g_print (" Statistics (%s):\n", type);
for (i=0; i<array->len; i++) {
obj = (DkpHistoryObj *) g_ptr_array_index (array, i);
g_print (" %i\t%.3f\t%s\n", obj->time, obj->value, dkp_device_state_to_text (obj->state));
}
g_ptr_array_foreach (array, (GFunc) dkp_history_obj_free, NULL);
g_ptr_array_free (array, TRUE);
ret = TRUE;
out:
return ret;
}
/**
* dkp_client_device_print:
**/
@ -203,8 +232,9 @@ dkp_client_device_print (const DkpClientDevice *device)
dkp_object_print (device->priv->obj);
/* if we can, get stats */
dkp_client_device_get_statistics (device, "charge", 120);
dkp_client_device_get_statistics (device, "rate", 120);
dkp_client_device_print_stats (device, "charge");
dkp_client_device_print_stats (device, "rate");
return TRUE;
}

View file

@ -285,9 +285,7 @@ dkp_object_print (const DkpObject *obj)
g_print (" power supply: %s\n", dkp_object_bool_to_text (obj->power_supply));
g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - obj->update_time));
g_print (" %s\n", dkp_device_type_to_text (obj->type));
if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
g_print (" battery\n");
g_print (" present: %s\n", dkp_object_bool_to_text (obj->battery_is_present));
g_print (" rechargeable: %s\n", dkp_object_bool_to_text (obj->battery_is_rechargeable));
g_print (" state: %s\n", dkp_device_state_to_text (obj->battery_state));
@ -310,7 +308,6 @@ dkp_object_print (const DkpObject *obj)
g_print (" capacity: %g%%\n", obj->battery_capacity);
g_print (" technology: %s\n", dkp_device_technology_to_text (obj->battery_technology));
} else if (obj->type == DKP_DEVICE_TYPE_LINE_POWER) {
g_print (" line-power\n");
g_print (" online: %s\n", dkp_object_bool_to_text (obj->line_power_online));
} else if (obj->type == DKP_DEVICE_TYPE_MOUSE || obj->type == DKP_DEVICE_TYPE_KEYBOARD) {
g_print (" present: %s\n", dkp_object_bool_to_text (obj->battery_is_present));