mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-06 13:48:18 +02:00
trivial: add a resolution parameter to GetHistory rather than just guessing a number on the server
This commit is contained in:
parent
ba8eecf2b4
commit
7382bcc168
8 changed files with 32 additions and 16 deletions
|
|
@ -206,7 +206,7 @@ dkp_client_device_print_history (const DkpClientDevice *device, const gchar *typ
|
|||
gboolean ret = FALSE;
|
||||
|
||||
/* get a fair chunk of data */
|
||||
array = dkp_client_device_get_history (device, type, 120);
|
||||
array = dkp_client_device_get_history (device, type, 120, 10);
|
||||
if (array == NULL)
|
||||
goto out;
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ out:
|
|||
* Returns an array of %DkpHistoryObj's
|
||||
**/
|
||||
EggObjList *
|
||||
dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type, guint timespec)
|
||||
dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type, guint timespec, guint resolution)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GType g_type_gvalue_array;
|
||||
|
|
@ -283,6 +283,7 @@ dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type,
|
|||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
|
||||
|
||||
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
|
||||
dbus_g_type_get_struct("GValueArray",
|
||||
|
|
@ -295,6 +296,7 @@ dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type,
|
|||
ret = dbus_g_proxy_call (device->priv->proxy_device, "GetHistory", &error,
|
||||
G_TYPE_STRING, type,
|
||||
G_TYPE_UINT, timespec,
|
||||
G_TYPE_UINT, resolution,
|
||||
G_TYPE_INVALID,
|
||||
g_type_gvalue_array, &gvalue_ptr_array,
|
||||
G_TYPE_INVALID);
|
||||
|
|
@ -359,6 +361,7 @@ dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *ty
|
|||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
|
||||
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
|
||||
|
||||
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
|
||||
dbus_g_type_get_struct("GValueArray",
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ gboolean dkp_client_device_print (const DkpClientDevice *device);
|
|||
gboolean dkp_client_device_refresh (DkpClientDevice *device);
|
||||
EggObjList *dkp_client_device_get_history (const DkpClientDevice *device,
|
||||
const gchar *type,
|
||||
guint timespec);
|
||||
guint timespec,
|
||||
guint resolution);
|
||||
EggObjList *dkp_client_device_get_statistics (const DkpClientDevice *device,
|
||||
const gchar *type);
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ egg_obj_list_clear (EggObjList *list)
|
|||
|
||||
array = list->priv->array;
|
||||
func_free = list->priv->func_free;
|
||||
|
||||
if (func_free != NULL)
|
||||
g_ptr_array_foreach (array, (GFunc) func_free, NULL);
|
||||
g_ptr_array_remove_range (array, 0, array->len);
|
||||
|
|
|
|||
|
|
@ -396,7 +396,7 @@ out:
|
|||
* dkp_device_get_history:
|
||||
**/
|
||||
gboolean
|
||||
dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint timespan, DBusGMethodInvocation *context)
|
||||
dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint timespan, guint resolution, DBusGMethodInvocation *context)
|
||||
{
|
||||
GError *error;
|
||||
EggObjList *array = NULL;
|
||||
|
|
@ -428,7 +428,7 @@ dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint times
|
|||
|
||||
/* something recognised */
|
||||
if (type != DKP_HISTORY_TYPE_UNKNOWN)
|
||||
array = dkp_history_get_data (device->priv->history, type, timespan);
|
||||
array = dkp_history_get_data (device->priv->history, type, timespan, resolution);
|
||||
|
||||
/* maybe the device doesn't have any history */
|
||||
if (array == NULL) {
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ gboolean dkp_device_refresh (DkpDevice *device,
|
|||
gboolean dkp_device_get_history (DkpDevice *device,
|
||||
const gchar *type,
|
||||
guint timespan,
|
||||
guint resolution,
|
||||
DBusGMethodInvocation *context);
|
||||
gboolean dkp_device_get_statistics (DkpDevice *device,
|
||||
const gchar *type,
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ static void dkp_history_finalize (GObject *object);
|
|||
#define DKP_HISTORY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_HISTORY, DkpHistoryPrivate))
|
||||
|
||||
#define DKP_HISTORY_SAVE_INTERVAL 5 /* seconds */
|
||||
#define DKP_HISTORY_MAX_RESOLUTION 150
|
||||
|
||||
struct DkpHistoryPrivate
|
||||
{
|
||||
|
|
@ -207,7 +206,6 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
|
|||
guint i;
|
||||
const DkpHistoryObj *obj;
|
||||
EggObjList *array_new;
|
||||
EggObjList *array_resolution;
|
||||
guint start;
|
||||
|
||||
/* no data */
|
||||
|
|
@ -227,20 +225,17 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
|
|||
egg_obj_list_add (array_new, (const gpointer) obj);
|
||||
}
|
||||
|
||||
/* only add a certain number of points */
|
||||
array_resolution = dkp_history_array_limit_resolution (array_new, DKP_HISTORY_MAX_RESOLUTION);
|
||||
g_object_unref (array_new);
|
||||
|
||||
return array_resolution;
|
||||
return array_new;
|
||||
}
|
||||
|
||||
/**
|
||||
* dkp_history_get_data:
|
||||
**/
|
||||
EggObjList *
|
||||
dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan)
|
||||
dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan, guint resolution)
|
||||
{
|
||||
EggObjList *array;
|
||||
EggObjList *array_resolution;
|
||||
const EggObjList *array_data = NULL;
|
||||
|
||||
g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
|
||||
|
|
@ -261,8 +256,16 @@ dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan)
|
|||
if (array_data == NULL)
|
||||
return NULL;
|
||||
|
||||
/* only return a certain time */
|
||||
array = dkp_history_copy_array_timespan (array_data, timespan);
|
||||
return array;
|
||||
if (array == NULL)
|
||||
return NULL;
|
||||
|
||||
/* only add a certain number of points */
|
||||
array_resolution = dkp_history_array_limit_resolution (array, resolution);
|
||||
g_object_unref (array);
|
||||
|
||||
return array_resolution;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -64,7 +64,8 @@ GType dkp_history_get_type (void) G_GNUC_CONST;
|
|||
DkpHistory *dkp_history_new (void);
|
||||
EggObjList *dkp_history_get_data (DkpHistory *history,
|
||||
DkpHistoryType type,
|
||||
guint timespan);
|
||||
guint timespan,
|
||||
guint resolution);
|
||||
EggObjList *dkp_history_get_profile_data (DkpHistory *history,
|
||||
gboolean charging);
|
||||
gboolean dkp_history_set_id (DkpHistory *history,
|
||||
|
|
|
|||
|
|
@ -58,6 +58,14 @@
|
|||
<arg name="timespan" direction="in" type="u">
|
||||
<doc:doc><doc:summary>The amount of data to return in seconds, or 0 for all.</doc:summary></doc:doc>
|
||||
</arg>
|
||||
<arg name="resolution" direction="in" type="u">
|
||||
<doc:doc>
|
||||
<doc:summary>
|
||||
The approximate number of points to return.
|
||||
A higher resolution is more accurate, at the expense of plotting speed.
|
||||
</doc:summary>
|
||||
</doc:doc>
|
||||
</arg>
|
||||
<arg name="data" direction="out" type="a(uds)">
|
||||
<doc:doc><doc:summary>
|
||||
The history data for the power device, if the device supports history.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue