removed the log message functions
[framework/api/system-settings.git] / src / system_settings.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 #include <glib.h>
28
29
30 #ifdef LOG_TAG
31 #undef LOG_TAG
32 #endif
33
34 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
35
36 #define SYSTEM_SETTINGS_MAX -1
37
38
39
40 system_setting_s system_setting_table[] = {
41
42         {
43                 SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE,
44                 SYSTEM_SETTING_DATA_TYPE_STRING,
45                 system_setting_get_incoming_call_ringtone,
46                 system_setting_set_incoming_call_ringtone,
47                 system_setting_set_changed_callback_incoming_call_ringtone,
48                 system_setting_unset_changed_callback_incoming_call_ringtone,
49                 NULL
50         }, 
51
52         {
53                 SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN,
54                 SYSTEM_SETTING_DATA_TYPE_STRING,
55                 system_setting_get_wallpaper_home_screen,
56                 system_setting_set_wallpaper_home_screen,
57                 system_setting_set_changed_callback_wallpaper_home_screen,
58                 system_setting_unset_changed_callback_wallpaper_home_screen,
59                 NULL
60         },
61
62         {
63                 SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN,
64                 SYSTEM_SETTING_DATA_TYPE_STRING,
65                 system_setting_get_wallpaper_lock_screen,
66                 system_setting_set_wallpaper_lock_screen,
67                 system_setting_set_changed_callback_wallpaper_lock_screen,
68                 system_setting_unset_changed_callback_wallpaper_lock_screen,
69                 NULL
70         },
71
72         {
73                 SYSTEM_SETTINGS_KEY_FONT_SIZE,
74                 SYSTEM_SETTING_DATA_TYPE_INT,
75                 system_setting_get_font_size,
76                 system_setting_set_font_size,
77                 system_setting_set_changed_callback_font_size,
78                 system_setting_unset_changed_callback_font_size,
79                 NULL
80         },
81
82         {
83                 SYSTEM_SETTINGS_KEY_FONT_TYPE,
84                 SYSTEM_SETTING_DATA_TYPE_STRING,
85                 system_setting_get_font_type,
86                 system_setting_set_font_type,
87                 system_setting_set_changed_callback_font_type,
88                 system_setting_unset_changed_callback_font_type,
89                 NULL
90         },
91
92         {
93                 SYSTEM_SETTINGS_KEY_MOTION_ACTIVATION,
94                 SYSTEM_SETTING_DATA_TYPE_BOOL,
95                 system_setting_get_motion_activation,
96                 system_setting_set_motion_activation,
97                 system_setting_set_changed_callback_motion_activation,
98                 system_setting_unset_changed_callback_motion_activation,
99                 NULL
100         },
101
102         {
103                 SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE,
104                 SYSTEM_SETTING_DATA_TYPE_STRING,
105                 system_setting_get_email_alert_ringtone,
106                 system_setting_set_email_alert_ringtone,
107                 system_setting_set_changed_callback_email_alert_ringtone,
108                 system_setting_unset_changed_callback_email_alert_ringtone,
109                 NULL
110         },
111         {
112                 SYSTEM_SETTINGS_MAX, -1, NULL, NULL, NULL, NULL, NULL
113         }
114 };
115
116 int system_settings_get_item(system_settings_key_e key, system_setting_h *item)
117 {
118     int index = 0;
119
120     while (system_setting_table[index].key != SYSTEM_SETTINGS_MAX)
121     {   
122         if (system_setting_table[index].key == key)
123         {   
124             *item = &system_setting_table[index];
125             return 0;
126         }   
127
128         index++;
129     }   
130
131     return -1; 
132 }
133
134 int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
135 {
136     system_setting_h system_setting_item;
137         system_setting_get_value_cb     system_setting_getter;
138
139     if (system_settings_get_item(key, &system_setting_item))
140     {
141         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
142         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
143     }
144
145     if (system_setting_item->data_type != data_type)
146     {
147         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
148         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
149     }
150
151     system_setting_getter = system_setting_item->get_value_cb;
152
153     if (system_setting_getter == NULL)
154     {
155         LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
156         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
157     }
158
159     return system_setting_getter(key, system_setting_item->data_type, value);
160 }
161
162 int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
163 {
164         system_setting_h system_setting_item;
165         system_setting_set_value_cb     system_setting_setter;
166
167     if (system_settings_get_item(key, &system_setting_item))
168     {
169         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
170         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
171     }
172
173     system_setting_setter = system_setting_item->set_value_cb;
174
175     if (system_setting_setter == NULL)
176     {
177         LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
178         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
179     }
180
181     return system_setting_setter(key, system_setting_item->data_type, value);
182 }
183
184 // typedef int (*system_setting_set_value_cb) (system_settings_key_e key, system_setting_data_type_e data_type, void* value);
185 int system_settings_set_value_int(system_settings_key_e key, int value)
186 {
187         // TODO: make sure the value is inside of enum.
188         int* ptr = &value;
189         return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT,(void*)ptr);
190 }
191
192 int system_settings_get_value_int(system_settings_key_e key, int *value)
193 {
194         return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void**)value);
195 }
196
197 int system_settings_set_value_bool(system_settings_key_e key, bool value)
198 {
199         bool* ptr = &value;
200         return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL,(void*)ptr);
201 }
202
203 int system_settings_get_value_bool(system_settings_key_e key, bool *value)
204 {
205         return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void**)value);
206 }
207
208 int system_settings_set_value_double(system_settings_key_e key, double value)
209 {
210         double* ptr = &value;
211         return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE,(void*)ptr);
212 }
213
214 int system_settings_get_value_double(system_settings_key_e key, double *value)
215 {
216         return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE, (void**)value);
217 }
218
219 int system_settings_set_value_string(system_settings_key_e key, const char *value)
220 {
221         return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING,(void*)value);
222 }
223
224 int system_settings_get_value_string(system_settings_key_e key, char **value)
225 {
226         return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void**)value);
227 }
228
229
230 /*
231         - START
232                 - system_settings_set_changed_cb
233                         -> int (*system_setting_set_changed_callback_cb)(key, callback, user_data)
234 */
235
236 /*PUBLIC*/
237 int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
238 {
239     system_setting_h system_setting_item;
240         system_setting_set_changed_callback_cb system_setting_set_changed_cb;
241
242     if (system_settings_get_item(key, &system_setting_item))
243     {
244         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
245         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
246     }
247
248         system_setting_set_changed_cb = system_setting_item->set_changed_cb;
249
250         // Store the callback function from application side
251         if (callback)
252                 system_setting_item->changed_cb = callback;
253
254     if (system_setting_set_changed_cb == NULL)
255     {
256         LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
257         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
258     }
259
260         return system_setting_set_changed_cb(key, callback, user_data);
261 }
262
263
264 int system_settings_unset_changed_cb(system_settings_key_e key)
265 {
266     system_setting_h system_setting_item;
267         system_setting_unset_changed_callback_cb system_setting_unset_changed_cb;
268
269     if (system_settings_get_item(key, &system_setting_item))
270     {
271         LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
272         return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
273     }
274
275         system_setting_unset_changed_cb = system_setting_item->unset_changed_cb;
276
277         // free the callback function from application side
278         if (system_setting_item->changed_cb)
279                 system_setting_item->changed_cb = NULL;
280         //-----------------------------------------------------
281
282     if (system_setting_unset_changed_cb == NULL)
283     {
284         LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
285         return SYSTEM_SETTINGS_ERROR_IO_ERROR;
286     }
287
288         return system_setting_unset_changed_cb(key);
289 }
290