summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-28 10:43:08 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-28 10:43:08 +0100
commit0e2c7ef0ecb7ef924230a4e45c0b75a3937678d7 (patch)
tree8f05b722eee88bd6d2f7aa48b0a3fd23806d330a
parent57ae3ac178d8fc961357328f09bade6b1722aede (diff)
save the time to full and time to empty too
-rw-r--r--src/dkp-history.c120
-rw-r--r--src/dkp-history.h8
-rw-r--r--src/dkp-supply.c6
3 files changed, 134 insertions, 0 deletions
diff --git a/src/dkp-history.c b/src/dkp-history.c
index 7b63f80..5a16ac6 100644
--- a/src/dkp-history.c
+++ b/src/dkp-history.c
@@ -42,10 +42,14 @@ struct DkpHistoryPrivate
{
gchar *id;
gdouble rate_last;
+ gint64 time_full_last;
+ gint64 time_empty_last;
gdouble percentage_last;
DkpDeviceState state;
GPtrArray *data_rate;
GPtrArray *data_charge;
+ GPtrArray *data_time_full;
+ GPtrArray *data_time_empty;
guint save_id;
};
@@ -122,6 +126,38 @@ dkp_history_get_rate_data (DkpHistory *history, guint timespan)
}
/**
+ * dkp_history_get_time_full_data:
+ **/
+GPtrArray *
+dkp_history_get_time_full_data (DkpHistory *history, guint timespan)
+{
+ GPtrArray *array;
+
+ g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
+
+ if (history->priv->id == NULL)
+ return NULL;
+ array = dkp_history_copy_array_timespan (history->priv->data_time_full, timespan);
+ return array;
+}
+
+/**
+ * dkp_history_get_time_empty_data:
+ **/
+GPtrArray *
+dkp_history_get_time_empty_data (DkpHistory *history, guint timespan)
+{
+ GPtrArray *array;
+
+ g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
+
+ if (history->priv->id == NULL)
+ return NULL;
+ array = dkp_history_copy_array_timespan (history->priv->data_time_empty, timespan);
+ return array;
+}
+
+/**
* dkp_history_load_data:
**/
static gchar *
@@ -212,6 +248,16 @@ dkp_history_save_data (DkpHistory *history)
dkp_history_save_data_array (filename, history->priv->data_charge);
g_free (filename);
+ /* save charge history to disk */
+ filename = dkp_history_get_filename (history, "time-full");
+ dkp_history_save_data_array (filename, history->priv->data_time_full);
+ g_free (filename);
+
+ /* save charge history to disk */
+ filename = dkp_history_get_filename (history, "time-empty");
+ dkp_history_save_data_array (filename, history->priv->data_time_empty);
+ g_free (filename);
+
return TRUE;
}
@@ -362,6 +408,16 @@ dkp_history_load_data (DkpHistory *history)
dkp_history_load_data_array (filename, history->priv->data_charge);
g_free (filename);
+ /* load charge history from disk */
+ filename = dkp_history_get_filename (history, "time-full");
+ dkp_history_load_data_array (filename, history->priv->data_time_full);
+ g_free (filename);
+
+ /* load charge history from disk */
+ filename = dkp_history_get_filename (history, "time-empty");
+ dkp_history_load_data_array (filename, history->priv->data_time_empty);
+ g_free (filename);
+
return TRUE;
}
@@ -458,6 +514,66 @@ dkp_history_set_rate_data (DkpHistory *history, gdouble rate)
}
/**
+ * dkp_history_set_time_full_data:
+ **/
+gboolean
+dkp_history_set_time_full_data (DkpHistory *history, gint64 time)
+{
+ DkpHistoryObj *obj;
+
+ g_return_val_if_fail (DKP_IS_HISTORY (history), FALSE);
+
+ if (history->priv->id == NULL)
+ return FALSE;
+ if (history->priv->state == DKP_DEVICE_STATE_UNKNOWN)
+ return FALSE;
+ if (time < 0)
+ return FALSE;
+ if (history->priv->time_full_last == time)
+ return FALSE;
+
+ /* add to array and schedule save file */
+ obj = dkp_history_obj_create ((gdouble) time, history->priv->state);
+ g_ptr_array_add (history->priv->data_time_full, obj);
+ dkp_history_schedule_save (history);
+
+ /* save last value */
+ history->priv->time_full_last = time;
+
+ return TRUE;
+}
+
+/**
+ * dkp_history_set_time_empty_data:
+ **/
+gboolean
+dkp_history_set_time_empty_data (DkpHistory *history, gint64 time)
+{
+ DkpHistoryObj *obj;
+
+ g_return_val_if_fail (DKP_IS_HISTORY (history), FALSE);
+
+ if (history->priv->id == NULL)
+ return FALSE;
+ if (history->priv->state == DKP_DEVICE_STATE_UNKNOWN)
+ return FALSE;
+ if (time < 0)
+ return FALSE;
+ if (history->priv->time_empty_last == time)
+ return FALSE;
+
+ /* add to array and schedule save file */
+ obj = dkp_history_obj_create ((gdouble) time, history->priv->state);
+ g_ptr_array_add (history->priv->data_time_empty, obj);
+ dkp_history_schedule_save (history);
+
+ /* save last value */
+ history->priv->time_empty_last = time;
+
+ return TRUE;
+}
+
+/**
* dkp_history_class_init:
* @klass: The DkpHistoryClass
**/
@@ -483,6 +599,8 @@ dkp_history_init (DkpHistory *history)
history->priv->state = DKP_DEVICE_STATE_UNKNOWN;
history->priv->data_rate = g_ptr_array_new ();
history->priv->data_charge = g_ptr_array_new ();
+ history->priv->data_time_full = g_ptr_array_new ();
+ history->priv->data_time_empty = g_ptr_array_new ();
history->priv->save_id = 0;
}
@@ -504,6 +622,8 @@ dkp_history_finalize (GObject *object)
g_ptr_array_free (history->priv->data_rate, TRUE);
g_ptr_array_free (history->priv->data_charge, TRUE);
+ g_ptr_array_free (history->priv->data_time_full, TRUE);
+ g_ptr_array_free (history->priv->data_time_empty, TRUE);
g_free (history->priv->id);
g_return_if_fail (history->priv != NULL);
diff --git a/src/dkp-history.h b/src/dkp-history.h
index dc280bc..81b30ca 100644
--- a/src/dkp-history.h
+++ b/src/dkp-history.h
@@ -55,6 +55,10 @@ GPtrArray *dkp_history_get_charge_data (DkpHistory *history,
guint timespan);
GPtrArray *dkp_history_get_rate_data (DkpHistory *history,
guint timespan);
+GPtrArray *dkp_history_get_time_full_data (DkpHistory *history,
+ guint timespan);
+GPtrArray *dkp_history_get_time_empty_data (DkpHistory *history,
+ guint timespan);
gboolean dkp_history_set_id (DkpHistory *history,
const gchar *id);
@@ -64,6 +68,10 @@ gboolean dkp_history_set_charge_data (DkpHistory *history,
gdouble percentage);
gboolean dkp_history_set_rate_data (DkpHistory *history,
gdouble rate);
+gboolean dkp_history_set_time_full_data (DkpHistory *history,
+ gint64 time);
+gboolean dkp_history_set_time_empty_data (DkpHistory *history,
+ gint64 time);
G_END_DECLS
diff --git a/src/dkp-supply.c b/src/dkp-supply.c
index a7f9d31..9bc5c75 100644
--- a/src/dkp-supply.c
+++ b/src/dkp-supply.c
@@ -331,6 +331,8 @@ out:
dkp_history_set_state (supply->priv->history, obj->state);
dkp_history_set_charge_data (supply->priv->history, obj->percentage);
dkp_history_set_rate_data (supply->priv->history, obj->energy_rate);
+ dkp_history_set_time_full_data (supply->priv->history, obj->time_to_full);
+ dkp_history_set_time_empty_data (supply->priv->history, obj->time_to_empty);
g_free (status);
return ret;
@@ -371,6 +373,10 @@ dkp_supply_get_history (DkpDevice *device, const gchar *type, guint timespan)
array = dkp_history_get_rate_data (supply->priv->history, timespan);
else if (strcmp (type, "charge") == 0)
array = dkp_history_get_charge_data (supply->priv->history, timespan);
+ else if (strcmp (type, "time-full") == 0)
+ array = dkp_history_get_time_full_data (supply->priv->history, timespan);
+ else if (strcmp (type, "time-empty") == 0)
+ array = dkp_history_get_time_empty_data (supply->priv->history, timespan);
return array;
}