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,
102 SYSTEM_SETTINGS_MAX, -1, NULL, NULL, NULL, NULL, NULL
106 int system_settings_get_item(system_settings_key_e key, system_setting_h *item)
110 while (system_setting_table[index].key != SYSTEM_SETTINGS_MAX)
112 if (system_setting_table[index].key == key)
114 *item = &system_setting_table[index];
124 int system_settings_get_value(system_settings_key_e key, system_setting_data_type_e data_type, void** value)
126 system_setting_h system_setting_item;
127 system_setting_get_value_cb system_setting_getter;
129 if (system_settings_get_item(key, &system_setting_item))
131 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
132 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
135 if (system_setting_item->data_type != data_type)
137 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid data type", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
138 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
141 printf("assigned getter \n");
142 system_setting_getter = system_setting_item->get_value_cb;
144 if (system_setting_getter == NULL)
146 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
147 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
150 return system_setting_getter(key, system_setting_item->data_type, value);
153 int system_settings_set_value(system_settings_key_e key, system_setting_data_type_e data_type, void* value)
155 system_setting_h system_setting_item;
156 system_setting_set_value_cb system_setting_setter;
158 if (system_settings_get_item(key, &system_setting_item))
160 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
161 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
164 printf("assigned setter \n");
165 system_setting_setter = system_setting_item->set_value_cb;
167 if (system_setting_setter == NULL)
169 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
170 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
173 return system_setting_setter(key, system_setting_item->data_type, value);
176 // typedef int (*system_setting_set_value_cb) (system_settings_key_e key, system_setting_data_type_e data_type, void* value);
177 int system_settings_set_value_int(system_settings_key_e key, int value)
179 printf("[MOCK] system_settings_set_value_int - value = %d \n", value);
181 // TODO: make sure the value is inside of enum.
183 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_INT,(void*)ptr);
186 int system_settings_get_value_int(system_settings_key_e key, int *value)
188 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_INT, (void**)value);
191 int system_settings_set_value_bool(system_settings_key_e key, bool value)
193 printf("[MOCK] system_settings_set_value_bool - value = %d \n", value);
195 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL,(void*)ptr);
198 int system_settings_get_value_bool(system_settings_key_e key, bool *value)
200 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_BOOL, (void**)value);
203 int system_settings_set_value_double(system_settings_key_e key, double value)
205 printf("[MOCK] system_settings_set_value_double - value = %f \n", value);
206 double* ptr = &value;
207 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE,(void*)ptr);
210 int system_settings_get_value_double(system_settings_key_e key, double *value)
212 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_DOUBLE, (void**)value);
215 int system_settings_set_value_string(system_settings_key_e key, const char *value)
217 printf("[MOCK] system_settings_set_value_string - input string : %s \n", value);
218 return system_settings_set_value(key, SYSTEM_SETTING_DATA_TYPE_STRING,(void*)value);
221 int system_settings_get_value_string(system_settings_key_e key, char **value)
223 return system_settings_get_value(key, SYSTEM_SETTING_DATA_TYPE_STRING, (void**)value);
229 - system_settings_set_changed_cb
230 -> int (*system_setting_set_changed_callback_cb)(key, callback, user_data)
234 int system_settings_set_changed_cb(system_settings_key_e key, system_settings_changed_cb callback, void *user_data)
236 printf("system_settings_set_changed_cb \n");
238 system_setting_h system_setting_item;
239 system_setting_set_changed_callback_cb system_setting_set_changed_cb;
241 if (system_settings_get_item(key, &system_setting_item))
243 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
244 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
247 system_setting_set_changed_cb = system_setting_item->set_changed_cb;
249 // Store the callback function from application side
251 system_setting_item->changed_cb = callback;
253 if (system_setting_set_changed_cb == NULL)
255 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
256 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
259 return system_setting_set_changed_cb(key, callback, user_data);
263 int system_settings_unset_changed_cb(system_settings_key_e key)
265 printf("system_settings_unset_changed_cb \n");
267 system_setting_h system_setting_item;
268 system_setting_unset_changed_callback_cb system_setting_unset_changed_cb;
270 if (system_settings_get_item(key, &system_setting_item))
272 LOGE("[%s] INVALID_PARAMETER(0x%08x) : invalid key", __FUNCTION__, SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER);
273 return SYSTEM_SETTINGS_ERROR_INVALID_PARAMETER;
276 system_setting_unset_changed_cb = system_setting_item->unset_changed_cb;
278 // free the callback function from application side
279 if (system_setting_item->changed_cb)
280 system_setting_item->changed_cb = NULL;
281 //-----------------------------------------------------
283 if (system_setting_unset_changed_cb == NULL)
285 LOGE("[%s] IO_ERROR(0x%08x) : failed to call getter for the system settings", __FUNCTION__, SYSTEM_SETTINGS_ERROR_IO_ERROR);
286 return SYSTEM_SETTINGS_ERROR_IO_ERROR;
289 return system_setting_unset_changed_cb(key);