Add new api to get type 68/218768/4
authormk5004.lee <mk5004.lee@samsung.com>
Thu, 28 Nov 2019 04:26:32 +0000 (13:26 +0900)
committerMyungKi Lee <mk5004.lee@samsung.com>
Mon, 20 Jan 2020 08:21:09 +0000 (08:21 +0000)
Change-Id: I6201c13791d10ae75e75d4f66543804c15dd6aa6
Signed-off-by: mk5004.lee <mk5004.lee@samsung.com>
include/app_preference.h
include/app_preference_internal.h
src/preference.c

index 7113578fe8db6d2243b86e4f3c2642609f7e2408..4aeb98c5a8bd470bf984a822d1707b3ac1b99292 100644 (file)
@@ -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);
 /**
  * @}
  */
index 478efb71aa4e81ff60620b03bfa456f6f1fac029..0221c2042d511af0b665f3b78ad200f27090ee8c 100644 (file)
@@ -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;
index cbf815cdfe2cac0ad2994a0a9d564a6fecde3888..4547d5f5a9cd17eabbe0044bfe65cc92de1aa13f 100644 (file)
@@ -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;
+}