diff options
author | Martin Szulecki | 2010-12-18 18:34:05 +0100 |
---|---|---|
committer | Martin Szulecki | 2010-12-19 21:23:46 +0100 |
commit | 6a1b66f1de2d7147d4498f0902a494de56282039 (patch) | |
tree | 381ab46f5a740406e3581381b2976887d880e70b | |
parent | 948e2a8a85dc5082279a6b3e1c586f2ce7622716 (diff) | |
download | sbmanager-6a1b66f1de2d7147d4498f0902a494de56282039.tar.gz sbmanager-6a1b66f1de2d7147d4498f0902a494de56282039.tar.bz2 |
Do not poll all device info again, just the battery capacity
-rw-r--r-- | src/device.c | 45 | ||||
-rw-r--r-- | src/device.h | 1 | ||||
-rw-r--r-- | src/gui.c | 2 |
3 files changed, 46 insertions, 2 deletions
diff --git a/src/device.c b/src/device.c index 2d3b3c5..e92fbc2 100644 --- a/src/device.c +++ b/src/device.c @@ -277,9 +277,52 @@ static guint battery_info_get_current_capacity(plist_t battery_info) return (guint)current_capacity; } +gboolean device_poll_battery_capacity(const char *uuid, device_info_t *device_info, GError **error) { + plist_t node = NULL; + idevice_t phone = NULL; + lockdownd_client_t client = NULL; + gboolean res = FALSE; + + printf("%s: %s\n", __func__, uuid); + + if (!device_info) { + return res; + } + + printf("%s\n", __func__); + + g_mutex_lock(idevice_mutex); + if (!device_connect(uuid, &phone, &client, error)) { + goto leave_cleanup; + } + + if (!*device_info) { + /* make new device info */ + *device_info = device_info_new(); + } + + /* get current battery capacity */ + node = NULL; + lockdownd_get_value(client, "com.apple.mobile.battery", NULL, &node); + (*device_info)->battery_capacity = battery_info_get_current_capacity(node); + plist_free(node); + + res = TRUE; + + leave_cleanup: + if (client) { + lockdownd_client_free(client); + } + idevice_free(phone); + g_mutex_unlock(idevice_mutex); + + return res; +} + gboolean device_get_info(const char *uuid, device_info_t *device_info, GError **error) { - uint64_t interval = 60; + uint8_t boolean = FALSE; + uint64_t integer = 60; plist_t node = NULL; idevice_t phone = NULL; lockdownd_client_t client = NULL; diff --git a/src/device.h b/src/device.h index 4714368..c8829b2 100644 --- a/src/device.h +++ b/src/device.h @@ -46,6 +46,7 @@ char *device_sbs_save_wallpaper(sbservices_client_t sbc, const char *uuid, GErro device_info_t device_info_new(); void device_info_free(device_info_t device_info); +gboolean device_poll_battery_capacity(const char *uuid, device_info_t *device_info, GError **error); gboolean device_get_info(const char *uuid, device_info_t *device_info, GError **error); #endif @@ -1889,7 +1889,7 @@ static gboolean update_battery_info_cb(gpointer user_data) return FALSE; } - if (device_get_info(uuid, &device_info, &error)) { + if (device_poll_battery_capacity(uuid, &device_info, &error)) { clutter_actor_set_size(battery_level, (guint) (((double) (device_info->battery_capacity) / 100.0) * 15), 6); if (device_info->battery_capacity == 100) { res = FALSE; |