mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-01-07 00:30:11 +01:00
feature: add two new properties, has-history and has-statistics
This commit is contained in:
parent
ffbc3a026b
commit
b43fa536fb
8 changed files with 57 additions and 4 deletions
|
|
@ -387,6 +387,8 @@ dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *ty
|
|||
array = egg_obj_list_new ();
|
||||
egg_obj_list_set_copy (array, (EggObjListCopyFunc) dkp_stats_obj_copy);
|
||||
egg_obj_list_set_free (array, (EggObjListFreeFunc) dkp_stats_obj_free);
|
||||
egg_obj_list_set_to_string (array, (EggObjListToStringFunc) dkp_stats_obj_to_string);
|
||||
egg_obj_list_set_from_string (array, (EggObjListFromStringFunc) dkp_stats_obj_from_string);
|
||||
|
||||
for (i=0; i<gvalue_ptr_array->len; i++) {
|
||||
gva = (GValueArray *) g_ptr_array_index (gvalue_ptr_array, i);
|
||||
|
|
@ -404,7 +406,6 @@ dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *ty
|
|||
dkp_stats_obj_free (obj);
|
||||
g_value_array_free (gva);
|
||||
}
|
||||
|
||||
out:
|
||||
if (gvalue_ptr_array != NULL)
|
||||
g_ptr_array_free (gvalue_ptr_array, TRUE);
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ dkp_object_clear_internal (DkpObject *obj)
|
|||
obj->is_present = FALSE;
|
||||
obj->power_supply = FALSE;
|
||||
obj->is_rechargeable = FALSE;
|
||||
obj->has_history = FALSE;
|
||||
obj->has_statistics = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,6 +80,10 @@ dkp_object_collect_props (const char *key, const GValue *value, DkpObject *obj)
|
|||
obj->type = dkp_device_type_from_text (g_value_get_string (value));
|
||||
else if (egg_strequal (key, "online"))
|
||||
obj->online = g_value_get_boolean (value);
|
||||
else if (egg_strequal (key, "has-history"))
|
||||
obj->has_history = g_value_get_boolean (value);
|
||||
else if (egg_strequal (key, "has-statistics"))
|
||||
obj->has_statistics = g_value_get_boolean (value);
|
||||
else if (egg_strequal (key, "energy"))
|
||||
obj->energy = g_value_get_double (value);
|
||||
else if (egg_strequal (key, "energy-empty"))
|
||||
|
|
@ -152,6 +158,8 @@ dkp_object_copy (const DkpObject *cobj)
|
|||
obj->is_present = cobj->is_present;
|
||||
obj->power_supply = cobj->power_supply;
|
||||
obj->is_rechargeable = cobj->is_rechargeable;
|
||||
obj->has_history = cobj->has_history;
|
||||
obj->has_statistics = cobj->has_statistics;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
|
@ -169,6 +177,8 @@ dkp_object_equal (const DkpObject *obj1, const DkpObject *obj2)
|
|||
obj1->energy_full_design == obj2->energy_full_design &&
|
||||
obj1->energy_rate == obj2->energy_rate &&
|
||||
obj1->percentage == obj2->percentage &&
|
||||
obj1->has_history == obj2->has_history &&
|
||||
obj1->has_statistics == obj2->has_statistics &&
|
||||
obj1->capacity == obj2->capacity &&
|
||||
obj1->time_to_empty == obj2->time_to_empty &&
|
||||
obj1->time_to_full == obj2->time_to_full &&
|
||||
|
|
@ -243,6 +253,8 @@ dkp_object_print (const DkpObject *obj)
|
|||
g_print (" serial: %s\n", obj->serial);
|
||||
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 (" has history: %s\n", dkp_object_bool_to_text (obj->has_history));
|
||||
g_print (" has statistics: %s\n", dkp_object_bool_to_text (obj->has_statistics));
|
||||
g_print (" %s\n", dkp_device_type_to_text (obj->type));
|
||||
|
||||
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
|
||||
|
|
@ -311,6 +323,14 @@ dkp_object_diff (const DkpObject *old, const DkpObject *obj)
|
|||
g_print (" model: %s -> %s\n", old->model, obj->model);
|
||||
if (!egg_strequal (obj->serial, old->serial))
|
||||
g_print (" serial: %s -> %s\n", old->serial, obj->serial);
|
||||
if (obj->has_history != old->has_history)
|
||||
g_print (" has history: %s -> %s\n",
|
||||
dkp_object_bool_to_text (old->has_history),
|
||||
dkp_object_bool_to_text (obj->has_history));
|
||||
if (obj->has_statistics != old->has_statistics)
|
||||
g_print (" has statistics: %s -> %s\n",
|
||||
dkp_object_bool_to_text (old->has_statistics),
|
||||
dkp_object_bool_to_text (obj->has_statistics));
|
||||
|
||||
g_print (" %s\n", dkp_device_type_to_text (obj->type));
|
||||
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ typedef struct {
|
|||
gboolean online;
|
||||
gboolean is_present;
|
||||
gboolean is_rechargeable;
|
||||
gboolean has_history;
|
||||
gboolean has_statistics;
|
||||
DkpDeviceType type;
|
||||
DkpDeviceState state;
|
||||
DkpDeviceTechnology technology;
|
||||
|
|
|
|||
|
|
@ -68,12 +68,12 @@ dkp_stats_obj_free (DkpStatsObj *obj)
|
|||
* dkp_stats_obj_create:
|
||||
**/
|
||||
DkpStatsObj *
|
||||
dkp_stats_obj_create (gdouble value, gdouble state)
|
||||
dkp_stats_obj_create (gdouble value, gdouble accuracy)
|
||||
{
|
||||
DkpStatsObj *obj;
|
||||
obj = dkp_stats_obj_new ();
|
||||
obj->value = value;
|
||||
obj->accuracy = state;
|
||||
obj->accuracy = accuracy;
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ DkpStatsObj *dkp_stats_obj_new (void);
|
|||
gboolean dkp_stats_obj_free (DkpStatsObj *obj);
|
||||
DkpStatsObj *dkp_stats_obj_copy (const DkpStatsObj *cobj);
|
||||
DkpStatsObj *dkp_stats_obj_create (gdouble value,
|
||||
gdouble state);
|
||||
gdouble accuracy);
|
||||
DkpStatsObj *dkp_stats_obj_from_string (const gchar *text);
|
||||
gchar *dkp_stats_obj_to_string (const DkpStatsObj *obj);
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ enum
|
|||
PROP_BATTERY_CAPACITY,
|
||||
PROP_BATTERY_IS_PRESENT,
|
||||
PROP_BATTERY_IS_RECHARGEABLE,
|
||||
PROP_BATTERY_HAS_HISTORY,
|
||||
PROP_BATTERY_HAS_STATISTICS,
|
||||
PROP_BATTERY_STATE,
|
||||
PROP_BATTERY_ENERGY,
|
||||
PROP_BATTERY_ENERGY_EMPTY,
|
||||
|
|
@ -181,6 +183,12 @@ dkp_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
|
|||
case PROP_BATTERY_IS_RECHARGEABLE:
|
||||
g_value_set_boolean (value, obj->is_rechargeable);
|
||||
break;
|
||||
case PROP_BATTERY_HAS_HISTORY:
|
||||
g_value_set_boolean (value, obj->has_history);
|
||||
break;
|
||||
case PROP_BATTERY_HAS_STATISTICS:
|
||||
g_value_set_boolean (value, obj->has_statistics);
|
||||
break;
|
||||
case PROP_BATTERY_STATE:
|
||||
g_value_set_string (value, dkp_device_state_to_text (obj->state));
|
||||
break;
|
||||
|
|
@ -698,6 +706,14 @@ dkp_device_class_init (DkpDeviceClass *klass)
|
|||
object_class,
|
||||
PROP_BATTERY_IS_RECHARGEABLE,
|
||||
g_param_spec_boolean ("is-rechargeable", NULL, NULL, FALSE, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_HAS_HISTORY,
|
||||
g_param_spec_boolean ("has-history", NULL, NULL, FALSE, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_HAS_STATISTICS,
|
||||
g_param_spec_boolean ("has-statistics", NULL, NULL, FALSE, G_PARAM_READABLE));
|
||||
g_object_class_install_property (
|
||||
object_class,
|
||||
PROP_BATTERY_STATE,
|
||||
|
|
|
|||
|
|
@ -229,6 +229,8 @@ dkp_supply_refresh_battery (DkpSupply *supply)
|
|||
|
||||
/* assume true for laptops */
|
||||
obj->is_rechargeable = TRUE;
|
||||
obj->has_history = TRUE;
|
||||
obj->has_statistics = TRUE;
|
||||
|
||||
/* these don't change at runtime */
|
||||
obj->energy_full =
|
||||
|
|
|
|||
|
|
@ -182,6 +182,18 @@
|
|||
</doc:para></doc:description></doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="has-history" type="b" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
If the power device has history.
|
||||
</doc:para></doc:description></doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="has-statistics" type="b" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
If the power device has statistics.
|
||||
</doc:para></doc:description></doc:doc>
|
||||
</property>
|
||||
|
||||
<property name="online" type="b" access="read">
|
||||
<doc:doc><doc:description><doc:para>
|
||||
Whether power is currently being provided through line power.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue