power: apply wait callback mechanism to all state transitions
[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_NORMAL_INDEX = POWER_STATE_MIN_INDEX,
49         POWER_STATE_SLEEP_INDEX,
50         POWER_STATE_POWEROFF_INDEX,
51         POWER_STATE_REBOOT_INDEX,
52         POWER_STATE_MAX_INDEX,
53 };
54
55 #define POWER_STATE_NORMAL   (1ULL << POWER_STATE_NORMAL_INDEX)
56 #define POWER_STATE_SLEEP    (1ULL << POWER_STATE_SLEEP_INDEX)
57 #define POWER_STATE_POWEROFF (1ULL << POWER_STATE_POWEROFF_INDEX)
58 #define POWER_STATE_REBOOT   (1ULL << POWER_STATE_REBOOT_INDEX)
59 #define POWER_STATE_ALL      ((1ULL << POWER_STATE_MAX_INDEX) - (1ULL << POWER_STATE_MIN_INDEX))
60
61 #define SIGNAME_CHANGE_STATE_TO_NORMAL        "ChangeStateToNormal"
62 #define SIGNAME_CHANGE_STATE_TO_SLEEP         "ChangeStateToSleep"
63 #define SIGNAME_CHANGE_STATE_TO_POWEROFF      "ChangeStateToPowerOff"
64 #define SIGNAME_CHANGE_STATE_TO_REBOOT        "ChangeStateToReboot"
65
66 struct device_change_state_info {
67         uint64_t prev_state;
68         uint64_t next_state;
69         int reason;
70 };
71
72 typedef int (*change_state_callback) (const struct device_change_state_info *info, void *user_data);
73
74 int device_power_add_change_state_wait_callback(uint64_t state_bits, change_state_callback cb, void *user_data);
75 void device_power_remove_change_state_wait_callback(uint64_t state_bits);
76
77 #ifdef __cplusplus
78 }
79 #endif
80
81 #endif