display: Move plugin-common files to core(src/display)
[platform/core/system/deviced.git] / src / display / slave-logging.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the License);
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19
20 #include <stdbool.h>
21
22 #include "shared/common.h"
23 #include "core/log.h"
24 #include "core.h"
25 #include "poll.h"
26
27 #define BUFF_MAX        255
28 #define LOCK_STR_MAX    20
29 #define DISP_LOCK_STR   "displock"
30 #define MAIN_LOCK_STR   "mainlock"
31 #define DIM_LOCK_STR    "dimlock"
32
33 #define USER_WAKELOCK_NODE      "/sys/power/slave_wake_lock"
34 #define USER_WAKEUNLOCK_NODE    "/sys/power/slave_wake_unlock"
35
36 static bool userlock_saving_support;
37
38 int save_pmlock(enum state_t state, bool on, pid_t pid)
39 {
40         int ret = 0;
41         char *node, *state_str;
42         char str[LOCK_STR_MAX];
43
44         if (!userlock_saving_support)
45                 return -ENOSYS;
46
47         switch (state) {
48         case S_NORMAL:
49                 state_str = DISP_LOCK_STR;
50                 break;
51         case S_LCDDIM:
52                 state_str = DIM_LOCK_STR;
53                 break;
54         case S_LCDOFF:
55                 state_str  = MAIN_LOCK_STR;
56                 break;
57         default:
58                 return -EINVAL;
59         }
60
61         node = (on ? USER_WAKELOCK_NODE : USER_WAKEUNLOCK_NODE);
62
63         snprintf(str, LOCK_STR_MAX, "%s %d", state_str, pid);
64
65         ret = sys_set_str(node, str);
66         if (ret < 0)
67                 _E("Failed to set disp userlock state!");
68
69         return ret;
70 }
71
72 void init_save_userlock(void)
73 {
74         int ret;
75         char str[BUFF_MAX];
76
77         userlock_saving_support = false;
78
79         ret = sys_get_str(USER_WAKELOCK_NODE, str, sizeof(str));
80         if (ret < 0) {
81                 _E("Failed to load userlock(lock)!");
82                 return;
83         }
84
85         ret = sys_get_str(USER_WAKEUNLOCK_NODE, str, sizeof(str));
86         if (ret < 0) {
87                 _E("Failed to load userlock(unlock)!");
88                 return;
89         }
90
91         userlock_saving_support = true;
92         _I("userlock-saving is enabled!");
93 }
94