summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-11-04 12:01:46 +0000
committerRichard Hughes <richard@hughsie.com>2008-11-04 12:01:46 +0000
commit355b268ad7c88614b81354102a113940f0712654 (patch)
treed766bd9bf05aed19b2735e4e390e60c133d0e08b
parent39e7c41db1c19d9496a475e10bdf8f1d3c030022 (diff)
trivial: convert the data getting to enumerated types
-rw-r--r--src/dkp-history.c63
-rw-r--r--src/dkp-history.h19
-rw-r--r--src/dkp-supply.c25
3 files changed, 41 insertions, 66 deletions
diff --git a/src/dkp-history.c b/src/dkp-history.c
index cd2d01a..75fc26c 100644
--- a/src/dkp-history.c
+++ b/src/dkp-history.c
@@ -192,66 +192,33 @@ dkp_history_copy_array_timespan (const EggObjList *array, guint timespan)
}
/**
- * dkp_history_get_charge_data:
+ * dkp_history_get_data:
**/
EggObjList *
-dkp_history_get_charge_data (DkpHistory *history, guint timespan)
+dkp_history_get_data (DkpHistory *history, DkpHistoryType type, guint timespan)
{
EggObjList *array;
+ const EggObjList *array_data = NULL;
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_charge, timespan);
- return array;
-}
-
-/**
- * dkp_history_get_rate_data:
- **/
-EggObjList *
-dkp_history_get_rate_data (DkpHistory *history, guint timespan)
-{
- EggObjList *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_rate, timespan);
- return array;
-}
-
-/**
- * dkp_history_get_time_full_data:
- **/
-EggObjList *
-dkp_history_get_time_full_data (DkpHistory *history, guint timespan)
-{
- EggObjList *array;
-
- g_return_val_if_fail (DKP_IS_HISTORY (history), NULL);
- if (history->priv->id == NULL)
+ if (type == DKP_HISTORY_TYPE_CHARGE)
+ array_data = history->priv->data_charge;
+ else if (type == DKP_HISTORY_TYPE_RATE)
+ array_data = history->priv->data_rate;
+ else if (type == DKP_HISTORY_TYPE_TIME_FULL)
+ array_data = history->priv->data_time_full;
+ else if (type == DKP_HISTORY_TYPE_TIME_EMPTY)
+ array_data = history->priv->data_time_empty;
+
+ /* not recognised */
+ if (array_data == NULL)
return NULL;
- array = dkp_history_copy_array_timespan (history->priv->data_time_full, timespan);
- return array;
-}
-
-/**
- * dkp_history_get_time_empty_data:
- **/
-EggObjList *
-dkp_history_get_time_empty_data (DkpHistory *history, guint timespan)
-{
- EggObjList *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);
+ array = dkp_history_copy_array_timespan (array_data, timespan);
return array;
}
diff --git a/src/dkp-history.h b/src/dkp-history.h
index 594bf9e..9b7ba62 100644
--- a/src/dkp-history.h
+++ b/src/dkp-history.h
@@ -51,19 +51,22 @@ typedef struct
GObjectClass parent_class;
} DkpHistoryClass;
+typedef enum {
+ DKP_HISTORY_TYPE_CHARGE,
+ DKP_HISTORY_TYPE_RATE,
+ DKP_HISTORY_TYPE_TIME_FULL,
+ DKP_HISTORY_TYPE_TIME_EMPTY,
+ DKP_HISTORY_TYPE_UNKNOWN
+} DkpHistoryType;
+
+
GType dkp_history_get_type (void) G_GNUC_CONST;
DkpHistory *dkp_history_new (void);
-EggObjList *dkp_history_get_charge_data (DkpHistory *history,
- guint timespan);
-EggObjList *dkp_history_get_rate_data (DkpHistory *history,
- guint timespan);
-EggObjList *dkp_history_get_time_full_data (DkpHistory *history,
- guint timespan);
-EggObjList *dkp_history_get_time_empty_data (DkpHistory *history,
+EggObjList *dkp_history_get_data (DkpHistory *history,
+ DkpHistoryType type,
guint timespan);
EggObjList *dkp_history_get_profile_data (DkpHistory *history,
gboolean charging);
-
gboolean dkp_history_set_id (DkpHistory *history,
const gchar *id);
gboolean dkp_history_set_state (DkpHistory *history,
diff --git a/src/dkp-supply.c b/src/dkp-supply.c
index 80ec755..d271915 100644
--- a/src/dkp-supply.c
+++ b/src/dkp-supply.c
@@ -399,23 +399,28 @@ dkp_supply_poll_battery (DkpSupply *supply)
* dkp_supply_get_history:
**/
static EggObjList *
-dkp_supply_get_history (DkpDevice *device, const gchar *type, guint timespan)
+dkp_supply_get_history (DkpDevice *device, const gchar *type_string, guint timespan)
{
DkpSupply *supply = DKP_SUPPLY (device);
EggObjList *array = NULL;
+ DkpHistoryType type = DKP_HISTORY_TYPE_UNKNOWN;
g_return_val_if_fail (DKP_IS_SUPPLY (supply), FALSE);
- g_return_val_if_fail (type != NULL, FALSE);
+ g_return_val_if_fail (type_string != NULL, FALSE);
/* get the correct data */
- if (egg_strequal (type, "rate"))
- array = dkp_history_get_rate_data (supply->priv->history, timespan);
- else if (egg_strequal (type, "charge"))
- array = dkp_history_get_charge_data (supply->priv->history, timespan);
- else if (egg_strequal (type, "time-full"))
- array = dkp_history_get_time_full_data (supply->priv->history, timespan);
- else if (egg_strequal (type, "time-empty"))
- array = dkp_history_get_time_empty_data (supply->priv->history, timespan);
+ if (egg_strequal (type_string, "rate"))
+ type = DKP_HISTORY_TYPE_RATE;
+ else if (egg_strequal (type_string, "charge"))
+ type = DKP_HISTORY_TYPE_CHARGE;
+ else if (egg_strequal (type_string, "time-full"))
+ type = DKP_HISTORY_TYPE_TIME_FULL;
+ else if (egg_strequal (type_string, "time-empty"))
+ type = DKP_HISTORY_TYPE_TIME_EMPTY;
+
+ /* something recognised */
+ if (type != DKP_HISTORY_TYPE_UNKNOWN)
+ array = dkp_history_get_data (supply->priv->history, type, timespan);
return array;
}