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.
*/
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);
/**
* @}
*/
*/
#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;
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;
+}