4 * Copyright (c) 2014 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.
23 #include "core/device-notifier.h"
24 #include "core/devices.h"
25 #include "core/edbus-handler.h"
26 #include "core/common.h"
27 #include "display/core.h"
30 #define SLEEP_CHECK_DURATION 3600 /* 1hour */
41 static struct sleep_type monitor = {
44 static time_t old = 0;
45 static time_t diff = 0;
47 static void sleep_changed(int status)
49 if (monitor.sleep_status == status)
51 monitor.sleep_status = status;
52 _I("sleep status %d", status);
55 static void check_sleep(void)
59 if (monitor.sleep_status == DEVICE_SLEEP)
65 if (diff > SLEEP_CHECK_DURATION)
66 sleep_changed(DEVICE_SLEEP);
69 static int display_changed(void *data)
71 enum state_t state = (enum state_t)data;
73 if (state == S_LCDOFF || state == S_SLEEP)
79 sleep_changed(DEVICE_AWAKE);
84 static int booting_done(void *data)
87 register_notifier(DEVICE_NOTIFIER_LCD, display_changed);
91 static void sleep_init(void *data)
93 register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
96 static void sleep_exit(void *data)
98 unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
99 unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed);
102 static int sleep_execute(void *data)
108 static const struct device_ops sleep_device_ops = {
109 .priority = DEVICE_PRIORITY_NORMAL,
110 .name = DEVICE_SLEEP_OPS,
113 .execute = sleep_execute,
116 DEVICE_OPS_REGISTER(&sleep_device_ops)