1/*
2 * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 *    conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 *    of conditions and the following disclaimer in the documentation and/or other materials
13 *    provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 *    to endorse or promote products derived from this software without specific prior written
17 *    permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef __LINUX_WAKELOCK_H__
33#define __LINUX_WAKELOCK_H__
34
35#ifdef __cplusplus
36#if __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39#endif /* __cplusplus */
40
41enum {
42    WAKE_LOCK_SUSPEND, /* Prevent suspend */
43    WAKE_LOCK_IDLE
44};
45
46struct wakeup_source {
47    const char  *name;
48};
49
50struct wake_lock {
51    struct wakeup_source ws;
52    unsigned int bitmap_pos;
53};
54
55/**
56 * @ingroup  wakelock
57 * @brief Activate the wake lock.
58 *
59 * @par Description:
60 * This API is used to activate the wake lock.
61 *
62 * @attention
63 * <ul>
64 * <li>Use this function,you must run wake_lock_init first !</li>
65 * <li>please make sure the parameter lock is valid,otherwise the system maybe crash!</li>
66 * </ul>
67 *
68 * @param  lock [IN] Type #struct wake_lock   struct of the lock.
69 *
70 * @retval None.
71 * @par Dependency:
72 * <ul><li>Wakelock.h: the header file that contains the API declaration.</li></ul>
73 * @see wake_unlock.
74 */
75void linux_wake_lock(struct wake_lock *lock);
76
77/**
78 * @ingroup  wakelock
79 * @brief Unlock the wake lock.
80 *
81 * @par Description:
82 * This API is used to Unlock the wake lock,and make it invalid.
83 *
84 * @attention
85 * <ul>
86 * <li>Use this function,you must run wake_lock_init first !</li>
87 * <li>please make sure the parameter lock is valid,otherwise the system maybe crash!</li>
88 * </ul>
89 *
90 * @param  lock [IN] Type #struct wake_lock   struct of the lock.
91 *
92 * @retval None.
93 * @par Dependency:
94 * <ul><li>Wakelock.h: the header file that contains the API declaration.</li></ul>
95 * @see wake_lock.
96 */
97void linux_wake_unlock(struct wake_lock *lock);
98
99/**
100 * @ingroup  wakelock
101 * @brief judge whether the wake lock is active or not.
102 *
103 * @par Description:
104 * This API is used to judge whether the wake lock is active or not.
105 *
106 * @attention
107 * <ul>
108 * <li>Use this function,you must run wake_lock_init first !</li>
109 * <li>please make sure the parameter lock is valid,otherwise the system maybe crash!</li>
110 * </ul>
111 *
112 * @param  lock [IN] Type #struct wake_lock   struct of the lock.
113 *
114 * @retval #1 the wake lock is active.
115 * @retval #0 the wake lock is not active.
116 * @par Dependency:
117 * <ul><li>Wakelock.h: the header file that contains the API declaration.</li></ul>
118 * @see none.
119 */
120int linux_wake_lock_active(struct wake_lock *lock);
121
122/**
123 * @ingroup  wakelock
124 * @brief initial a new wakelock.
125 *
126 * @par Description:
127 * This API is used to initial a wakelock.
128 *
129 * @attention
130 * <ul>
131 * <li>DO NOT init more than 32 wack_lock!.</li>
132 * <li>please make sure the parameter lock type name are valid,otherwise the system maybe crash!</li>
133 * </ul>
134 *
135 * @param  lock [IN] Type #struct wake_lock   struct of the lock.
136 * @param  type [IN] Type #int   type of the new wakelock,not supported now.
137 * @param  name [IN] Type #const char   name of the new wakelock.
138 *
139 * @retval None.
140 * @par Dependency:
141 * <ul><li>Wakelock.h: the header file that contains the API declaration.</li></ul>
142 * @see none.
143 */
144void linux_wake_lock_init(struct wake_lock *lock, int type, const char *name);
145
146#define wake_lock(lock)    \
147    linux_wake_lock(lock)
148
149#define wake_unlock(lock)    \
150    linux_wake_unlock(lock)
151
152#define wake_lock_active(lock)    \
153    linux_wake_lock_active(lock)
154
155#define wake_lock_init(lock, type, name)    \
156    linux_wake_lock_init(lock, type, name)
157
158#ifdef __cplusplus
159#if __cplusplus
160}
161#endif /* __cplusplus */
162#endif /* __cplusplus */
163
164#endif /* __LINUX_WAKELOCK_H__ */
165