• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef POWERMGR_POWER_COMMON_H
17 #define POWERMGR_POWER_COMMON_H
18 
19 #include <cstdint>
20 #include <type_traits>
21 
22 #include "power_log.h"
23 #include "power_mgr_errors.h"
24 
25 #define SHUT_STAGE_FRAMEWORK_START 1
26 #define SHUT_STAGE_FRAMEWORK_FINISH 2
27 #define BOOT_DETECTOR_IOCTL_BASE 'B'
28 #define SET_SHUT_STAGE _IOW(BOOT_DETECTOR_IOCTL_BASE, 106, int)
29 
30 namespace OHOS {
31 namespace PowerMgr {
32 #define RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
33 #define RETURN_IF(cond) if (cond) {return;}
34 #define RETURN_IF_WITH_LOG(cond, loginfo)                                                   \
35     do {                                                                                \
36         if (cond) {                                                                     \
37             POWER_HILOGE(COMP_FWK, #loginfo);                                           \
38             return;                                                                     \
39         }                                                                               \
40     } while (0)                                                                         \
41 
42 #define RETURN_IF_READ_PARCEL_FAILED_NO_RET(parcel, type, out)                                           \
43     do {                                                                                \
44         if (!(parcel).Read##type(out)) {                                                \
45             POWER_HILOGE(COMP_FWK, "read "#out" failed");                          \
46             return;                                                                     \
47         }                                                                               \
48     } while (0)                                                                         \
49 
50 #define RETURN_IF_WRITE_PARCEL_FAILED_NO_RET(parcel, type, data)                                         \
51     do {                                                                                \
52         if (!(parcel).Write##type(data)) {                                              \
53             POWER_HILOGE(COMP_FWK, "write "#data" failed");                        \
54             return;                                                                     \
55         }                                                                               \
56     } while (0)                                                                         \
57 
58 #define RETURN_IF_READ_PARCEL_FAILED_WITH_RET(parcel, type, out, retval)                                \
59     do {                                                                               \
60         if (!(parcel).Read##type(out)) {                                               \
61             POWER_HILOGE(COMP_FWK, "read "#out" failed");                         \
62             return (retval);                                                           \
63         }                                                                              \
64     } while (0)                                                                        \
65 
66 #define RETURN_IF_WRITE_PARCEL_FAILED_WITH_RET(parcel, type, data, retval)                              \
67     do {                                                                               \
68         if (!(parcel).Write##type(data)) {                                             \
69             POWER_HILOGE(COMP_FWK, "write data failed");                       \
70             return (retval);                                                           \
71         }                                                                              \
72     } while (0)
73 
74 template<typename E>
ToUnderlying(E e)75 constexpr auto ToUnderlying(E e) noexcept
76 {
77     return static_cast<std::underlying_type_t<E>>(e);
78 }
79 } // namespace PowerMgr
80 } // namespace OHOS
81 
82 #endif // POWERMGR_POWER_COMMON_H