2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
22 #include <sys/types.h>
34 #include <livebox-service.h>
36 #include "client_life.h"
40 #include "slave_life.h"
41 #include "critical_log.h"
55 static void lcd_state_cb(keynode_t *node, void *user_data)
61 xmonitor_handle_state_changes();
64 HAPI int setting_is_lcd_off(void)
68 if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) {
69 ErrPrint("Idle lock state is not valid\n");
70 state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */
73 DbgPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP);
74 return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP;
77 static void power_off_cb(keynode_t *node, void *user_data)
80 CRITICAL_LOG("Terminated(vconf)\n");
82 if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) {
83 ErrPrint("Failed to get power off status (%d)\n", val);
87 if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
88 DbgPrint("Power off requested: Ignored\n");
90 ErrPrint("Unknown power state: %d\n", val);
94 static void region_changed_cb(keynode_t *node, void *user_data)
99 region = vconf_get_str(VCONFKEY_REGIONFORMAT);
104 setenv("LC_CTYPE", region, 1);
105 setenv("LC_NUMERIC", region, 1);
106 setenv("LC_TIME", region, 1);
107 setenv("LC_COLLATE", region, 1);
108 setenv("LC_MONETARY", region, 1);
109 setenv("LC_PAPER", region, 1);
110 setenv("LC_NAME", region, 1);
111 setenv("LC_ADDRESS", region, 1);
112 setenv("LC_TELEPHONE", region, 1);
113 setenv("LC_MEASUREMENT", region, 1);
114 setenv("LC_IDENTIFICATION", region, 1);
116 r = setlocale(LC_ALL, "");
118 ErrPrint("Failed to change region\n");
124 static void lang_changed_cb(keynode_t *node, void *user_data)
129 lang = vconf_get_str(VCONFKEY_LANGSET);
134 setenv("LANG", lang, 1);
135 setenv("LC_MESSAGES", lang, 1);
137 r = setlocale(LC_ALL, "");
139 ErrPrint("Failed to change locale\n");
142 DbgPrint("Locale: %s\n", setlocale(LC_ALL, NULL));
146 static void low_mem_cb(keynode_t *node, void *user_data)
150 val = vconf_keynode_get_int(node);
152 if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING) {
153 CRITICAL_LOG("Low memory: level %d\n", val);
154 if (s_info.deactivated == 0) {
155 s_info.deactivated = 1;
156 //slave_deactivate_all(0, 1);
158 ErrPrint("Fall into the low mem status\n");
161 CRITICAL_LOG("Normal memory: level %d\n", val);
162 if (s_info.deactivated == 1) {
163 s_info.deactivated = 0;
164 //slave_activate_all();
165 ErrPrint("Recover from the low mem status\n");
170 HAPI int setting_init(void)
174 ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL);
176 ErrPrint("Failed to add vconf for lock state: %d\n", ret);
179 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL);
181 ErrPrint("Failed to add vconf for power state: %d \n", ret);
184 ret = vconf_notify_key_changed(VCONFKEY_LANGSET, lang_changed_cb, NULL);
186 ErrPrint("Failed to add vconf for lang change: %d\n", ret);
189 ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb, NULL);
191 ErrPrint("Failed to add vconf for region change: %d\n", ret);
194 ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb, NULL);
196 ErrPrint("Failed to add vconf for low mem monitor: %d\n", ret);
199 lang_changed_cb(NULL, NULL);
200 region_changed_cb(NULL, NULL);
204 HAPI int setting_fini(void)
208 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb);
210 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
213 ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
215 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
218 ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb);
220 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
223 ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
225 ErrPrint("Failed to ignore vconf key (%d)\n", ret);
228 ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
230 ErrPrint("Failed to ignore vconf key (%d)\n", ret);