diff options
author | Martin Szulecki | 2012-04-07 18:20:47 +0200 |
---|---|---|
committer | Martin Szulecki | 2012-04-07 18:20:47 +0200 |
commit | 1c39477bba4c2e88fd193a03c18209eb7db91f75 (patch) | |
tree | f801204be6a8bdfe2817096232a8eaf8e485dea9 | |
parent | a3d02692d3772767ae847ed2f32c1203cfb7e42a (diff) | |
download | libimobiledevice-1c39477bba4c2e88fd193a03c18209eb7db91f75.tar.gz libimobiledevice-1c39477bba4c2e88fd193a03c18209eb7db91f75.tar.bz2 |
sbservices: Implement retrieving interface orientation from device
-rw-r--r-- | include/libimobiledevice/sbservices.h | 12 | ||||
-rw-r--r-- | src/sbservices.c | 46 |
2 files changed, 58 insertions, 0 deletions
diff --git a/include/libimobiledevice/sbservices.h b/include/libimobiledevice/sbservices.h index 616168e..08cb740 100644 --- a/include/libimobiledevice/sbservices.h +++ b/include/libimobiledevice/sbservices.h @@ -39,6 +39,17 @@ extern "C" { #define SBSERVICES_E_UNKNOWN_ERROR -256 /*@}*/ +/** @name Orientation of the user interface on the device */ +/*@{*/ +typedef enum { + SBSERVICES_INTERFACE_ORIENTATION_UNKNOWN = 0, + SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT = 1, + SBSERVICES_INTERFACE_ORIENTATION_PORTRAIT_UPSIDE_DOWN = 2, + SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_RIGHT = 3, + SBSERVICES_INTERFACE_ORIENTATION_LANDSCAPE_LEFT = 4 +} sbservices_interface_orientation_t; +/*@}*/ + /** Represents an error code. */ typedef int16_t sbservices_error_t; @@ -51,6 +62,7 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client); sbservices_error_t sbservices_get_icon_state(sbservices_client_t client, plist_t *state, const char *format_version); sbservices_error_t sbservices_set_icon_state(sbservices_client_t client, plist_t newstate); sbservices_error_t sbservices_get_icon_pngdata(sbservices_client_t client, const char *bundleId, char **pngdata, uint64_t *pngsize); +sbservices_error_t sbservices_get_interface_orientation(sbservices_client_t client, sbservices_interface_orientation_t* interface_orientation); sbservices_error_t sbservices_get_home_screen_wallpaper_pngdata(sbservices_client_t client, char **pngdata, uint64_t *pngsize); #ifdef __cplusplus diff --git a/src/sbservices.c b/src/sbservices.c index 7f050bf..2c17d8c 100644 --- a/src/sbservices.c +++ b/src/sbservices.c @@ -283,7 +283,53 @@ leave_unlock: } sbs_unlock(client); return res; +} +/** + * Gets the interface orientation of the device. + * + * @param client The connected sbservices client to use. + * @param interface_orientation The interface orientation upon successful return. + * + * @return SBSERVICES_E_SUCCESS on success, SBSERVICES_E_INVALID_ARG when + * client or state is invalid, or an SBSERVICES_E_* error code otherwise. + */ +sbservices_error_t sbservices_get_interface_orientation(sbservices_client_t client, sbservices_interface_orientation_t* interface_orientation) +{ + if (!client || !client->parent || !interface_orientation) + return SBSERVICES_E_INVALID_ARG; + + sbservices_error_t res = SBSERVICES_E_UNKNOWN_ERROR; + + plist_t dict = plist_new_dict(); + plist_dict_insert_item(dict, "command", plist_new_string("getInterfaceOrientation")); + + sbs_lock(client); + + res = sbservices_error(property_list_service_send_binary_plist(client->parent, dict)); + if (res != SBSERVICES_E_SUCCESS) { + debug_info("could not send plist, error %d", res); + goto leave_unlock; + } + plist_free(dict); + dict = NULL; + + res = sbservices_error(property_list_service_receive_plist(client->parent, &dict)); + if (res == SBSERVICES_E_SUCCESS) { + plist_t node = plist_dict_get_item(dict, "interfaceOrientation"); + if (node) { + uint64_t value = SBSERVICES_INTERFACE_ORIENTATION_UNKNOWN; + plist_get_uint_val(node, &value); + *interface_orientation = (sbservices_interface_orientation_t)value; + } + } + +leave_unlock: + if (dict) { + plist_free(dict); + } + sbs_unlock(client); + return res; } /** |