Update License
[platform/framework/web/data-provider-master.git] / src / setting.c
1 /*
2  * Copyright 2013  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org
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 <unistd.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <fcntl.h>
24 #include <errno.h>
25
26 #include <vconf.h>
27 #include <dlog.h>
28
29 #include <Eina.h>
30
31 #include "client_life.h"
32 #include "setting.h"
33 #include "util.h"
34 #include "debug.h"
35 #include "slave_life.h"
36 #include "critical_log.h"
37 #include "xmonitor.h"
38 #include "conf.h"
39
40 int errno;
41
42 static void lcd_state_cb(keynode_t *node, void *user_data)
43 {
44         if (!node)
45                 return;
46
47         xmonitor_handle_state_changes();
48 }
49
50 HAPI int setting_is_lcd_off(void)
51 {
52         int state;
53
54         if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) {
55                 ErrPrint("Idle lock state is not valid\n");
56                 state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */
57         }
58
59         DbgPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP);
60         return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP;
61 }
62
63 static void power_off_cb(keynode_t *node, void *user_data)
64 {
65         int val;
66         CRITICAL_LOG("Terminated(vconf)\n");
67
68         if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) {
69                 ErrPrint("Failed to get power off status (%d)\n", val);
70                 return;
71         }
72
73         if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
74                 if (creat("/tmp/.stop.provider", 0644) < 0)
75                         ErrPrint("Failed to create .stop.provider [%s]\n", strerror(errno));
76
77                 exit(0);
78         } else {
79                 ErrPrint("Unknown power state: %d\n", val);
80         }
81 }
82
83 HAPI int setting_init(void)
84 {
85         int ret;
86
87         ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL);
88         if (ret < 0)
89                 ErrPrint("Failed to add vconf for lock state\n");
90
91         ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL);
92         if (ret < 0)
93                 ErrPrint("Failed to add vconf for power state\n");
94
95         return ret;
96 }
97
98 HAPI int setting_fini(void)
99 {
100         int ret;
101         ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
102         ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
103         return ret;
104 }
105
106 /* End of a file */