From fadbde1d9dd18320a2a7506da7a58d7903a7d3b7 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Fri, 14 Oct 2016 15:51:09 +0900 Subject: [PATCH] Revert "Revert "share buxton connection in vconf get/set api"" This reverts commit c84229499da8c0583d9d53f3647e792c98e440ec. Change-Id: Ib1bb601b255de1bce4e3ce6a1e20d6d0893f8519 Signed-off-by: Jiwoong Im --- vconf-compat/vconf.c | 155 ++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 83 deletions(-) diff --git a/vconf-compat/vconf.c b/vconf-compat/vconf.c index 27ce2c2..e49e644 100644 --- a/vconf-compat/vconf.c +++ b/vconf-compat/vconf.c @@ -43,7 +43,7 @@ static pthread_mutex_t vconf_lock = PTHREAD_MUTEX_INITIALIZER; static int _refcnt; -static struct buxton_client *noti_client; +static struct buxton_client *client; static struct buxton_layer *system_layer; static struct buxton_layer *memory_layer; static GHashTable *noti_tbl; @@ -183,7 +183,7 @@ static void free_noti(struct noti *noti) free(noti); } -static void _close_for_noti(void) +static void _close(void) { _refcnt--; if (_refcnt) { @@ -199,11 +199,11 @@ static void _close_for_noti(void) g_hash_table_destroy(noti_tbl); noti_tbl = NULL; - buxton_close(noti_client); - noti_client = NULL; + buxton_close(client); + client = NULL; } -static int _open_for_noti(void) +static int _open(void) { int r; @@ -212,7 +212,7 @@ static int _open_for_noti(void) return 0; } - r = buxton_open(¬i_client, NULL, NULL); + r = buxton_open(&client, NULL, NULL); if (r == -1) { LOGE("Can't connect to buxton: %d", errno); return -1; @@ -227,31 +227,6 @@ static int _open_for_noti(void) return 0; } -static void _close(struct buxton_client *client, struct buxton_layer *layer) -{ - buxton_free_layer(layer); - buxton_close(client); -} - -static int _open(const char *key, struct buxton_client **client, - struct buxton_layer **layer) -{ - int r; - - r = buxton_open_full(client, false, NULL, NULL); - if (r == -1) { - LOGE("Can't connect to buxton: %d", errno); - return -1; - } - - if (key && !strncmp(key, "memory/", strlen("memory/"))) - *layer = buxton_create_layer("memory"); - else - *layer = buxton_create_layer("system"); - - return 0; -} - static void to_vconf_t(const struct buxton_value *val, keynode_t *node) { int r; @@ -486,7 +461,7 @@ EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb, } pthread_mutex_lock(&vconf_lock); - r = _open_for_noti(); + r = _open(); if (r == -1) { pthread_mutex_unlock(&vconf_lock); return -1; @@ -496,11 +471,11 @@ EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb, if (!noti) { noti = create_noti(key, cb, user_data); if (!noti) { - _close_for_noti(); + _close(); pthread_mutex_unlock(&vconf_lock); return -1; } - r = buxton_register_notification_sync(noti_client, get_layer(key), key, + r = buxton_register_notification_sync(client, get_layer(key), key, notify_cb, NULL); if (r == -1) { LOGE("vconf_notify_key_changed: key '%s' add notify error %d", @@ -509,12 +484,12 @@ EXPORT int vconf_notify_key_changed(const char *key, vconf_callback_fn cb, } /* increase reference count */ if (r == 0) - _open_for_noti(); + _open(); } else { r = add_noti(noti, cb, user_data); } - _close_for_noti(); + _close(); pthread_mutex_unlock(&vconf_lock); if (r == 0) @@ -581,7 +556,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb) return 0; } - r = buxton_unregister_notification_sync(noti_client, get_layer(key), + r = buxton_unregister_notification_sync(client, get_layer(key), key, notify_cb); if (r == -1) LOGE("unregister error '%s' %d", noti->key, errno); @@ -591,7 +566,7 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb) g_hash_table_remove(noti_tbl, key); /* decrease reference count */ - _close_for_noti(); + _close(); pthread_mutex_unlock(&vconf_lock); return 0; @@ -600,21 +575,23 @@ EXPORT int vconf_ignore_key_changed(const char *key, vconf_callback_fn cb) static int _vconf_set(const char *key, const struct buxton_value *val) { int r; - struct buxton_client *client; - struct buxton_layer *layer; assert(key); assert(val); - r = _open(key, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_set_value_sync(client, layer, key, val); + r = buxton_set_value_sync(client, get_layer(key), key, val); if (r == -1) LOGE("set value: key '%s' errno %d", key, errno); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return r; } @@ -719,18 +696,19 @@ static int _vconf_get(const char *key, enum buxton_key_type type, struct buxton_value **val) { int r; - struct buxton_client *client; - struct buxton_layer *layer; struct buxton_value *v; assert(key); assert(val); - r = _open(key, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_get_value_sync(client, layer, key, &v); + r = buxton_get_value_sync(client, get_layer(key), key, &v); if (r == -1) { LOGE("get value: key '%s' errno %d", key, errno); } else { @@ -749,7 +727,8 @@ static int _vconf_get(const char *key, enum buxton_key_type type, } } - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return r; } @@ -1201,19 +1180,16 @@ static int set_keynode_value(struct buxton_value *v, struct _keynode_t *keynode) return r; } -static struct _keynode_t *alloc_keynode(struct buxton_client *client, - struct buxton_layer *layer, - const char *keyname) +static struct _keynode_t *alloc_keynode(const char *keyname) { int r; struct buxton_value *v; struct _keynode_t *keynode; assert(client); - assert(layer); assert(keyname); - r = buxton_get_value_sync(client, layer, keyname, &v); + r = buxton_get_value_sync(client, get_layer(keyname), keyname, &v); if (r == -1) { LOGE("get value: key '%s' errno %d", keyname, errno); return NULL; @@ -1252,8 +1228,6 @@ EXPORT int vconf_get(keylist_t *keylist, unsigned int len; int i; int dirlen; - struct buxton_client *client; - struct buxton_layer *layer; if (!keylist || !in_parentDIR) { errno = EINVAL; @@ -1266,14 +1240,18 @@ EXPORT int vconf_get(keylist_t *keylist, return -1; } - r = _open(in_parentDIR, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_list_keys_sync(client, layer, &names, &len); + r = buxton_list_keys_sync(client, get_layer(in_parentDIR), &names, &len); if (r == -1) { LOGE("get key list: errno %d", errno); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return -1; } @@ -1286,14 +1264,15 @@ EXPORT int vconf_get(keylist_t *keylist, if (strncmp(in_parentDIR, names[i], dirlen)) continue; - keynode = alloc_keynode(client, layer, names[i]); + keynode = alloc_keynode(names[i]); if (keynode) keylist->list = g_list_append(keylist->list, keynode); } buxton_free_keys(names); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return 0; } @@ -1339,8 +1318,6 @@ EXPORT int vconf_set(keylist_t *keylist) EXPORT int vconf_unset(const char *in_key) { int r; - struct buxton_client *client; - struct buxton_layer *layer; if (getuid() != 0) return VCONF_ERROR_NOT_SUPPORTED; @@ -1351,15 +1328,19 @@ EXPORT int vconf_unset(const char *in_key) return -1; } - r = _open(in_key, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_unset_value_sync(client, layer, in_key); + 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(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); /* LCOV_EXCL_STOP */ return r; @@ -1372,8 +1353,6 @@ EXPORT int vconf_unset_recursive(const char *in_dir) int dirlen; char **names; unsigned int len; - struct buxton_client *client; - struct buxton_layer *layer; if (getuid() != 0) return VCONF_ERROR_NOT_SUPPORTED; @@ -1390,14 +1369,18 @@ EXPORT int vconf_unset_recursive(const char *in_dir) return -1; } - r = _open(in_dir, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_list_keys_sync(client, layer, &names, &len); + r = buxton_list_keys_sync(client, get_layer(in_dir), &names, &len); if (r == -1) { LOGE("get key list: errno %d", errno); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return -1; } @@ -1405,16 +1388,20 @@ EXPORT int vconf_unset_recursive(const char *in_dir) if (strncmp(in_dir, names[i], dirlen)) continue; + pthread_mutex_unlock(&vconf_lock); r = vconf_unset(names[i]); + pthread_mutex_lock(&vconf_lock); if (r == -1) { buxton_free_keys(names); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return -1; } } buxton_free_keys(names); - _close(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); /* LCOV_EXCL_STOP */ return 0; @@ -1423,24 +1410,26 @@ EXPORT int vconf_unset_recursive(const char *in_dir) EXPORT int vconf_sync_key(const char *in_key) { int r; - struct buxton_client *client; - struct buxton_layer *layer; struct buxton_value *v; assert(in_key); - r = _open(in_key, &client, &layer); - if (r == -1) + pthread_mutex_lock(&vconf_lock); + r = _open(); + if (r == -1) { + pthread_mutex_unlock(&vconf_lock); return -1; + } - r = buxton_get_value_sync(client, layer, in_key, &v); + 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(client, layer); + _close(); + pthread_mutex_unlock(&vconf_lock); return r; } -- 2.7.4