Merge Tizen 2.0 dev to RSA
[framework/system/power-manager.git] / pm_x_lcd_onoff.c
1 /*
2  * Copyright 2012  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://www.tizenopensource.org/license
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
18 #ifndef __PM_X_LCD_ONOFF_C__
19 #define __PM_X_LCD_ONOFF_C__
20
21 #include <string.h>
22 #include <sys/wait.h>
23 #include <errno.h>
24
25 #include "pm_device_plugin.h"
26
27 #define CMD_STANDBY     "standby"
28 #define CMD_OFF         "off"
29
30 static int pm_x_set_lcd_backlight(struct _PMSys *p, int onoff)
31 {
32         pid_t pid;
33         char cmd_line[32];
34         int ret;
35
36         LOGINFO("Backlight onoff=%d", onoff);
37         if (onoff == STATUS_ON)
38                 snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_STANDBY);
39         else
40                 snprintf(cmd_line, sizeof(cmd_line), "%s", CMD_OFF);
41
42         signal(SIGCHLD, SIG_DFL);
43         pid = vfork();
44
45         if (pid < 0) {
46                 LOGERR("[1] Failed to fork child process for LCD On/Off");
47                 return -1;
48         }
49
50         if (pid == 0) {
51                 LOGINFO("[1] Child proccess for LCD %s was created (%s)",
52                         ((onoff == STATUS_ON) ? "ON" : "OFF"), cmd_line);
53                 execl("/usr/bin/xset", "/usr/bin/xset", "dpms", "force",
54                       cmd_line, NULL);
55                 _exit(0);
56         } else if (pid != (ret = waitpid(pid, NULL, 0))) {
57                 LOGERR
58                     ("[1] Waiting failed for the child process pid: %d, ret: %d, errno: %d",
59                      pid, ret, errno);
60         }
61
62         signal(SIGCHLD, SIG_IGN);
63         return 0;
64 }
65
66 #endif                          /*__PM_X_LCD_ONOFF_C__ */