power: rename callback function
[platform/core/api/device.git] / include / power-internal.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __TIZEN_SYSTEM_POWER_INTERNAL_H__
18 #define __TIZEN_SYSTEM_POWER_INTERNAL_H__
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #include <stdint.h>
25 #include <glib.h>
26 #include <gio/gio.h>
27
28 #include "device-error.h"
29
30 /**
31  * @platform
32  * @brief Power off the device.
33  * @details It operates synchronously.
34  * @since_tizen 6.5
35  * @privlevel platform
36  * @privilege %http://tizen.org/privilege/reboot
37  * @return @c 0 on success,
38  *         otherwise a negative error value
39  * @retval #DEVICE_ERROR_NONE Successful
40  * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
41  * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
42  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
43  */
44 int device_power_poweroff(void);
45
46 enum {
47         POWER_STATE_MIN_INDEX = 4,
48         POWER_STATE_START_INDEX = POWER_STATE_MIN_INDEX,
49         POWER_STATE_NORMAL_INDEX,
50         POWER_STATE_SLEEP_INDEX,
51         POWER_STATE_POWEROFF_INDEX,
52         POWER_STATE_REBOOT_INDEX,
53         POWER_STATE_EXIT_INDEX,
54         POWER_STATE_MAX_INDEX,
55 };
56
57 #define POWER_STATE_START    (1ULL << POWER_STATE_START_INDEX)
58 #define POWER_STATE_NORMAL   (1ULL << POWER_STATE_NORMAL_INDEX)
59 #define POWER_STATE_SLEEP    (1ULL << POWER_STATE_SLEEP_INDEX)
60 #define POWER_STATE_POWEROFF (1ULL << POWER_STATE_POWEROFF_INDEX)
61 #define POWER_STATE_REBOOT   (1ULL << POWER_STATE_REBOOT_INDEX)
62 #define POWER_STATE_EXIT     (1ULL << POWER_STATE_EXIT_INDEX)
63 #define POWER_STATE_ALL      ((1ULL << POWER_STATE_MAX_INDEX) - (1ULL << POWER_STATE_MIN_INDEX))
64
65 #define SIGNAME_CHANGE_STATE_TO_START         "ChangeStateToStart"
66 #define SIGNAME_CHANGE_STATE_TO_NORMAL        "ChangeStateToNormal"
67 #define SIGNAME_CHANGE_STATE_TO_SLEEP         "ChangeStateToSleep"
68 #define SIGNAME_CHANGE_STATE_TO_POWEROFF      "ChangeStateToPowerOff"
69 #define SIGNAME_CHANGE_STATE_TO_REBOOT        "ChangeStateToReboot"
70 #define SIGNAME_CHANGE_STATE_TO_EXIT          "ChangeStateToExit"
71
72 struct device_change_state_info {
73         uint64_t prev_state; /* previous state before the state transition, one of POWER_STATE_* */
74         uint64_t next_state; /* current state that has been transitioned, one of POWER_STATE_* */
75         uint64_t id;         /* unique id for each transition. it is used for wait-done */
76         int reason;          /* integer that signifies what event has triggered the transition */
77 };
78
79 /**
80  * @brief Called when a device power state is changed
81  * @details If both power_change_state_wait_callback and power_change_state_callback have registered to the same power state, \n
82  *          then the power_change_state_wait_callback will be invoked first and the power_change_state_callback will follow.
83  * @param[out] info Information about state change
84  * @param[out] user_data User data passed from the callback registration
85  */
86 typedef void (*power_change_state_wait_callback) (const struct device_change_state_info *info, void *user_data);
87
88 /**
89  * @brief Add a callback to observe power state change
90  * @details Register a callback for specific power state. \n
91  *          The callback will be invoked when the deviced changes state to the designated power state. \n
92  *          An actual action, such as triggering poweroff on changing state to POWER_STATE_POWEROFF or \n
93  *          wake unlock on changing state to POWER_STATE_SLEEP, will be deferred to give a chance \n
94  *          for the API caller to prepare for the action.
95  * @sinze_tizen 6.5
96  * @param[in] state_bits Bitwise ORed power state
97  * @param[in] cb Callback function
98  * @param[in] user_data Data to be passed to the callback function
99  * @return 0 on success,
100  *         otherwise a negative error value
101  * @retval #DEVICE_ERROR_NONE Successful
102  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
103  */
104 int device_power_add_change_state_wait_callback(uint64_t state_bits, power_change_state_wait_callback cb, void *user_data);
105
106 /**
107  * @brief Notify the deviced that it is ready for the actual action.
108  * @details Notify the deviced that it is ok to take an actual action of change state. \n
109  *          This API only works on the id received from power_change_state_wait_callback.
110  * @since_tizen 6.5
111  * @param[in] id Id of a state change
112  * @return 0 on success,
113  *         otherwise a negative error value
114  * @retval #DEVICE_ERROR_NONE Successful
115  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
116  */
117 int device_power_change_state_wait_done(uint64_t id);
118
119 /**
120  * @brief Remove callback that has registered to power state.
121  * @since_tizen 6.5
122  * @param[in] state_bits Bitwise ORed power state
123  */
124 void device_power_remove_change_state_wait_callback(uint64_t state_bits);
125
126 /**
127  * @brief Async callback of device_power_change_state().
128  * @details If both power_change_state_wait_callback and power_change_state_callback have registered to the same power state, \n
129  *          then the power_change_state_wait_callback will be invoked first and the power_change_state_callback will follow.
130  * @since_tizen 6.5
131  * @param[out] state State to be changed
132  * @param[out] retval Return of change state
133  * @param[out] user_data The user data passed from the change state function
134  */
135 typedef void (*power_change_state_callback) (uint64_t state, int retval, void *user_data);
136
137 /**
138  * @brief Send request for changing power state asynchronously.
139  * @since_tizen 6.5
140  * @param[in] state Target state
141  * @param[in] timeout_sec Timeout for the async reply in second, maximum of 10 seconds
142  * @param[in] cb Async callback of the request
143  * @param[in] user_data Data to be passed to the callback function
144  * @return 0 on success,
145  *         otherwise a negative error value
146  * @retval #DEVICE_ERROR_NONE Successful
147  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
148  */
149 int device_power_change_state(uint64_t state, int timeout_sec, power_change_state_callback cb, void *user_data);
150
151 /**
152  * @brief Check if reboot is possible on the current device state
153  * @since_tizen 6.5
154  * @return 1 if a device is able to reboot,
155  *         otherwise return 0
156  */
157 int device_power_check_reboot_allowed(void);
158
159 /**
160  * @brief Get internal power state of the deviced
161  * @since_tizen 6.5
162  * @param[out] state Internal power state of the deviced
163  * @return 0 on success,
164  *         otherwise a negative error value
165  * @retval #DEVICE_ERROR_NONE Successful
166  * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
167  */
168 int device_power_get_state(uint64_t *state);
169
170 #ifdef __cplusplus
171 }
172 #endif
173
174 #endif