copy license file to /usr/share/license
[platform/core/system/power-manager.git] / pm_x_lcd_onoff.c
1 /*
2  * power-manager
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 */
17
18
19 #ifndef __PM_X_LCD_ONOFF_C__
20 #define __PM_X_LCD_ONOFF_C__
21
22 #include <string.h>
23 #include <sys/wait.h>
24 #include <errno.h>
25
26 #define CMD_ON          "on"
27 #define CMD_OFF         "off"
28
29 static int pm_x_set_lcd_backlight(struct _PMSys *p, int onoff)
30 {
31         pid_t pid;
32         char cmd_line[32];
33         int ret;
34
35         LOGINFO("Backlight onoff=%d", onoff);
36         if (onoff == STATUS_ON)
37                 snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_ON);
38         else
39                 snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_OFF);
40
41         signal(SIGCHLD, SIG_DFL);
42         pid = vfork();
43
44         if (pid < 0) {
45                 LOGERR("[1] Failed to fork child process for LCD On/Off");
46                 return -1;
47         }
48
49         if (pid == 0) {
50                 LOGINFO("[1] Child proccess for LCD %s was created (%s)",
51                         ((onoff == STATUS_ON) ? "ON" : "OFF"), cmd_line);
52                 execl("/usr/bin/xset", "/usr/bin/xset", "dpms", "force",
53                       cmd_line, NULL);
54                 _exit(0);
55         } else if (pid != (ret = waitpid(pid, NULL, 0))) {
56                 LOGERR
57                     ("[1] Waiting failed for the child process pid: %d, ret: %d, errno: %d",
58                      pid, ret, errno);
59         }
60
61         signal(SIGCHLD, SIG_IGN);
62         return 0;
63 }
64
65 #endif                          /*__PM_X_LCD_ONOFF_C__ */