From 7382bcc1686bce63ad3b7a5c3770ebc6c90802fe Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sat, 8 Nov 2008 16:13:00 +0000 Subject: trivial: add a resolution parameter to GetHistory rather than just guessing a number on the server --- src/dkp-device.c | 4 ++-- src/dkp-device.h | 1 + src/dkp-history.c | 21 ++++++++++++--------- src/dkp-history.h | 3 ++- src/org.freedesktop.DeviceKit.Power.Device.xml | 8 ++++++++ 5 files changed, 25 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/dkp-device.c b/src/dkp-device.c index 5aafbd2..bd46221 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -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) { diff --git a/src/dkp-device.h b/src/dkp-device.h index d4d1d12..5af4d97 100644 --- a/src/dkp-device.h +++ b/src/dkp-device.h @@ -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, diff --git a/src/dkp-history.c b/src/dkp-history.c index 05ffcb8..1e556c7 100644 --- a/src/dkp-history.c +++ b/src/dkp-history.c @@ -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; } /** diff --git a/src/dkp-history.h b/src/dkp-history.h index 9b7ba62..72a9399 100644 --- a/src/dkp-history.h +++ b/src/dkp-history.h @@ -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, diff --git a/src/org.freedesktop.DeviceKit.Power.Device.xml b/src/org.freedesktop.DeviceKit.Power.Device.xml index a2d2c16..8148665 100644 --- a/src/org.freedesktop.DeviceKit.Power.Device.xml +++ b/src/org.freedesktop.DeviceKit.Power.Device.xml @@ -58,6 +58,14 @@ The amount of data to return in seconds, or 0 for all. + + + + The approximate number of points to return. + A higher resolution is more accurate, at the expense of plotting speed. + + + The history data for the power device, if the device supports history. -- cgit v1.2.3