From: Jiwoong Im Date: Wed, 13 Jan 2016 07:32:13 +0000 (+0900) Subject: vconf-compat : sync vconf api with tizen_2.4 X-Git-Tag: accepted/tizen/mobile/20160129.083656~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F75%2F56875%2F3;p=platform%2Fcore%2Fsystem%2Fbuxton2.git vconf-compat : sync vconf api with tizen_2.4 Add missing api and sync vconf.h with tizen_2.4 Change-Id: I10ce8495ba8298603263276ef0135315b89b4bd4 Signed-off-by: Jiwoong Im --- diff --git a/vconf-compat/vconf.c b/vconf-compat/vconf.c index 78390f3..436c99a 100644 --- a/vconf-compat/vconf.c +++ b/vconf-compat/vconf.c @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include @@ -50,16 +53,7 @@ struct noti_cb { gboolean deleted; }; -struct _keynode_t { - char *keyname; - int type; - union { - int i; - int b; - double d; - char *s; - } value; -}; +static bool last_result; EXPORT char *vconf_keynode_get_name(keynode_t *keynode) { @@ -512,6 +506,7 @@ EXPORT int vconf_set_int(const char *key, int intval) { int r; struct buxton_value *val; + last_result = false; if (!key) { errno = EINVAL; @@ -525,6 +520,7 @@ EXPORT int vconf_set_int(const char *key, int intval) r = _vconf_set(key, val); buxton_value_free(val); + last_result = true; return r; } @@ -533,6 +529,7 @@ EXPORT int vconf_set_bool(const char *key, int boolval) { int r; struct buxton_value *val; + last_result = false; if (!key) { errno = EINVAL; @@ -546,6 +543,7 @@ EXPORT int vconf_set_bool(const char *key, int boolval) r = _vconf_set(key, val); buxton_value_free(val); + last_result = true; return r; } @@ -554,6 +552,7 @@ EXPORT int vconf_set_str(const char *key, const char *strval) { int r; struct buxton_value *val; + last_result = false; if (!key || !strval) { errno = EINVAL; @@ -567,6 +566,7 @@ EXPORT int vconf_set_str(const char *key, const char *strval) r = _vconf_set(key, val); buxton_value_free(val); + last_result = true; return r; } @@ -575,6 +575,7 @@ EXPORT int vconf_set_dbl(const char *key, double dblval) { int r; struct buxton_value *val; + last_result = false; if (!key) { errno = EINVAL; @@ -588,6 +589,7 @@ EXPORT int vconf_set_dbl(const char *key, double dblval) r = _vconf_set(key, val); buxton_value_free(val); + last_result = true; return r; } @@ -634,6 +636,7 @@ EXPORT int vconf_get_int(const char *key, int *intval) int r; struct buxton_value *val; int32_t i; + last_result = false; if (!key || !intval) { errno = EINVAL; @@ -652,6 +655,7 @@ EXPORT int vconf_get_int(const char *key, int *intval) return -1; *intval = i; + last_result = true; return 0; } @@ -661,6 +665,8 @@ EXPORT int vconf_get_bool(const char *key, int *boolval) int r; struct buxton_value *val; int32_t b; + last_result = false; + if (!key || !boolval) { errno = EINVAL; @@ -679,6 +685,7 @@ EXPORT int vconf_get_bool(const char *key, int *boolval) return -1; *boolval = b; + last_result = true; return 0; } @@ -689,6 +696,7 @@ EXPORT char *vconf_get_str(const char *key) struct buxton_value *val; const char *s; char *str; + last_result = false; if (!key) { errno = EINVAL; @@ -706,6 +714,7 @@ EXPORT char *vconf_get_str(const char *key) str = s ? strdup(s) : NULL; buxton_value_free(val); + last_result = true; return str; } @@ -715,6 +724,7 @@ EXPORT int vconf_get_dbl(const char *key, double *dblval) int r; struct buxton_value *val; double d; + last_result = false; if (!key || !dblval) { errno = EINVAL; @@ -733,17 +743,46 @@ EXPORT int vconf_get_dbl(const char *key, double *dblval) return -1; *dblval = d; + last_result = true; return 0; } EXPORT int vconf_get_ext_errno(void) { - return errno * -1; + int ret; + + if (last_result) + return VCONF_OK; + + switch(errno) { + case ENOENT: + ret = VCONF_ERROR_FILE_NO_ENT; + break; + case ENOMEM: + case ENOSPC: + ret = VCONF_ERROR_FILE_NO_MEM; + break; + case EAGAIN: + case ETIMEDOUT: + case EBUSY: + case EMFILE: + ret = VCONF_ERROR_FILE_BUSY; + break; + case EACCES: + case EPERM: + ret = VCONF_ERROR_FILE_PERM; + break; + default: + ret = VCONF_ERROR; + } + + return ret; } struct _keylist_t { GList *list; /* struct _keynode_t list */ + GList *cursor; }; EXPORT keylist_t *vconf_keylist_new(void) @@ -818,6 +857,7 @@ static struct _keynode_t *get_keynode(struct _keylist_t *keylist, } keylist->list = g_list_append(keylist->list, keynode); + keylist->cursor = g_list_last(keylist->list); return keynode; } @@ -842,7 +882,7 @@ EXPORT int vconf_keylist_add_int(keylist_t *keylist, keynode->type = VCONF_TYPE_INT; keynode->value.i = value; - return 0; + return g_list_length(keylist->list); } EXPORT int vconf_keylist_add_bool(keylist_t *keylist, @@ -865,7 +905,7 @@ EXPORT int vconf_keylist_add_bool(keylist_t *keylist, keynode->type = VCONF_TYPE_BOOL; keynode->value.b = value; - return 0; + return g_list_length(keylist->list); } EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, @@ -888,7 +928,7 @@ EXPORT int vconf_keylist_add_dbl(keylist_t *keylist, keynode->type = VCONF_TYPE_DOUBLE; keynode->value.d = value; - return 0; + return g_list_length(keylist->list); } EXPORT int vconf_keylist_add_str(keylist_t *keylist, @@ -918,7 +958,24 @@ EXPORT int vconf_keylist_add_str(keylist_t *keylist, keynode->type = VCONF_TYPE_STRING; keynode->value.s = s; - return 0; + return g_list_length(keylist->list); +} + +EXPORT int vconf_keylist_add_null(keylist_t *keylist, const char *keyname) +{ + struct _keynode_t *keynode; + + if (!keylist || !keyname) { + errno = EINVAL; + return -1; + } + + keynode = get_keynode(keylist, keyname); + if (!keynode) { + return -1; + } + + return g_list_length(keylist->list); } EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname) @@ -942,6 +999,48 @@ EXPORT int vconf_keylist_del(keylist_t *keylist, const char *keyname) return 0; } +EXPORT keynode_t *vconf_keylist_nextnode(keylist_t *keylist) +{ + keynode_t *node = NULL; + GList *next; + + if (!keylist) { + errno = EINVAL; + return NULL; + } + + next = g_list_next(keylist->cursor); + if (!next) { + next = g_list_first(keylist->cursor); + } + + node = next->data; + keylist->cursor = next; + + return node; +} + +EXPORT int vconf_keylist_rewind(keylist_t *keylist) +{ + GList *l; + + if (!keylist) { + errno = EINVAL; + return -1; + } + + l = g_list_last(keylist->cursor); + + if (!l) { + errno = ENOENT; + return -1; + } + + keylist->cursor = l; + + return 0; +} + static int set_keynode_value(struct buxton_value *v, struct _keynode_t *keynode) { int r; @@ -1130,6 +1229,107 @@ EXPORT int vconf_set(keylist_t *keylist) return 0; } +EXPORT int vconf_unset(const char *in_key) +{ + int r; + if (getuid() != 0) + return VCONF_ERROR_NOT_SUPPORTED; + + if (!in_key) { + errno = EINVAL; + return -1; + } + + r = _open(); + if (r == -1) + return -1; + + r = buxton_unset_value_sync(client, get_layer(in_key), in_key); + if (r == -1) + LOGE("unset value: key '%s' errno %d", in_key, errno); + + _close(); + + return r; +} + +EXPORT int vconf_unset_recursive(const char *in_dir) +{ + int r; + int i; + int dirlen; + char **names; + unsigned int len; + struct buxton_layer *layer; + + if (getuid() != 0) + return VCONF_ERROR_NOT_SUPPORTED; + + if (!in_dir) { + errno = EINVAL; + return -1; + } + + dirlen = strlen(in_dir); + if (dirlen < 2) { /* minimum is "db" */ + errno = EINVAL; + return -1; + } + + r = _open(); + if (r == -1) + return -1; + + layer = get_layer(in_dir); + + r = buxton_list_keys_sync(client, layer, &names, &len); + if (r == -1) { + LOGE("get key list: errno %d", errno); + _close(); + return -1; + } + + for (i = 0; i < len; i++) { + if (strncmp(in_dir, names[i], dirlen)) + continue; + + r = vconf_unset(names[i]); + if (r == -1) { + buxton_free_keys(names); + _close(); + return -1; + } + } + + buxton_free_keys(names); + _close(); + + return 0; +} + +EXPORT int vconf_sync_key(const char *in_key) +{ + int r; + struct buxton_value *v; + + assert(in_key); + + r = _open(); + if (r == -1) + return -1; + + r = buxton_get_value_sync(client, get_layer(in_key), in_key, &v); + if (r == -1) { + LOGE("get value: key '%s'", in_key); + } else { + r = 0; + } + + _close(); + + return r; +} + EXPORT int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, keynode_t **return_node) { diff --git a/vconf-compat/vconf.h b/vconf-compat/vconf.h index 3c57346..ab9d420 100644 --- a/vconf-compat/vconf.h +++ b/vconf-compat/vconf.h @@ -16,333 +16,1184 @@ * limitations under the License. */ -#ifndef __VCONF_H__ -#define __VCONF_H__ +#pragma once #include - #include "vconf-keys.h" #ifdef __cplusplus extern "C" { #endif -#define VCONF_OK 0 -#define VCONF_ERROR -1 -#define VCONF_ERROR_FILE_NO_ENT -ENOENT -#define VCONF_ERROR_FILE_PERM -EPERM +/** + * @file vconf.h + */ + +/** + * @addtogroup StorageFW_VCONF_MODULE + * @{ + */ + +/** + * @brief Definition for VCONF_OK. + * @since_tizen 2.3 + */ +#define VCONF_OK 0 + +/** + * @brief Definition for VCONF_ERROR. + * @since_tizen 2.3 + */ +#define VCONF_ERROR -1 + +/** + * @brief Definition for VCONF_ERROR_WRONG_PREFIX. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_WRONG_PREFIX -2 + +/** + * @brief Definition for VCONF_ERROR_WRONG_TYPE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_WRONG_TYPE -3 + +/** + * @brief Definition for VCONF_ERROR_WRONG_VALUE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_WRONG_VALUE -4 + +/** + * @brief Definition for VCONF_ERROR_NOT_INITIALIZED. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_NOT_INITIALIZED -5 + +/** + * @brief Definition for VCONF_ERROR_NO_MEM. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_NO_MEM -6 + +/** + * @brief Definition for VCONF_ERROR_FILE_PERM. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_PERM -11 + +/** + * @brief Definition for VCONF_ERROR_FILE_BUSY. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_BUSY -12 + +/** + * @brief Definition for VCONF_ERROR_FILE_NO_MEM. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_NO_MEM -13 + +/** + * @brief Definition for VCONF_ERROR_FILE_NO_ENT. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_NO_ENT -14 + +/** + * @brief Definition for VCONF_ERROR_FILE_OPEN. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_OPEN -21 +/** + * @brief Definition for VCONF_ERROR_FILE_FREAD. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_FREAD -22 + +/** + * @brief Definition for VCONF_ERROR_FILE_FGETS. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_FGETS -23 + +/** + * @brief Definition for VCONF_ERROR_FILE_WRITE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_WRITE -24 + +/** + * @brief Definition for VCONF_ERROR_FILE_SYNC. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_SYNC -25 + +/** + * @brief Definition for VCONF_ERROR_FILE_CLOSE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_CLOSE -26 + +/** + * @brief Definition for VCONF_ERROR_FILE_ACCESS. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_ACCESS -27 + +/** + * @brief Definition for VCONF_ERROR_FILE_CHMOD. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_CHMOD -28 + +/** + * @brief Definition for VCONF_ERROR_FILE_LOCK. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_LOCK -29 + +/** + * @brief Definition for VCONF_ERROR_FILE_REMOVE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_REMOVE -30 + +/** + * @brief Definition for VCONF_ERROR_FILE_SEEK. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_SEEK -31 + +/** + * @brief Definition for VCONF_ERROR_FILE_TRUNCATE. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_FILE_TRUNCATE -32 + +/** + * @brief Definition for VCONF_ERROR_NOT_SUPPORTED. + * @since_tizen 2.3 + */ +#define VCONF_ERROR_NOT_SUPPORTED -33 + + +/** + * @brief Enumeration for uses of vconf_get(). + * @since_tizen 2.3 + * @see vconf_get() + */ +enum get_option_t { + VCONF_GET_KEY = 0, /**< Get only keys */ + VCONF_GET_ALL, /**< Get keys and directories */ + VCONF_GET_DIR /**< Get only directories */ +}; + +/** + * @brief Enumeration for Definition for Enumeration type. + * @since_tizen 2.3 + * + */ +typedef enum get_option_t get_option_t; + + /** + * @brief Enumeration for vconf_t. + * @since_tizen 2.3 + * + */ enum vconf_t { - VCONF_TYPE_NONE = 0, /**< Vconf none type for Error detection */ + VCONF_TYPE_NONE = 0, /**< Vconf none type for Error detection */ VCONF_TYPE_STRING = 40, /**< Vconf string type */ - VCONF_TYPE_INT = 41, /**< Vconf integer type */ + VCONF_TYPE_INT = 41, /**< Vconf integer type */ VCONF_TYPE_DOUBLE = 42, /**< Vconf double type */ - VCONF_TYPE_BOOL = 43, /**< Vconf boolean type */ - VCONF_TYPE_DIR /**< Vconf directory type */ + VCONF_TYPE_BOOL = 43, /**< Vconf boolean type */ + VCONF_TYPE_DIR /**< Vconf directory type */ }; + /** - * keynode_t key node structure + * @brief The structure type for an opaque type. It must be used via accessor functions. + * @since_tizen 2.3 + * + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_dbl() + * @see vconf_keynode_get_int() + * @see vconf_keynode_get_str() */ -typedef struct _keynode_t keynode_t; +typedef struct _keynode_t { + char *keyname; /**< Keyname for keynode */ + int type; /**< Keynode type */ + union { + int i; /**< Integer type */ + int b; /**< Bool type */ + double d; /**< Double type */ + char *s; /**< String type */ + } value; /**< Value for keynode */ +} keynode_t; /** - * Get the name of key + * @brief The structure type for opaque type. It must be used via accessor functions. + * @since_tizen 2.3 * - * @param[in] keynode Key node - * @return the name - * @deprecated use buxton APIs + * @see vconf_keylist_new() + * @see vconf_keylist_free() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_int() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() + * @see vconf_keylist_lookup() + * @see vconf_keylist_nextnode() + * @see vconf_keylist_rewind() + */ +typedef struct _keylist_t keylist_t; + + +/** + * @brief Called when the key is set handle. + * @details This is the signature of a callback function added with vconf_notify_key_changed() handle. + * + * @since_tizen 2.3 + * + * @see keynode_t + */ +typedef void (*vconf_callback_fn) (keynode_t *node, void *user_data); + +/************************************************ + * keynode handling APIs * + ************************************************/ + +/** + * @brief Gets the key name of a keynode. + * + * @since_tizen 2.3 + * + * @param[in] keynode The Key + * + * @return The key name of the keynode + * + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_str() + * @see vconf_keynode_get_int() + * @see vconf_keynode_get_dbl() + * @see keynode_t + * @see vconf_t */ char *vconf_keynode_get_name(keynode_t *keynode); /** - * Get the type of key + * @brief Gets the value type of a keynode. + * + * @since_tizen 2.3 + * + * @param[in] keynode The Key + * + * @return The type of the keynode * - * @param[in] keynode Key node - * @return the type - * @deprecated use buxton APIs + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_str() + * @see vconf_keynode_get_int() + * @see vconf_keynode_get_dbl() + * @see keynode_t + * @see vconf_t */ int vconf_keynode_get_type(keynode_t *keynode); /** - * Get an integer value of key + * @brief Gets the integer value of a keynode. * - * @param[in] keynode Key node - * @return An integer value - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @param[in] keynode The Key + * + * @return The integer value, + * otherwise @c 0 if no value is obtained + * + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_str() + * @see vconf_keynode_get_dbl() + * @see keynode_t + * @see vconf_t */ int vconf_keynode_get_int(keynode_t *keynode); /** - * Get a double-precision float value of key + * @brief Gets the double value of a keynode. + * + * @since_tizen 2.3 + * + * @param[in] keynode The Key * - * @param[in] keynode Key node - * @return A double-precision float value - * @deprecated use buxton APIs + * @return The double value, + * otherwise @c 0.0 if no value is obtained + * + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_str() + * @see vconf_keynode_get_int() + * @see keynode_t + * @see vconf_t */ double vconf_keynode_get_dbl(keynode_t *keynode); /** - * Get a boolean value of key + * @brief Gets the boolean value of a keynode. + * + * @since_tizen 2.3 + * + * @param[in] keynode The Key + * + * @return The boolean value, + * otherwise @c -1 on error \n + * Integer value @c 1 is 'True', and @c 0 is 'False'. * - * @param[in] keynode Key node - * @return a boolean value - * @deprecated use buxton APIs + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_str() + * @see vconf_keynode_get_int() + * @see vconf_keynode_get_dbl() + * @see keynode_t + * @see vconf_t */ int vconf_keynode_get_bool(keynode_t *keynode); /** - * Get a string value of key + * @brief Gets the string value of a keynode. * - * @param[in] keynode Key node - * @return a string value - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @param[in] keynode The Key + * + * @return The string value, + * otherwise @c NULL if no value is obtained + * + * @see vconf_notify_key_changed() + * @see vconf_keynode_get_name() + * @see vconf_keynode_get_bool() + * @see vconf_keynode_get_type() + * @see vconf_keynode_get_int() + * @see vconf_keynode_get_dbl() + * @see keynode_t + * @see vconf_t */ char *vconf_keynode_get_str(keynode_t *keynode); + +/************************************************ + * keylist handling APIs + ************************************************/ + /** - * The type of function which is called when a key is changed + * @brief Allocates, initializes and returns a new keylist object. + * @details You must release the return value keylist_t* pointer using vconf_keylist_free(). * - * @param[in] keynode Key node - * @param[in] user_data data passed to callback function + * @since_tizen 2.3 + * + * @return The pointer of New keylist, + * otherwise @c NULL on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_new() + * @see vconf_keylist_free() */ -typedef void (*vconf_callback_fn)(keynode_t *keynode, void *user_data); +keylist_t *vconf_keylist_new(void); /** - * Add a callback function which is called when a key is changed + * @brief Moves the current keynode position to the first item. + * + * @since_tizen 2.3 * - * @param[in] key the name of key - * @param[in] cb callback function - * @param[in] user_data data passed to callback function - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @param[in] keylist The Key List + * + * @return @c 0 on success, + * otherwise -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_nextnode() + * @see vconf_keylist_rewind() + * @see vconf_keylist_nextnode() + * + * @par example + * @code + int r =0; + keylist_t* pKeyList = NULL; + pKeyList = vconf_keylist_new(); + + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r) { + tet_infoline("vconf_get() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + vconf_keylist_nextnode(pKeyList); + vconf_keylist_nextnode(pKeyList); + + // Move first position from KeyList + r = vconf_keylist_rewind(pKeyList); + if (r<0) { + tet_infoline("vconf_keylist_rewind() failed in positive test case"); + tet_result(TET_FAIL); + return; + } + + while(vconf_keylist_nextnode(pKeyList)) ; + * @endcode */ -int vconf_notify_key_changed(const char *key, vconf_callback_fn cb, - void *user_data); +int vconf_keylist_rewind(keylist_t *keylist); /** - * Remove a change callback function + * @brief Destroys a keylist. + * @details After calling vconf_keylist_new(), you must call this function to release internal memory. + * + * @since_tizen 2.3 + * + * @param[in] keylist The Key List * - * @param[in] key the name of key - * @param[in] cb callback function - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_new() */ -int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb); +int vconf_keylist_free(keylist_t *keylist); /** - * Set an integer value + * @brief Looks for a keynode contained in a keylist that matches the keyname. + * + * @since_tizen 2.3 + * + * @param[in] keylist The Key List + * @param[in] keyname The key to find + * @param[out] return_node The pointer of the keynode to set + * + * @return The type of the found key that is vconf_t enumeration value * - * @param[in] key the name of key - * @param[in] intval an integer value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @see vconf_set() + * @see vconf_get() + * @see keynode_t + * @see vconf_t + * @par example + * @code +#include +#include + +int main() +{ + int r = 0; + int nResult = 0; + keylist_t* pKeyList = NULL; + keynode_t *pKeyNode; + + pKeyList = vconf_keylist_new(); + r = vconf_get(pKeyList, KEY_PARENT, VCONF_GET_KEY); + if (r<0) { + printf("vconf_get() failed in positive test case"); + return -1; + } + + r = vconf_keylist_lookup(pKeyList, KEY_02, &pKeyNode); + if (r<0) { + printf("vconf_get() failed in positive test case"); + return -1; + } + + nResult = vconf_keynode_get_int(pKeyNode); + if(nResult !=KEY_02_INT_VALUE) + { + printf("vconf_get() failed in positive test case"); + return -1; + + } + + vconf_keylist_free(pKeyList); + return 0; +} + * @endcode */ -int vconf_set_int(const char *key, int intval); +int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, + keynode_t **return_node); /** - * Set a boolean value + * @brief Gets the next key in a keylist. + * @details The next key is known by the keylist internal cursor. * - * @param[in] key the name of key - * @param[in] boolval a boolean value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @param[in] keylist The Key List + * + * @return The next Keynode, + * otherwise @c NULL on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_rewind() + * @see vconf_keylist_nextnode() + * @see keynode_t */ -int vconf_set_bool(const char *key, int boolval); +keynode_t *vconf_keylist_nextnode(keylist_t *keylist); /** - * Set a string value + * @brief Appends a new keynode containing an integer value to a keylist. + * @details If the same keyname exists, the keynode will change. + * + * @since_tizen 2.3 + * + * @param[in] keylist The Key List + * @param[in] keyname The key + * @param[in] value The integer value * - * @param[in] key the name of key - * @param[in] strval a string value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @return The number of keynode included in the keylist, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() */ -int vconf_set_str(const char *key, const char *strval); +int vconf_keylist_add_int(keylist_t *keylist, const char *keyname, + const int value); /** - * Set a double-precision float value + * @brief Appends a new keynode containing a boolean value to a keylist. + * @details If the same keyname exist, the keynode will change. + * + * @since_tizen 2.3 + * + * @param[in] keylist The Key List + * @param[in] keyname The key + * @param[in] value The boolean value * - * @param[in] key the name of key - * @param[in] dblval a double value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @return The number of keynodes included in the keylist, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() */ -int vconf_set_dbl(const char *key, double dblval); +int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, + const int value); /** - * Get an integer value + * @brief Appends a new keynode containing a double value to a keylist. + * @details If the same keyname exist, the keynode will change. + * + * @since_tizen 2.3 * - * @param[in] key the name of key - * @param[out] intval a pointer to an integer value to be set - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @param[in] keylist The Key List + * @param[in] keyname The key + * @param[in] value The double value + * + * @return The number of the keynodes included in the keylist, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() */ -int vconf_get_int(const char *key, int *intval); +int vconf_keylist_add_dbl(keylist_t *keylist, const char *keyname, + const double value); /** - * Get a boolean value + * @brief Appends a new keynode containing a string to a keylist. + * @details If the same keyname exist, the keynode will change. + * + * @since_tizen 2.3 + * + * @remarks The size limit of value is 4K. * - * @param[in] key the name of key - * @param[out] boolval a pointer to a boolean value to be set - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @param[in] keylist The Key List + * @param[in] keyname The key + * @param[in] value The pointer of string value + * + * @return The number of keynodes included in the keylist, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() */ -int vconf_get_bool(const char *key, int *boolval); +int vconf_keylist_add_str(keylist_t *keylist, const char *keyname, + const char *value); /** - * Get a string value + * @brief Appends a new keynode to a keylist without a value. + * @details Uses for vconf_get(). + * + * @since_tizen 2.3 + * + * @param[in] keylist The Key List + * @param[in] keyname The key + * + * @return The number of the keynodes included in the keylist, + * otherwise @c -1 on error * - * @param[in] key the name of key - * @return a string on success (should be freed by free()), NULL on error - * @deprecated use buxton APIs + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() */ -char *vconf_get_str(const char *key); +int vconf_keylist_add_null(keylist_t *keylist, const char *keyname); /** - * Get a double-precision float value + * @brief Removes the keynode that matches the given keyname. * - * @param[in] key the name of key - * @param[out] dblval a pointer to a double value to be set - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @param[in] keylist The keylist containing the keyname + * @param[in] keyname The key + * + * @return @c 0 on success, + * @c -1 if invalid parameter), + * otherwise @c -2 (Not exist keyname in keylist) on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() */ -int vconf_get_dbl(const char *key, double *dblval); +int vconf_keylist_del(keylist_t *keylist, const char *keyname); + +/************************************************ + * setting APIs * + ************************************************/ /** - * Get an error code of the last API call + * @brief Sets the keys included in a keylist. + * @details If you use DB backend, the keylist is handled as one transaction. + * + * @since_tizen 2.3 + * + * @param[in] keylist The keylist which should contain changed keys + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_set() + * @see vconf_get() + * @see vconf_keylist_add_int() + * @see vconf_keylist_add_str() + * @see vconf_keylist_add_dbl() + * @see vconf_keylist_add_bool() + * @see vconf_keylist_del() + * @see vconf_keylist_add_null() * - * @return error code - * @deprecated use buxton APIs + * @par example + * @code +#include +#include + +int main() +{ + keylist_t *kl=NULL; + const char *keyname_list[3]={"db/test/key1", "db/test/key2", "db/test/key3"}; + + // Transaction Test(all or nothing is written) + kl = vconf_keylist_new(); + + vconf_keylist_add_int(kl, keyname_list[0], 1); + vconf_keylist_add_str(kl, keyname_list[1], "transaction Test"); + vconf_keylist_add_dbl(kl, keyname_list[2], 0.3); + if(vconf_set(kl)) + fprintf(stderr, "nothing is written\n"); + else + printf("everything is written\n"); + + vconf_keylist_free(kl); + + // You can set items which have different backend. + kl = vconf_keylist_new(); + + vconf_keylist_add_int(kl, "memory/a/xxx1", 4); + vconf_keylist_add_str(kl, "file/a/xxx2", "test 3"); + vconf_keylist_add_dbl(kl, "db/a/xxx3", 0.3); + vconf_set(kl) + + vconf_keylist_free(kl); + return 0; +} + * @endcode */ -int vconf_get_ext_errno(void); +int vconf_set(keylist_t *keylist); +/** + * @brief Sets the integer value of the given key. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[in] intval The integer value to set \n + * @c 0 is also allowed as a value. + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_set_bool() + * @see vconf_set_dbl() + * @see vconf_set_str() + */ +int vconf_set_int(const char *in_key, const int intval); /** - * keylist_t + * @brief Sets the boolean value of the given key. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[in] boolval The Boolean value( @c 1 or @c 0) to set + * Integer value @c 1 is 'True', and @c 0 is 'False'. + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_set_int() + * @see vconf_set_dbl() + * @see vconf_set_str() + * + * @par example + * @code +#include +#include + + const char *key1_name="memory/test/key1"; + + int main(int argc, char **argv) + { + int key1_value; + + if(vconf_set_bool(key1_name, 1)) + fprintf(stderr, "vconf_set_bool FAIL\n"); + else + printf("vconf_set_bool OK\n"); + + if(vconf_get_bool(key1_name, &key1_value)) + fprintf(stderr, "vconf_get_bool FAIL\n"); + else + printf("vconf_get_bool OK(key1 value is %d)\n", key1_value); + + return 0; + } + * @endcode */ -typedef struct _keylist_t keylist_t; +int vconf_set_bool(const char *in_key, const int boolval); /** - * Create a new keylist + * @brief Sets the double value of the given key. * - * @return keylist_t on success, NULL on error - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[in] dblval The double value to set \n + * @c 0.0 is also allowed as a value. + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_set_int() + * @see vconf_set_bool() + * @see vconf_set_str() */ -keylist_t *vconf_keylist_new(void); +int vconf_set_dbl(const char *in_key, const double dblval); /** - * Release a keylist + * @brief Sets the string value of the given key. * - * @param[in] keylist keylist_t to be freed - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @remarks The size limit of value is 4K. + * + * @param[in] in_key The key + * @param[in] strval The string value to set + * + * @return @c 0 on success, + * otherwise -1 on error + * + * @see vconf_set_bool() + * @see vconf_set_dbl() + * @see vconf_set_int() */ -int vconf_keylist_free(keylist_t *keylist); +int vconf_set_str(const char *in_key, const char *strval); + +/** + * @brief Gets the keys or subdirectory in in_parentDIR. + * @details If the keylist has any key information, vconf only retrieves the keys. + * This is not recursive. + * + * @since_tizen 2.3 + * + * @param[in] keylist The keylist created by vconf_keylist_new() + * @param[in] in_parentDIR The parent DIRECTORY of needed keys + * @param[in] option The options \n + * VCONF_GET_KEY|VCONF_GET_DIR|VCONF_GET_ALL + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @par example + * @code +#include +#include + +int main() +{ + keylist_t *kl=NULL; + keynode_t *temp_node; + const char *vconfkeys1="db/test/key1"; + const char *parent_dir="db/test"; + + kl = vconf_keylist_new(); + if(vconf_get(kl, parent_dir, 0)) + fprintf(stderr, "vconf_get FAIL(%s)", vconfkeys1); + else + printf("vconf_get OK(%s)", vconfkeys1); + + while((temp_node = vconf_keylist_nextnode(kl))) { + switch(vconf_keynode_get_type(temp_node)) { + case VCONF_TYPE_INT: + printf("key = %s, value = %d\n", + vconf_keynode_get_name(temp_node), vconf_keynode_get_int(temp_node)); + break; + case VCONF_TYPE_BOOL: + printf("key = %s, value = %d\n", + vconf_keynode_get_name(temp_node), vconf_keynode_get_bool(temp_node)); + break; + case VCONF_TYPE_DOUBLE: + printf("key = %s, value = %f\n", + vconf_keynode_get_name(temp_node), vconf_keynode_get_dbl(temp_node)); + break; + case VCONF_TYPE_STRING: + printf("key = %s, value = %s\n", + vconf_keynode_get_name(temp_node), vconf_keynode_get_str(temp_node)); + break; + default: + printf("Unknown Type\n"); + } + } + vconf_keylist_free(kl); +} + * @endcode + */ +int vconf_get(keylist_t *keylist, const char *in_parentDIR, get_option_t option); /** - * Add an integer type key to keylist + * @brief Gets the integer value of the given key. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[out] intval The output buffer + * + * @return @c 0 on success, + * otherwise @c -1 on error * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @param[in] value an integer value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @see vconf_get_bool() + * @see vconf_get_dbl() + * @see vconf_get_str() + * + * @par example + * @code +#include +#include + +const char *key1_name="db/test/key1"; + +int main(int argc, char **argv) +{ + int key1_value; + + if(vconf_set_int(key1_name,1)) + fprintf(stderr, "vconf_set_int FAIL\n"); + else + printf("vconf_set_int OK\n"); + + if(vconf_get_int(key1_name, &key1_value)) + fprintf(stderr, "vconf_get_int FAIL\n"); + else + printf("vconf_get_int OK(key1 value is %d)\n", key1_value); + + return 0; +} + * @endcode */ -int vconf_keylist_add_int(keylist_t *keylist, const char *keyname, int value); +int vconf_get_int(const char *in_key, int *intval); /** - * Add a boolean type key to keylist + * @brief Gets the boolean value (@c 1 or @c 0) of the given key. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[out] boolval The output buffer * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @param[in] value a boolean value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_get_int() + * @see vconf_get_dbl() + * @see vconf_get_str() */ -int vconf_keylist_add_bool(keylist_t *keylist, const char *keyname, int value); +int vconf_get_bool(const char *in_key, int *boolval); /** - * Add a double-precision float type key to keylist + * @brief Gets the double value of the given key. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[out] dblval The output buffer * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @param[in] value a double value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @see vconf_get_int() + * @see vconf_get_bool() + * @see vconf_get_str() */ -int vconf_keylist_add_dbl(keylist_t *keylist, - const char *keyname, double value); +int vconf_get_dbl(const char *in_key, double *dblval); /** - * Add a string type key to keylist + * @brief Gets the string value of the given key. + * @details You have to free this returned value. + * + * @since_tizen 2.3 * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @param[in] value a string value - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @param[in] in_key The key + * + * @return The allocated pointer of key value on success, + * otherwise @c NULL on error + * + * @see vconf_get_int() + * @see vconf_get_dbl() + * @see vconf_get_bool() + * + * @par example + * @code + #include + #include + + char *get_str=vconf_get_str("db/test/test1"); + if(get_str) { + printf("vconf_get_str OK(value = %s)", get_str); + free(get_str); + }else + fprintf(stderr, "vconf_get_str FAIL"); + * @endcode */ -int vconf_keylist_add_str(keylist_t *keylist, - const char *keyname, const char *value); +char *vconf_get_str(const char *in_key); /** - * Remove a key from keylist + * @brief Deletes the given key from the backend system. * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @since_tizen 2.3 + * + * @remarks Only root can unset value. + * If user unsets value with this api, it returns VCONF_ERROR_NOT_SUPPORTED. + * + * @param[in] in_key The key + * + * @return @c 0 on success, + * otherwise @c -1 on error */ -int vconf_keylist_del(keylist_t *keylist, const char *keyname); +int vconf_unset(const char *in_key); /** - * vconf_get options + * @brief Synchronizes the given key (only file backend) with the storage device. + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @par example + * @code + if(vconf_set_int("file/test/key1",1)) + fprintf(stderr, "vconf_set_int FAIL\n"); + else { + printf("vconf_set_int OK\n"); + vconf_sync_key("file/test/key1"); + } + * @endcode */ -enum get_option_t { - VCONF_GET_KEY = 0, /**< get keys */ - VCONF_GET_ALL, /**< get keys and directories */ - VCONF_GET_DIR, /**< get directories */ -}; -typedef enum get_option_t get_option_t; +int vconf_sync_key(const char *in_key); + +/** + * @brief Deletes all keys and directories below the given directory from the backend system. + * + * @since_tizen 2.3 + * + * @remarks Only root can unset value. + * If user unsets value with this api, it returns VCONF_ERROR_NOT_SUPPORTED. + * + * @param[in] in_dir The directory name for removal + * + * @return @c 0 on success, + * otherwise @c -1 on error + * + * @par example + * @code + vconf_set_int("db/test/key1",1); + vconf_set_int("db/test/test1/key1",1); + vconf_set_int("db/test/test2/key1",1); + vconf_set_int("db/test/key2",1); + + if(vconf_unset_recursive("db/test")) + fprintf(stderr, "vconf_unset_recursive FAIL\n"); + else + printf("vconf_unset_recursive OK(deleted db/test\n"); + + * @endcode + */ +int vconf_unset_recursive(const char *in_dir); /** - * Get keys in the in_parentDIR directory + * @brief Adds a change callback for the given key, which is called when the key is set or unset. + * @details The changed information (#keynode_t) of the key is delivered to #vconf_callback_fn, + * or if the key is deleted, the @link #keynode_t keynode @endlink has #VCONF_TYPE_NONE as type. + * + * @details Multiple vconf_callback_fn functions may exist for one key. + * + * @details The callback is issued in the context of the glib main loop. + * + * @since_tizen 2.3 + * + * @remarks: This callback mechanism DOES NOT GUARANTEE consistency of data change. For example, + * When you have a callback for a certain key, assume that two or more processes are trying to + * change the value of the key competitively. In this case, the callback function will always + * get the 'CURRENT' value, not the value which raised the notification and caused the callback call. + * So, do not use vconf callback when competitive write for a key is happening. In such case, use + * socket-based IPC (dbus or something else) instead. + * + * @param[in] in_key The key + * @param[in] cb The callback function + * @param[in] user_data The callback data + * + * @return @c 0 on success, + * otherwise @c -1 on error * - * @param[in] keylist keylist_t - * @param[in] in_parentDIR parent directory - * @param[in] option enum get_option_t - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @see vconf_ignore_key_changed + * + * @par example + * @code + void test_cb(keynode_t *key, void* data) + { + switch(vconf_keynode_get_type(key)) + { + case VCONF_TYPE_INT: + printf("key = %s, value = %d(int)\n", + vconf_keynode_get_name(key), vconf_keynode_get_int(key)); + break; + case VCONF_TYPE_BOOL: + printf("key = %s, value = %d(bool)\n", + vconf_keynode_get_name(key), vconf_keynode_get_bool(key)); + break; + case VCONF_TYPE_DOUBLE: + printf("key = %s, value = %f(double)\n", + vconf_keynode_get_name(key), vconf_keynode_get_dbl(key)); + break; + case VCONF_TYPE_STRING: + printf("key = %s, value = %s(string)\n", + vconf_keynode_get_name(key), vconf_keynode_get_str(key)); + break; + default: + fprintf(stderr, "Unknown Type(%d)\n", vconf_keynode_get_type(key)); + break; + } + return; + } + + int main() + { + int i; + GMainLoop *event_loop; + + g_type_init(); + + vconf_notify_key_changed("db/test/test1", test_cb, NULL); + + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + + vconf_ignore_key_changed("db/test/test1", test_cb); + return 0; + } + * @endcode */ -int vconf_get(keylist_t *keylist, - const char *in_parentDIR, get_option_t option); +int vconf_notify_key_changed(const char *in_key, vconf_callback_fn cb, + void *user_data); /** - * Set the keys in keylist + * @brief Removes a change callback for the given key, + * which was added by vconf_notify_key_changed(). + * + * @since_tizen 2.3 + * + * @param[in] in_key The key + * @param[in] cb The callback function + * + * @return @c 0 on success, + * otherwise @c -1 on error * - * @param[in] keylist keylist_t - * @return 0 on success, -1 on error - * @deprecated use buxton APIs + * @see vconf_notify_key_changed() */ -int vconf_set(keylist_t *keylist); +int vconf_ignore_key_changed(const char *in_key, vconf_callback_fn cb); /** - * Look for a keynode with keyname in keylist + * @brief Gets the most recent errno generated by the set/get API. + * @details If a prior API call failed but the most recent API call succeeded, + * the return value from vconf_get_ext_errno() will be VCONF_OK. + * + * @since_tizen 2.3 * - * @param[in] keylist keylist_t - * @param[in] keyname the name of key - * @param[out] return_node keynode which has the same keyname - * @return type of key which is found, 0 if there is no matched key - * @deprecated use buxton APIs - * @note return_node is included in keylist. Do not free. \n - * It is valid until keylist is freed. + * @return The most recent errno + */ +int vconf_get_ext_errno(void); + +/** + * @} */ -int vconf_keylist_lookup(keylist_t *keylist, const char *keyname, - keynode_t **return_node); #ifdef __cplusplus } #endif -#endif /* __VCONF_H__ */ + diff --git a/vconf-compat/vconf.sym b/vconf-compat/vconf.sym index a0f9e16..745cacf 100644 --- a/vconf-compat/vconf.sym +++ b/vconf-compat/vconf.sym @@ -23,9 +23,15 @@ VCONF_BUXTON_1.0 { vconf_keylist_add_bool; vconf_keylist_add_dbl; vconf_keylist_add_str; + vconf_keylist_add_null; vconf_keylist_del; + vconf_keylist_nextnode; + vconf_keylist_rewind; vconf_get; vconf_set; + vconf_unset; + vconf_unset_recursive; + vconf_sync_key; vconf_keylist_lookup; local: *;