From: mk5004.lee Date: Thu, 28 Nov 2019 04:26:32 +0000 (+0900) Subject: Add new api to get type X-Git-Tag: submit/tizen/20200121.084153~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9d38434999a3d82fbbb0b94fa55d9255e6a04153;p=platform%2Fcore%2Fapi%2Fpreference.git Add new api to get type Change-Id: I6201c13791d10ae75e75d4f66543804c15dd6aa6 Signed-off-by: mk5004.lee --- diff --git a/include/app_preference.h b/include/app_preference.h index 7113578..4aeb98c 100644 --- a/include/app_preference.h +++ b/include/app_preference.h @@ -47,6 +47,18 @@ typedef enum { PREFERENCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR , /**< Internal I/O Error */ } preference_error_e; +/** + * @brief Enumeration for Preference type. + * @since_tizen 5.5 + */ +typedef enum { + PREFERENCE_TYPE_NONE = 0, /**< None */ + PREFERENCE_TYPE_STRING, /**< String */ + PREFERENCE_TYPE_INT, /**< Int */ + PREFERENCE_TYPE_DOUBLE, /**< Double */ + PREFERENCE_TYPE_BOOLEAN, /**< Bool */ +} preference_type_e; + /** * @brief Called when the given key's value in the preference changes. @@ -308,7 +320,21 @@ int preference_unset_changed_cb(const char *key); */ int preference_foreach_item(preference_item_cb callback, void *user_data); - +/** + * @brief Gets the type of a preference. + * @since_tizen 5.5 + * @param[in] key The name of the key + * @param[out] type The preference type + * @return @c 0 on success, + * otherwise a negative error value + * @retval #PREFERENCE_ERROR_NONE Successful + * @retval #PREFERENCE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PREFERENCE_ERROR_NO_KEY Required key not available + * @retval #PREFERENCE_ERROR_IO_ERROR Internal I/O Error + * @retval #PREFERENCE_ERROR_OUT_OF_MEMORY Out of memory + * @see #preference_type_e + */ +int preference_get_type(const char *key, preference_type_e *type); /** * @} */ diff --git a/include/app_preference_internal.h b/include/app_preference_internal.h index 478efb7..0221c20 100644 --- a/include/app_preference_internal.h +++ b/include/app_preference_internal.h @@ -91,14 +91,6 @@ extern "C" { */ #define PREFERENCE_ERROR_FILE_LOCK -29 -typedef enum { - PREFERENCE_TYPE_NONE = 0, - PREFERENCE_TYPE_STRING, - PREFERENCE_TYPE_INT, - PREFERENCE_TYPE_DOUBLE, - PREFERENCE_TYPE_BOOLEAN, -} preference_type_e; - typedef struct _pref_changed_cb_node_t { char *key; preference_changed_cb cb; diff --git a/src/preference.c b/src/preference.c index cbf815c..4547d5f 100644 --- a/src/preference.c +++ b/src/preference.c @@ -1594,3 +1594,45 @@ API int preference_foreach_item(preference_item_cb callback, void *user_data) return PREFERENCE_ERROR_NONE; } +/* + * This function get the type of given key + * @param[in] key key + * @param[out] type output buffer + * @return 0 on success, -value on error + */ +API int preference_get_type(const char *key, preference_type_e *type) +{ + int ret; + keynode_t *pKeyNode; + + START_TIME_CHECK + + retvm_if(key == NULL, PREFERENCE_ERROR_INVALID_PARAMETER, + "Invalid argument: key is null"); + retvm_if(type == NULL, PREFERENCE_ERROR_INVALID_PARAMETER, + "Invalid argument: output buffer is null"); + + pKeyNode = _preference_keynode_new(); + retvm_if(pKeyNode == NULL, PREFERENCE_ERROR_OUT_OF_MEMORY, "key malloc fail"); + + ret = _preference_keynode_set_keyname(pKeyNode, key); + if (ret != PREFERENCE_ERROR_NONE) { + ERR("set key name error"); + _preference_keynode_free(pKeyNode); + return ret; + } + + ret = _preference_get_key(pKeyNode); + if (ret != PREFERENCE_ERROR_NONE) { + ERR("preference_get_int(%d) : key(%s) error", getpid(), key); + *type = PREFERENCE_TYPE_NONE; + } else { + *type = pKeyNode->type; + } + + _preference_keynode_free(pKeyNode); + + END_TIME_CHECK + + return ret; +}