4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
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.
25 #include "display-ops.h"
27 #include "core/edbus-handler.h"
32 #define SIGNAL_ALPM_ON "ALPMOn"
33 #define SIGNAL_ALPM_OFF "ALPMOff"
34 #define CLOCK_START "clockstart"
35 #define CLOCK_END "clockend"
36 #define ALPM_MAX_TIME 30 /* minutes */
38 static char *alpm_path;
39 static int update_count;
40 static int alpm_state;
42 void broadcast_alpm_state(int state)
46 signal = (state == true ? SIGNAL_ALPM_ON : SIGNAL_ALPM_OFF);
48 broadcast_edbus_signal(DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY,
52 int alpm_get_state(void)
60 ret = sys_get_str(alpm_path, state);
64 if (!strncmp(state, ON, strlen(ON)))
66 else if (!strncmp(state, OFF, strlen(OFF)))
74 int alpm_set_state(int on)
79 broadcast_alpm_state(on);
83 _D("ALPM is %s", (on ? ON : OFF));
87 return sys_set_str(alpm_path, (on ? ON : OFF));
90 static void start_clock(void)
92 struct timespec now_time;
93 static struct timespec start_time;
96 if (pm_cur_state == S_NORMAL ||
97 pm_cur_state == S_LCDDIM ||
103 if (update_count == 0)
104 clock_gettime(CLOCK_REALTIME, &start_time);
108 _D("clock update count : %d", update_count);
110 clock_gettime(CLOCK_REALTIME, &now_time);
111 diff_time = (now_time.tv_sec - start_time.tv_sec) / 60;
113 if (diff_time >= ALPM_MAX_TIME) {
114 _D("Exit ALPM state, LCD off");
115 alpm_set_state(false);
121 /* change pmstate in order that apps can know the state */
122 set_setting_pmstate(S_NORMAL);
128 set_setting_pmstate(S_LCDOFF);
134 static void end_clock(void)
136 if (pm_cur_state == S_NORMAL ||
137 pm_cur_state == S_LCDDIM ||
141 _D("end clock : lcd off");
144 int set_alpm_screen(char *screen)
152 if (!strncmp(screen, CLOCK_START,
153 strlen(CLOCK_START))) {
155 } else if (!strncmp(screen, CLOCK_END,
156 strlen(CLOCK_END))) {
163 static void alpm_init(void *data)
167 alpm_path = getenv("ALPM_NODE");
169 /* Check alpm node is valid */
170 fd = open(alpm_path, O_RDONLY);
172 _E("alpm node is invalid");
176 _I("alpm path[%s] is initialized!", alpm_path);
181 static void alpm_exit(void *data)
183 alpm_set_state(false);
186 static const struct display_ops display_alpm_ops = {
192 DISPLAY_OPS_REGISTER(&display_alpm_ops)