Modified SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE list test case
[platform/core/api/system-settings.git] / src / system_settings_vconf.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20
21 #include <vconf.h>
22 #include <dlog.h>
23
24 #include <system_settings.h>
25 #include <system_settings_private.h>
26
27 #ifdef LOG_TAG
28 #undef LOG_TAG
29 #endif
30
31 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
32
33
34 int system_setting_vconf_get_value_int(const char *vconf_key, int *value)
35 {
36         return vconf_get_int(vconf_key, value);
37 }
38
39 int system_setting_vconf_get_value_bool(const char *vconf_key, bool *value)
40 {
41         int tempvalue = 0;
42         int ret = vconf_get_bool(vconf_key, &tempvalue);
43
44         if (tempvalue == 1) {
45                 *value = true;
46         } else {
47                 *value = false;
48         }
49         return ret;
50 }
51
52 int system_setting_vconf_get_value_string(const char *vconf_key, char **value)
53 {
54         char *str_value = NULL;
55
56         str_value = vconf_get_str(vconf_key);
57
58         if (str_value != NULL) {
59                 *value = str_value;
60                 return 0;
61         } else {
62                 return -1;
63         }
64 }
65
66 int system_setting_vconf_set_value_int(const char *vconf_key, int value)
67 {
68         return vconf_set_int(vconf_key, value);
69 }
70
71 int system_setting_vconf_set_value_bool(const char *vconf_key, bool value)
72 {
73         return vconf_set_bool(vconf_key, (int)value);
74 }
75
76 int system_setting_vconf_set_value_string(const char *vconf_key, char *value)
77 {
78         return vconf_set_str(vconf_key, value);
79 }
80
81 /*/////////////////////////////////////////////////////////////////////////////////////////// */
82
83 typedef void (*system_setting_vconf_event_cb)(keynode_t *node, void *event_data);
84
85 /*  LCOV_EXCL_START */
86 static void system_setting_vconf_event_cb0(keynode_t *node, void *event_data)
87 {
88         system_settings_key_e pkey = (system_settings_key_e)event_data;
89
90         if (node != NULL) {
91                 system_setting_h system_setting_item;
92
93                 int ret = system_settings_get_item(pkey, &system_setting_item);
94                 if (ret != 0) {
95                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
96                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
97                 }
98
99                 void *user_data = NULL;
100                 user_data = system_setting_item->user_data;
101                 system_setting_item->changed_cb(pkey, user_data);
102         }
103 }
104 /*  LCOV_EXCL_STOP */
105
106 /*  LCOV_EXCL_START */
107 static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
108 {
109         system_settings_key_e pkey = (system_settings_key_e)event_data;
110
111         if (node != NULL) {
112                 system_setting_h system_setting_item;
113
114                 int ret = system_settings_get_item(pkey, &system_setting_item);
115                 if (ret != 0) {
116                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
117                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
118                 }
119
120                 void *user_data = NULL;
121                 user_data = system_setting_item->user_data;
122                 system_setting_item->changed_cb(pkey, user_data);
123         }
124 }
125 /*  LCOV_EXCL_STOP */
126
127 /*  LCOV_EXCL_START */
128 static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
129 {
130         system_settings_key_e pkey = (system_settings_key_e)event_data;
131
132         if (node != NULL) {
133                 system_setting_h system_setting_item;
134
135                 int ret = system_settings_get_item(pkey, &system_setting_item);
136                 if (ret != 0) {
137                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
138                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
139                 }
140
141                 void *user_data = NULL;
142                 user_data = system_setting_item->user_data;
143                 system_setting_item->changed_cb(pkey, user_data);
144         }
145 }
146 /*  LCOV_EXCL_STOP */
147
148 /*  LCOV_EXCL_START */
149 static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
150 {
151         system_settings_key_e pkey = (system_settings_key_e)event_data;
152
153         if (node != NULL) {
154                 system_setting_h system_setting_item;
155
156                 int ret = system_settings_get_item(pkey, &system_setting_item);
157                 if (ret != 0) {
158                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
159                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
160                 }
161
162                 void *user_data = NULL;
163                 user_data = system_setting_item->user_data;
164                 system_setting_item->changed_cb(pkey, user_data);
165         }
166 }
167 /*  LCOV_EXCL_STOP */
168
169 /*  LCOV_EXCL_START */
170 static void system_setting_vconf_event_cb4(keynode_t *node, void *event_data)
171 {
172         system_settings_key_e pkey = (system_settings_key_e)event_data;
173
174         if (node != NULL) {
175                 system_setting_h system_setting_item;
176
177                 int ret = system_settings_get_item(pkey, &system_setting_item);
178                 if (ret != 0) {
179                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
180                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
181                 }
182
183                 void *user_data = NULL;
184                 user_data = system_setting_item->user_data;
185                 system_setting_item->changed_cb(pkey, user_data);
186         }
187 }
188 /*  LCOV_EXCL_STOP */
189
190 /*  LCOV_EXCL_START */
191 static void system_setting_vconf_event_cb100(keynode_t *node, void *event_data)
192 {
193         system_settings_key_e pkey = (system_settings_key_e)event_data;
194
195         if (node != NULL) {
196                 system_setting_h system_setting_item;
197
198                 int ret = system_settings_get_item(pkey, &system_setting_item);
199                 if (ret != 0) {
200                         if (ret == SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER)
201                                 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
202                 }
203
204                 void *user_data = NULL;
205                 user_data = system_setting_item->user_data;
206                 system_setting_item->changed_cb(pkey, user_data);
207         }
208 }
209 /*  LCOV_EXCL_STOP */
210
211
212 /*  LCOV_EXCL_START */
213 static system_setting_vconf_event_cb system_setting_vconf_get_event_cb_slot(int slot)
214 {
215         switch (slot) {
216         case 0:
217                 return system_setting_vconf_event_cb0;
218
219         case 1:
220                 return system_setting_vconf_event_cb1;
221
222         case 2:
223                 return system_setting_vconf_event_cb2;
224
225         case 3:
226                 return system_setting_vconf_event_cb3;
227
228         case 4:
229                 return system_setting_vconf_event_cb4;
230         case 100:
231                 return system_setting_vconf_event_cb100;
232
233         default:
234                 return NULL;
235         }
236 }
237 /*  LCOV_EXCL_STOP */
238
239 int system_setting_vconf_set_changed_cb(const char *vconf_key, system_settings_key_e key, int slot, void *user_data)
240 {
241         system_setting_vconf_event_cb vconf_event_cb;
242
243         vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
244
245         if (vconf_event_cb == NULL) {
246                 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_event_cb == 0");
247                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
248         }
249
250 #if 1
251         if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key))
252 #else
253         if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)user_data))
254 #endif
255         {
256                 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_notify_key_changed error");
257                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
258         }
259
260         return SYSTEM_SETTINGS_ERROR_NONE;
261 }
262
263 int system_setting_vconf_unset_changed_cb(const char *vconf_key, int slot)
264 {
265         system_setting_vconf_event_cb vconf_event_cb;
266
267         vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
268
269         if (vconf_event_cb != NULL) {
270                 vconf_ignore_key_changed(vconf_key, vconf_event_cb);
271         }
272
273         return SYSTEM_SETTINGS_ERROR_NONE;
274 }
275
276