extcon: Trivial typo fix
[platform/core/system/deviced.git] / src / display / display-signal.c
1 /*
2  * deviced
3  *
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
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 #include "display-signal.h"
20 #include "poll.h"
21 #include "shared/plugin.h"
22 #include "shared/time.h"
23
24 #define ACTIVE_ACT "active"
25 #define INACTIVE_ACT "inactive"
26
27 static const char *lcdon_sig_lookup[SIGNAL_MAX] = {
28         [SIGNAL_PRE]  = "LCDOn",
29         [SIGNAL_POST] = "LCDOnCompleted",
30 };
31 static const char *lcdoff_sig_lookup[SIGNAL_MAX] = {
32         [SIGNAL_PRE]  = "LCDOff",
33         [SIGNAL_POST] = "LCDOffCompleted",
34 };
35
36 static struct display_plugin *disp_plgn;
37 static long displayoff_time;
38
39 void broadcast_lcd_on(enum signal_type type, enum device_flags flags)
40 {
41         const char *str;
42         const char *signal;
43         int ret;
44         long diff = 0;
45
46         if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) {
47                 _E("Invalid signal type(%d).", type);
48                 return;
49         }
50
51         if (type == SIGNAL_PRE && displayoff_time != 0)
52                 diff = clock_gettime_to_long() - displayoff_time;
53
54         if (!disp_plgn->device_flags_to_string) {
55                 _E("Cannot convert device_flags to string.");
56                 return;
57         }
58
59         str = disp_plgn->device_flags_to_string(flags);
60
61         signal = lcdon_sig_lookup[type];
62         _I("lcdstep : Broadcast signal(%s:%s).", signal, str);
63         ret = gdbus_signal_emit_sync(NULL,
64                                                 DEVICED_PATH_DISPLAY,
65                                                 DEVICED_INTERFACE_DISPLAY,
66                                                 signal,
67                                                 g_variant_new("(si)", str, diff));
68         if (ret < 0)
69                 _E("Failed to send dbus signal(%s)", signal);
70 }
71
72 void broadcast_lcd_off(enum signal_type type, enum device_flags flags)
73 {
74         const char *str;
75         const char *signal;
76         int ret;
77
78         if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) {
79                 _E("Invalid signal type(%d).", type);
80                 return;
81         }
82
83         if (type == SIGNAL_PRE)
84                 displayoff_time = clock_gettime_to_long();
85
86         signal = lcdoff_sig_lookup[type];
87
88         if (!disp_plgn->device_flags_to_string) {
89                 _E("Cannot convert device_flags to string.");
90                 return;
91         }
92
93         str = disp_plgn->device_flags_to_string(flags);
94
95         _I("lcdstep : Broadcast signal(%s).", signal);
96         ret = gdbus_signal_emit_sync(NULL,
97                                                 DEVICED_PATH_DISPLAY,
98                                                 DEVICED_INTERFACE_DISPLAY,
99                                                 signal,
100                                                 g_variant_new("(s)", str));
101         if (ret < 0)
102                 _E("Failed to send dbus signal(%s)", signal);
103 }
104
105 void broadcast_lcd_off_late(enum device_flags flags)
106 {
107         static enum device_flags late_flags;
108
109         if (flags & LCD_OFF_LATE_MODE) {
110                 broadcast_lcd_off(SIGNAL_POST, late_flags);
111                 device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL);
112         } else {
113                 late_flags = flags;
114         }
115 }
116
117 void set_process_active(bool flag, pid_t pid)
118 {
119         int ret;
120
121         if (pid >= INTERNAL_LOCK_BASE)
122                 return;
123
124         /* Send dbus signal to resourced */
125         ret = gdbus_signal_emit(NULL,
126                                                         RESOURCED_PATH_PROCESS,
127                                                     RESOURCED_INTERFACE_PROCESS,
128                                                     RESOURCED_METHOD_ACTIVE,
129                                                     g_variant_new("(si)", (flag ? ACTIVE_ACT : INACTIVE_ACT), pid));
130         if (ret < 0)
131                 _E("Failed to send dbus signal to resourced.");
132 }
133
134 static void __CONSTRUCTOR__ initialize(void)
135 {
136         disp_plgn = get_var_display_plugin();
137         if (!disp_plgn)
138                 _E("Failed to get display plugin variable.");
139 }