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 printf("assigned getter \n");
152 system_setting_getter = system_setting_item->get_value_cb;
154 if (system_setting_getter == NULL)
156 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
157 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
160 return system_setting_getter(key, system_setting_item->data_type, value);
163 int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
165 system_setting_h system_setting_item;
166 system_setting_set_value_cb system_setting_setter;
168 if (system_settings_get_item(key, &system_setting_item))
170 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
171 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
174 printf("assigned setter \n");
175 system_setting_setter = system_setting_item->set_value_cb;
177 if (system_setting_setter == NULL)
179 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
180 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
183 return system_setting_setter(key, system_setting_item->data_type, value);
186 // typedef int (*system_setting_set_value_cb) (system_settings_key_e key, system_setting_data_type_e data_type, void* value);
187 int system_settings_set_value_int(system_settings_key_e key, int value)
189 printf("[MOCK] system_settings_set_value_int - value = %d \n", value);
191 // TODO: make sure the value is inside of enum.
193 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT,(void*)ptr);
196 int system_settings_get_value_int(system_settings_key_e key, int *value)
198 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void**)value);
201 int system_settings_set_value_bool(system_settings_key_e key, bool value)
203 printf("[MOCK] system_settings_set_value_bool - value = %d \n", value);
205 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL,(void*)ptr);
208 int system_settings_get_value_bool(system_settings_key_e key, bool *value)
210 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void**)value);
213 int system_settings_set_value_double(system_settings_key_e key, double value)
215 printf("[MOCK] system_settings_set_value_double - value = %f \n", value);
216 double* ptr = &value;
217 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE,(void*)ptr);
220 int system_settings_get_value_double(system_settings_key_e key, double *value)
222 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE, (void**)value);
225 int system_settings_set_value_string(system_settings_key_e key, const char *value)
227 printf("[MOCK] system_settings_set_value_string - input string : %s \n", value);
228 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING,(void*)value);
231 int system_settings_get_value_string(system_settings_key_e key, char **value)
233 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void**)value);
239 - system_settings_set_changed_cb
240 -> int (*system_setting_set_changed_callback_cb)(key, callback, user_data)
244 int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
246 printf("system_settings_set_changed_cb \n");
248 system_setting_h system_setting_item;
249 system_setting_set_changed_callback_cb system_setting_set_changed_cb;
251 if (system_settings_get_item(key, &system_setting_item))
253 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
254 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
257 system_setting_set_changed_cb = system_setting_item->set_changed_cb;
259 // Store the callback function from application side
261 system_setting_item->changed_cb = callback;
263 if (system_setting_set_changed_cb == NULL)
265 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
266 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
269 return system_setting_set_changed_cb(key, callback, user_data);
273 int system_settings_unset_changed_cb(system_settings_key_e key)
275 printf("system_settings_unset_changed_cb \n");
277 system_setting_h system_setting_item;
278 system_setting_unset_changed_callback_cb system_setting_unset_changed_cb;
280 if (system_settings_get_item(key, &system_setting_item))
282 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
283 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
286 system_setting_unset_changed_cb = system_setting_item->unset_changed_cb;
288 // free the callback function from application side
289 if (system_setting_item->changed_cb)
290 system_setting_item->changed_cb = NULL;
291 //-----------------------------------------------------
293 if (system_setting_unset_changed_cb == NULL)
295 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
296 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
299 return system_setting_unset_changed_cb(key);