summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-11-08 16:13:00 +0000
committerRichard Hughes <richard@hughsie.com>2008-11-08 16:13:00 +0000
commit7382bcc1686bce63ad3b7a5c3770ebc6c90802fe (patch)
treece87752f68a41d09b3900f3027a78fe9a016a416
parentba8eecf2b454f266561970209eeda9b71fdc33f7 (diff)
trivial: add a resolution parameter to GetHistory rather than just guessing a number on the server
-rw-r--r--libdevkit-power/dkp-client-device.c7
-rw-r--r--libdevkit-power/dkp-client-device.h3
-rw-r--r--libdevkit-power/egg-obj-list.c1
-rw-r--r--src/dkp-device.c4
-rw-r--r--src/dkp-device.h1
-rw-r--r--src/dkp-history.c21
-rw-r--r--src/dkp-history.h3
-rw-r--r--src/org.freedesktop.DeviceKit.Power.Device.xml8
8 files changed, 32 insertions, 16 deletions
diff --git a/libdevkit-power/dkp-client-device.c b/libdevkit-power/dkp-client-device.c
index ab0512d..dc25fc5 100644
--- a/libdevkit-power/dkp-client-device.c
+++ b/libdevkit-power/dkp-client-device.c
@@ -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",
diff --git a/libdevkit-power/dkp-client-device.h b/libdevkit-power/dkp-client-device.h
index 9903fc2..a0d88d2 100644
--- a/libdevkit-power/dkp-client-device.h
+++ b/libdevkit-power/dkp-client-device.h
@@ -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);
diff --git a/libdevkit-power/egg-obj-list.c b/libdevkit-power/egg-obj-list.c
index d0a255e..6e3fd25 100644
--- a/libdevkit-power/egg-obj-list.c
+++ b/libdevkit-power/egg-obj-list.c
@@ -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);
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 @@
<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.