Fixed errors when dynamic so file was created.
[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 static void system_setting_vconf_event_cb0(keynode_t *node, void *event_data)
86 {
87         system_settings_key_e pkey = (system_settings_key_e)event_data;
88
89         if (node != NULL) {
90                 system_setting_h system_setting_item;
91
92                 if (system_settings_get_item(pkey, &system_setting_item)) {
93                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
94                 }
95
96                 void *user_data = NULL;
97                 user_data = system_setting_item->user_data;
98                 system_setting_item->changed_cb(pkey, user_data);
99         }
100 }
101
102 static void system_setting_vconf_event_cb1(keynode_t *node, void *event_data)
103 {
104         system_settings_key_e pkey = (system_settings_key_e)event_data;
105
106         if (node != NULL) {
107                 system_setting_h system_setting_item;
108
109                 if (system_settings_get_item(pkey, &system_setting_item)) {
110                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
111                 }
112
113                 void *user_data = NULL;
114                 user_data = system_setting_item->user_data;
115                 system_setting_item->changed_cb(pkey, user_data);
116         }
117 }
118
119 static void system_setting_vconf_event_cb2(keynode_t *node, void *event_data)
120 {
121         system_settings_key_e pkey = (system_settings_key_e)event_data;
122
123         if (node != NULL) {
124                 system_setting_h system_setting_item;
125
126                 if (system_settings_get_item(pkey, &system_setting_item)) {
127                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
128                 }
129
130                 void *user_data = NULL;
131                 user_data = system_setting_item->user_data;
132                 system_setting_item->changed_cb(pkey, user_data);
133         }
134 }
135
136 static void system_setting_vconf_event_cb3(keynode_t *node, void *event_data)
137 {
138         system_settings_key_e pkey = (system_settings_key_e)event_data;
139
140         if (node != NULL) {
141                 system_setting_h system_setting_item;
142
143                 if (system_settings_get_item(pkey, &system_setting_item)) {
144                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
145                 }
146
147                 void *user_data = NULL;
148                 user_data = system_setting_item->user_data;
149                 system_setting_item->changed_cb(pkey, user_data);
150         }
151 }
152
153 static void system_setting_vconf_event_cb4(keynode_t *node, void *event_data)
154 {
155         system_settings_key_e pkey = (system_settings_key_e)event_data;
156
157         if (node != NULL) {
158                 system_setting_h system_setting_item;
159
160                 if (system_settings_get_item(pkey, &system_setting_item)) {
161                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
162                 }
163
164                 void *user_data = NULL;
165                 user_data = system_setting_item->user_data;
166                 system_setting_item->changed_cb(pkey, user_data);
167         }
168 }
169
170 static void system_setting_vconf_event_cb100(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                 if (system_settings_get_item(pkey, &system_setting_item)) {
178                         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
179                 }
180
181                 void *user_data = NULL;
182                 user_data = system_setting_item->user_data;
183                 system_setting_item->changed_cb(pkey, user_data);
184         }
185 }
186
187
188
189
190 static system_setting_vconf_event_cb system_setting_vconf_get_event_cb_slot(int slot)
191 {
192         switch (slot) {
193         case 0:
194                 return system_setting_vconf_event_cb0;
195
196         case 1:
197                 return system_setting_vconf_event_cb1;
198
199         case 2:
200                 return system_setting_vconf_event_cb2;
201
202         case 3:
203                 return system_setting_vconf_event_cb3;
204
205         case 4:
206                 return system_setting_vconf_event_cb4;
207         case 100:
208                 return system_setting_vconf_event_cb100;
209
210         default:
211                 return NULL;
212         }
213 }
214
215 int system_setting_vconf_set_changed_cb(const char *vconf_key, system_settings_key_e key, int slot, void *user_data)
216 {
217         system_setting_vconf_event_cb vconf_event_cb;
218
219         vconf_event_cb = system_setting_vconf_get_event_cb_slot(slot);
220
221         if (vconf_event_cb == NULL) {
222                 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_event_cb == 0");
223                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
224         }
225
226 #if 1
227         if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)key))
228 #else
229         if (vconf_notify_key_changed(vconf_key, vconf_event_cb, (void *)user_data))
230 #endif
231         {
232                 LOGE("[%s] INVALID_error , %s", __FUNCTION__, "vconf_notify_key_changed error");
233                 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
234         }
235
236         return SYSTEM_SETTINGS_ERROR_NONE;
237 }
238
239 int system_setting_vconf_unset_changed_cb(const char *vconf_key, int slot)
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                 vconf_ignore_key_changed(vconf_key, vconf_event_cb);
247         }
248
249         return SYSTEM_SETTINGS_ERROR_NONE;
250 }
251
252