summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-26 16:43:30 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-26 16:43:30 +0100
commitb53b7dadcf8856b5a4c3331e85207f7c0a2417e0 (patch)
treea3b2f3137d470eb23951830a883782a4767a8060 /src
parentcb9d4e69751fd1ce1351cb270608f7b58028d2b5 (diff)
don't return stats when we actually mean history -- the stats parts need to be written
Diffstat (limited to 'src')
-rw-r--r--src/dkp-device.c65
-rw-r--r--src/dkp-device.h9
-rw-r--r--src/dkp-supply.c6
-rw-r--r--src/org.freedesktop.DeviceKit.Power.Device.xml22
4 files changed, 77 insertions, 25 deletions
diff --git a/src/dkp-device.c b/src/dkp-device.c
index 8b36655..3dc27d8 100644
--- a/src/dkp-device.c
+++ b/src/dkp-device.c
@@ -40,6 +40,7 @@
#include "dkp-device.h"
#include "dkp-device.h"
#include "dkp-history-obj.h"
+#include "dkp-stats-obj.h"
#include "dkp-marshal.h"
#include "dkp-device-glue.h"
@@ -97,6 +98,8 @@ G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT)
#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_DEVICE, DkpDevicePrivate))
#define DKP_DBUS_STRUCT_UINT_DOUBLE_STRING (dbus_g_type_get_struct ("GValueArray", \
G_TYPE_UINT, G_TYPE_DOUBLE, G_TYPE_STRING, G_TYPE_INVALID))
+#define DKP_DBUS_STRUCT_DOUBLE_DOUBLE (dbus_g_type_get_struct ("GValueArray", \
+ G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_INVALID))
/**
* dkp_device_error_quark:
@@ -241,7 +244,7 @@ dkp_device_get_on_battery (DkpDevice *device, gboolean *on_battery)
g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
/* no support */
- if (klass->get_stats == NULL)
+ if (klass->get_on_battery == NULL)
return FALSE;
return klass->get_on_battery (device, on_battery);
@@ -308,7 +311,63 @@ out:
* dkp_device_get_statistics:
**/
gboolean
-dkp_device_get_statistics (DkpDevice *device, const gchar *type, guint timespan, DBusGMethodInvocation *context)
+dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvocation *context)
+{
+ DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
+ GError *error;
+ GPtrArray *array;
+ GPtrArray *complex;
+ const DkpStatsObj *obj;
+ GValue *value;
+ guint i;
+
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
+
+ /* doesn't even try to support this */
+ if (klass->get_stats == NULL) {
+ error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device does not support getting stats");
+ dbus_g_method_return_error (context, error);
+ goto out;
+ }
+
+ array = klass->get_stats (device, type);
+ /* maybe the device doesn't support histories */
+ if (array == NULL) {
+ error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device has no statistics");
+ dbus_g_method_return_error (context, error);
+ goto out;
+ }
+
+ /* always 100 items of data */
+ if (array->len != 100) {
+ error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "statistics invalid");
+ dbus_g_method_return_error (context, error);
+ goto out;
+ }
+
+ /* copy data to dbus struct */
+ complex = g_ptr_array_sized_new (array->len);
+ for (i=0; i<array->len; i++) {
+ obj = (const DkpStatsObj *) g_ptr_array_index (array, i);
+ value = g_new0 (GValue, 1);
+ g_value_init (value, DKP_DBUS_STRUCT_DOUBLE_DOUBLE);
+ g_value_take_boxed (value, dbus_g_type_specialized_construct (DKP_DBUS_STRUCT_DOUBLE_DOUBLE));
+ dbus_g_type_struct_set (value, 0, obj->value, 1, obj->accuracy, -1);
+ g_ptr_array_add (complex, g_value_get_boxed (value));
+ g_free (value);
+ }
+
+ g_ptr_array_free (array, TRUE);
+ dbus_g_method_return (context, complex);
+out:
+ return TRUE;
+}
+
+/**
+ * dkp_device_get_history:
+ **/
+gboolean
+dkp_device_get_history (DkpDevice *device, const gchar *type, guint timespan, DBusGMethodInvocation *context)
{
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
GError *error;
@@ -327,7 +386,7 @@ dkp_device_get_statistics (DkpDevice *device, const gchar *type, guint timespan,
goto out;
}
- array = klass->get_stats (device, type, timespan);
+ array = klass->get_history (device, type, timespan);
/* maybe the device doesn't support histories */
if (array == NULL) {
error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, "device has no history");
diff --git a/src/dkp-device.h b/src/dkp-device.h
index 9724948..fa9f356 100644
--- a/src/dkp-device.h
+++ b/src/dkp-device.h
@@ -59,9 +59,11 @@ typedef struct
gboolean *on_battery);
gboolean (*get_low_battery) (DkpDevice *device,
gboolean *low_battery);
- GPtrArray *(*get_stats) (DkpDevice *device,
+ GPtrArray *(*get_history) (DkpDevice *device,
const gchar *type,
guint timespan);
+ GPtrArray *(*get_stats) (DkpDevice *device,
+ const gchar *type);
} DkpDeviceClass;
typedef enum
@@ -95,10 +97,13 @@ void dkp_device_emit_changed (DkpDevice *device);
/* exported methods */
gboolean dkp_device_refresh (DkpDevice *device,
DBusGMethodInvocation *context);
-gboolean dkp_device_get_statistics (DkpDevice *device,
+gboolean dkp_device_get_history (DkpDevice *device,
const gchar *type,
guint timespan,
DBusGMethodInvocation *context);
+gboolean dkp_device_get_statistics (DkpDevice *device,
+ const gchar *type,
+ DBusGMethodInvocation *context);
G_END_DECLS
diff --git a/src/dkp-supply.c b/src/dkp-supply.c
index a2760ad..a7f9d31 100644
--- a/src/dkp-supply.c
+++ b/src/dkp-supply.c
@@ -355,10 +355,10 @@ dkp_supply_poll_battery (DkpSupply *supply)
}
/**
- * dkp_supply_get_stats:
+ * dkp_supply_get_history:
**/
static GPtrArray *
-dkp_supply_get_stats (DkpDevice *device, const gchar *type, guint timespan)
+dkp_supply_get_history (DkpDevice *device, const gchar *type, guint timespan)
{
DkpSupply *supply = DKP_SUPPLY (device);
GPtrArray *array = NULL;
@@ -503,7 +503,7 @@ dkp_supply_class_init (DkpSupplyClass *klass)
device_class->get_low_battery = dkp_supply_get_low_battery;
device_class->coldplug = dkp_supply_coldplug;
device_class->refresh = dkp_supply_refresh;
- device_class->get_stats = dkp_supply_get_stats;
+ device_class->get_history = dkp_supply_get_history;
g_type_class_add_private (klass, sizeof (DkpSupplyPrivate));
}
diff --git a/src/org.freedesktop.DeviceKit.Power.Device.xml b/src/org.freedesktop.DeviceKit.Power.Device.xml
index 7060aca..d08ebde 100644
--- a/src/org.freedesktop.DeviceKit.Power.Device.xml
+++ b/src/org.freedesktop.DeviceKit.Power.Device.xml
@@ -89,8 +89,7 @@
<doc:doc>
<doc:description>
<doc:para>
- Gets statistics for the power device that may be interesting
- to show on a graph in the session.
+ Gets history for the power device that is persistent across reboots.
</doc:para>
</doc:description>
</doc:doc>
@@ -100,35 +99,24 @@
<method name="GetStatistics">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="type" direction="in" type="s">
- <doc:doc><doc:summary>The type of statistics.
- Valid types are <literal>accuracy</literal> or <literal>time</literal>.</doc:summary></doc:doc>
- </arg>
- <arg name="mode" direction="in" type="s">
<doc:doc><doc:summary>The mode for the statistics.
Valid types are <literal>charging</literal> or <literal>discharging</literal>.</doc:summary></doc:doc>
</arg>
- <arg name="data" direction="out" type="a(uds)">
+ <arg name="data" direction="out" type="a(dd)">
<doc:doc><doc:summary>
The statistics data for the power device.
Each element contains the following members:
<doc:list>
<doc:item>
- <doc:term>time</doc:term>
- <doc:definition>
- The time value in seconds from the <literal>gettimeofday()</literal> method.
- </doc:definition>
- </doc:item>
- <doc:item>
<doc:term>value</doc:term>
<doc:definition>
- The data value, for instance the rate in W or the charge in %.
+ The value of the percentage point, usually in seconds
</doc:definition>
</doc:item>
<doc:item>
- <doc:term>state</doc:term>
+ <doc:term>accuracy</doc:term>
<doc:definition>
- The state of the device, for instance <literal>charging</literal> or
- <literal>discharging</literal>.
+ The accuracy of the prediction in percent.
</doc:definition>
</doc:item>
</doc:list>