2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <system_settings.h>
25 #include <system_settings_private.h>
31 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
34 int system_setting_vconf_get_value_int(const char *vconf_key, int *value)
36 return vconf_get_int(vconf_key, value);
39 int system_setting_vconf_get_value_bool(const char *vconf_key, bool *value)
42 int ret = vconf_get_bool(vconf_key, &tempvalue);
52 int system_setting_vconf_get_value_string(const char *vconf_key, char **value)
54 char *str_value = NULL;
56 str_value = vconf_get_str(vconf_key);
58 if (str_value != NULL) {
66 int system_setting_vconf_set_value_int(const char *vconf_key, int value)
68 return vconf_set_int(vconf_key, value);
71 int system_setting_vconf_set_value_bool(const char *vconf_key, bool value)
73 return vconf_set_bool(vconf_key, (int)value);
76 int system_setting_vconf_set_value_string(const char *vconf_key, char *value)
78 return vconf_set_str(vconf_key, value);
81 /*/////////////////////////////////////////////////////////////////////////////////////////// */
83 typedef void (*system_setting_vconf_event_cb)(keynode_t *node, void *event_data);
86 static void system_setting_vconf_event_cb0(keynode_t *node, void *event_data)
88 system_settings_key_e pkey = (system_settings_key_e)event_data;
91 system_setting_h system_setting_item;
93 int ret = system_settings_get_item(pkey, &system_setting_item);
95 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
96 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
99 void *user_data = NULL;
100 user_data = system_setting_item->user_data;
101 system_setting_item->changed_cb(pkey, user_data);
106 /* LCOV_EXCL_START */
107 static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
109 system_settings_key_e pkey = (system_settings_key_e)event_data;
112 system_setting_h system_setting_item;
114 int ret = system_settings_get_item(pkey, &system_setting_item);
116 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
117 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
120 void *user_data = NULL;
121 user_data = system_setting_item->user_data;
122 system_setting_item->changed_cb(pkey, user_data);
127 /* LCOV_EXCL_START */
128 static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
130 system_settings_key_e pkey = (system_settings_key_e)event_data;
133 system_setting_h system_setting_item;
135 int ret = system_settings_get_item(pkey, &system_setting_item);
137 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
138 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
141 void *user_data = NULL;
142 user_data = system_setting_item->user_data;
143 system_setting_item->changed_cb(pkey, user_data);
148 /* LCOV_EXCL_START */
149 static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
151 system_settings_key_e pkey = (system_settings_key_e)event_data;
154 system_setting_h system_setting_item;
156 int ret = system_settings_get_item(pkey, &system_setting_item);
158 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
159 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
162 void *user_data = NULL;
163 user_data = system_setting_item->user_data;
164 system_setting_item->changed_cb(pkey, user_data);
169 /* LCOV_EXCL_START */
170 static void system_setting_vconf_event_cb4(keynode_t *node, void *event_data)
172 system_settings_key_e pkey = (system_settings_key_e)event_data;
175 system_setting_h system_setting_item;
177 int ret = system_settings_get_item(pkey, &system_setting_item);
179 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
180 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
183 void *user_data = NULL;
184 user_data = system_setting_item->user_data;
185 system_setting_item->changed_cb(pkey, user_data);
190 /* LCOV_EXCL_START */
191 static void system_setting_vconf_event_cb100(keynode_t *node, void *event_data)
193 system_settings_key_e pkey = (system_settings_key_e)event_data;
196 system_setting_h system_setting_item;
198 int ret = system_settings_get_item(pkey, &system_setting_item);
200 if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
201 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
204 void *user_data = NULL;
205 user_data = system_setting_item->user_data;
206 system_setting_item->changed_cb(pkey, user_data);
212 /* LCOV_EXCL_START */
213 static system_setting_vconf_event_cb system_setting_vconf_get_event_cb_slot(int slot)
217 return system_setting_vconf_event_cb0;
220 return system_setting_vconf_event_cb1;
223 return system_setting_vconf_event_cb2;
226 return system_setting_vconf_event_cb3;
229 return system_setting_vconf_event_cb4;
231 return system_setting_vconf_event_cb100;
239 int system_setting_vconf_set_changed_cb(const char *vconf_key, system_settings_key_e key, int slot, void *user_data)
241 system_setting_vconf_event_cb vconf_event_cb;
243 vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
245 if (vconf_event_cb == NULL) {
246 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_event_cb == 0");
247 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
251 if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key))
253 if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)user_data))
256 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_notify_key_changed error");
257 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
260 return SYSTEM_SETTINGS_ERROR_NONE;
263 int system_setting_vconf_unset_changed_cb(const char *vconf_key, int slot)
265 system_setting_vconf_event_cb vconf_event_cb;
267 vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
269 if (vconf_event_cb != NULL) {
270 vconf_ignore_key_changed(vconf_key, vconf_event_cb);
273 return SYSTEM_SETTINGS_ERROR_NONE;