diff options
author | Landry Breuil <landry@rhaalovely.net> | 2011-03-06 14:02:37 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2011-03-21 18:39:15 +0000 |
commit | d5b1d6d49f8faa6ef09278836d9f0dd56f18fef3 (patch) | |
tree | e543aa811e19624675ddd332d35c1fa991ce4e4e /src/openbsd/up-backend.c | |
parent | 8d2844c51c0976d8424afcd6d20c9d7fc169e2a2 (diff) | |
download | upower-d5b1d6d49f8faa6ef09278836d9f0dd56f18fef3.tar.gz |
openbsd: move batt/ac properties update to their own separate functions
Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'src/openbsd/up-backend.c')
-rw-r--r-- | src/openbsd/up-backend.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/src/openbsd/up-backend.c b/src/openbsd/up-backend.c index 4b768f4..5b49065 100644 --- a/src/openbsd/up-backend.c +++ b/src/openbsd/up-backend.c @@ -166,30 +166,44 @@ UpDeviceState up_backend_apm_get_battery_state_value(u_char battery_state) { return -1; } +static void +up_backend_update_ac_state(UpDevice* device, struct apm_power_info a) +{ + GTimeVal timeval; + g_get_current_time (&timeval); + g_object_set (device, + "online", (a.ac_state == APM_AC_ON ? TRUE : FALSE), + "update-time", (guint64) timeval.tv_sec, + NULL); +} + +static void +up_backend_update_battery_state(UpDevice* device, struct apm_power_info a) +{ + GTimeVal timeval; + g_get_current_time (&timeval); + // XXX set time-to-empty ? + g_object_set (device, + "state", up_backend_apm_get_battery_state_value(a.battery_state), + "percentage", (gdouble) a.battery_life, + "update-time", (guint64) timeval.tv_sec, + NULL); +} + /* callback updating the device */ static gboolean up_backend_apm_powerchange_event_cb(gpointer object) { UpBackend *backend; struct apm_power_info a; - GTimeVal timeval; g_return_if_fail (UP_IS_BACKEND (object)); backend = UP_BACKEND (object); a = up_backend_apm_get_power_info(backend->priv->apm_fd); g_message("Got event, in callback, percentage=%d, battstate=%d, acstate=%d", a.battery_life, a.battery_state, a.ac_state); - // XXX set time-to-empty ? - g_get_current_time (&timeval); - g_object_set (backend->priv->battery, - "state", up_backend_apm_get_battery_state_value(a.battery_state), - "percentage", (gdouble) a.battery_life, - "update-time", (guint64) timeval.tv_sec, - NULL); - g_object_set (backend->priv->ac, - "online", (a.ac_state == APM_AC_ON ? TRUE : FALSE), - "update-time", (guint64) timeval.tv_sec, - NULL); + up_backend_update_ac_state(backend->priv->ac, a); + up_backend_update_battery_state(backend->priv->battery, a); /* return false to not endless loop */ return FALSE; } |