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>
34 #define LOG_TAG "TIZEN_N_SYSTEM_SETTINGS"
36 #define SYSTEM_SETTINGS_MAX -1
40 system_setting_s system_setting_table[] = {
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,
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,
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,
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,
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,
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,
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,
112 SYSTEM_SETTINGS_MAX, -1, NULL, NULL, NULL, NULL, NULL
116 int system_settings_get_item(system_settings_key_e key, system_setting_h *item)
120 while (system_setting_table[index].key != SYSTEM_SETTINGS_MAX)
122 if (system_setting_table[index].key == key)
124 *item = &system_setting_table[index];
134 int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
136 system_setting_h system_setting_item;
137 system_setting_get_value_cb system_setting_getter;
139 if (system_settings_get_item(key, &system_setting_item))
141 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
142 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
145 if (system_setting_item->data_type != data_type)
147 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
148 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
151 system_setting_getter = system_setting_item->get_value_cb;
153 if (system_setting_getter == NULL)
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;
159 return system_setting_getter(key, system_setting_item->data_type, value);
162 int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
164 system_setting_h system_setting_item;
165 system_setting_set_value_cb system_setting_setter;
167 if (system_settings_get_item(key, &system_setting_item))
169 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
170 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
173 system_setting_setter = system_setting_item->set_value_cb;
175 if (system_setting_setter == NULL)
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;
181 return system_setting_setter(key, system_setting_item->data_type, value);
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)
187 // TODO: make sure the value is inside of enum.
189 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT,(void*)ptr);
192 int system_settings_get_value_int(system_settings_key_e key, int *value)
194 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void**)value);
197 int system_settings_set_value_bool(system_settings_key_e key, bool value)
200 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL,(void*)ptr);
203 int system_settings_get_value_bool(system_settings_key_e key, bool *value)
205 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void**)value);
208 int system_settings_set_value_double(system_settings_key_e key, double value)
210 double* ptr = &value;
211 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE,(void*)ptr);
214 int system_settings_get_value_double(system_settings_key_e key, double *value)
216 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE, (void**)value);
219 int system_settings_set_value_string(system_settings_key_e key, const char *value)
221 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING,(void*)value);
224 int system_settings_get_value_string(system_settings_key_e key, char **value)
226 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void**)value);
232 - system_settings_set_changed_cb
233 -> int (*system_setting_set_changed_callback_cb)(key, callback, user_data)
237 int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
239 system_setting_h system_setting_item;
240 system_setting_set_changed_callback_cb system_setting_set_changed_cb;
242 if (system_settings_get_item(key, &system_setting_item))
244 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
245 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
248 system_setting_set_changed_cb = system_setting_item->set_changed_cb;
250 // Store the callback function from application side
252 system_setting_item->changed_cb = callback;
254 if (system_setting_set_changed_cb == NULL)
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;
260 return system_setting_set_changed_cb(key, callback, user_data);
264 int system_settings_unset_changed_cb(system_settings_key_e key)
266 system_setting_h system_setting_item;
267 system_setting_unset_changed_callback_cb system_setting_unset_changed_cb;
269 if (system_settings_get_item(key, &system_setting_item))
271 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
272 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
275 system_setting_unset_changed_cb = system_setting_item->unset_changed_cb;
277 // free the callback function from application side
278 if (system_setting_item->changed_cb)
279 system_setting_item->changed_cb = NULL;
280 //-----------------------------------------------------
282 if (system_setting_unset_changed_cb == NULL)
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;
288 return system_setting_unset_changed_cb(key);