• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 THERMAL_COMMON_H
17 #define THERMAL_COMMON_H
18 
19 #include <cstdint>
20 #include <type_traits>
21 
22 #include "thermal_log.h"
23 #include "thermal_mgr_errors.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 #define THERMAL_RETURN_IF_WITH_RET(cond, retval) \
28     if (cond) { return (retval); }
29 #define THERMAL_RETURN_IF(cond) if (cond) {return;}
30 #define THERMAL_RETURN_IF_WITH_LOG(cond, loginfo)                                                   \
31     do {                                                                                \
32         if (cond) {                                                                     \
33             THERMAL_HILOGE(COMP_FWK, #loginfo);                                         \
34             return;                                                                     \
35         }                                                                               \
36     } while (0)                                                                         \
37 
38 #define THERMAL_READ_PARCEL_NO_RET(parcel, type, out)                                           \
39     do {                                                                                \
40         if (!(parcel).Read##type(out)) {                                                \
41             THERMAL_HILOGE(COMP_FWK, "read "#out" failed");                          \
42             return;                                                                     \
43         }                                                                               \
44     } while (0)                                                                         \
45 
46 #define THERMAL_WRITE_PARCEL_NO_RET(parcel, type, data)                                         \
47     do {                                                                                \
48         if (!(parcel).Write##type(data)) {                                              \
49             THERMAL_HILOGE(COMP_FWK, "write "#data" failed");                        \
50             return;                                                                     \
51         }                                                                               \
52     } while (0)                                                                         \
53 
54 #define THERMAL_READ_PARCEL_WITH_RET(parcel, type, out, retval)                                \
55     do {                                                                               \
56         if (!(parcel).Read##type(out)) {                                               \
57             THERMAL_HILOGE(COMP_FWK, "read "#out" failed");                         \
58             return (retval);                                                           \
59         }                                                                              \
60     } while (0)                                                                        \
61 
62 #define THERMAL_WRITE_PARCEL_WITH_RET(parcel, type, data, retval)                              \
63     do {                                                                               \
64         if (!(parcel).Write##type(data)) {                                             \
65             THERMAL_HILOGE(COMP_FWK, "write "#data" failed");                       \
66             return (retval);                                                           \
67         }                                                                              \
68     } while (0)
69 
70 template<typename E>
ThermalToUnderlying(E e)71 constexpr auto ThermalToUnderlying(E e) noexcept
72 {
73     return static_cast<std::underlying_type_t<E>>(e);
74 }
75 } // namespace PowerMgr
76 } // namespace OHOS
77 #endif // THERMAL_COMMON_H
78