4 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "display-signal.h"
21 #include "shared/plugin.h"
22 #include "shared/time.h"
24 #define ACTIVE_ACT "active"
25 #define INACTIVE_ACT "inactive"
27 static const char *lcdon_sig_lookup[SIGNAL_MAX] = {
28 [SIGNAL_PRE] = "LCDOn",
29 [SIGNAL_POST] = "LCDOnCompleted",
31 static const char *lcdoff_sig_lookup[SIGNAL_MAX] = {
32 [SIGNAL_PRE] = "LCDOff",
33 [SIGNAL_POST] = "LCDOffCompleted",
36 static struct display_plugin *disp_plgn;
37 static long displayoff_time;
39 void broadcast_lcd_on(enum signal_type type, enum device_flags flags)
46 if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) {
47 _E("Invalid signal type(%d).", type);
51 if (type == SIGNAL_PRE && displayoff_time != 0)
52 diff = clock_gettime_to_long() - displayoff_time;
54 if (!disp_plgn->device_flags_to_string) {
55 _E("Cannot convert device_flags to string.");
59 str = disp_plgn->device_flags_to_string(flags);
61 signal = lcdon_sig_lookup[type];
62 _I("lcdstep : Broadcast signal(%s:%s).", signal, str);
63 ret = gdbus_signal_emit_sync(NULL,
65 DEVICED_INTERFACE_DISPLAY,
67 g_variant_new("(si)", str, diff));
69 _E("Failed to send dbus signal(%s)", signal);
72 void broadcast_lcd_off(enum signal_type type, enum device_flags flags)
78 if (type <= SIGNAL_INVALID || type >= SIGNAL_MAX) {
79 _E("Invalid signal type(%d).", type);
83 if (type == SIGNAL_PRE)
84 displayoff_time = clock_gettime_to_long();
86 signal = lcdoff_sig_lookup[type];
88 if (!disp_plgn->device_flags_to_string) {
89 _E("Cannot convert device_flags to string.");
93 str = disp_plgn->device_flags_to_string(flags);
95 _I("lcdstep : Broadcast signal(%s).", signal);
96 ret = gdbus_signal_emit_sync(NULL,
98 DEVICED_INTERFACE_DISPLAY,
100 g_variant_new("(s)", str));
102 _E("Failed to send dbus signal(%s)", signal);
105 void broadcast_lcd_off_late(enum device_flags flags)
107 static enum device_flags late_flags;
109 if (flags & LCD_OFF_LATE_MODE) {
110 broadcast_lcd_off(SIGNAL_POST, late_flags);
111 device_notify(DEVICE_NOTIFIER_LCD_OFF_COMPLETE, NULL);
117 void set_process_active(bool flag, pid_t pid)
121 if (pid >= INTERNAL_LOCK_BASE)
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));
131 _E("Failed to send dbus signal to resourced.");
134 static void __CONSTRUCTOR__ initialize(void)
136 disp_plgn = get_var_display_plugin();
138 _E("Failed to get display plugin variable.");