• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 DEVICESTATUS_COMMON_H
17 #define DEVICESTATUS_COMMON_H
18 
19 #include <cstdint>
20 #include <type_traits>
21 
22 #include "devicestatus_hilog_wrapper.h"
23 #include "devicestatus_errors.h"
24 
25 namespace OHOS {
26 namespace Msdp {
27 #define DEVICESTATUS_RETURN_IF_WITH_RET(cond, retval) if (cond) {return (retval);}
28 #define DEVICESTATUS_RETURN_IF(cond) if (cond) {return;}
29 #define DEVICESTATUS_RETURN_IF_WITH_LOG(cond, loginfo)                                  \
30     do {                                                                                \
31         if (cond) {                                                                     \
32             DEV_HILOGE(COMMON, "%{public}s "#loginfo" ", __func__); \
33             return;                                                                     \
34         }                                                                               \
35     } while (0)                                                                         \
36 
37 #define DEVICESTATUS_READ_PARCEL_NO_RET(parcel, type, out)                              \
38     do {                                                                                \
39         if (!(parcel).Read##type(out)) {                                                \
40             DEV_HILOGE(COMMON, "%{public}s read "#out" failed", __func__); \
41             return;                                                                     \
42         }                                                                               \
43     } while (0)                                                                         \
44 
45 #define DEVICESTATUS_WRITE_PARCEL_NO_RET(parcel, type, data)                            \
46     do {                                                                                \
47         if (!(parcel).Write##type(data)) {                                              \
48             DEV_HILOGE(COMMON, "%{public}s write "#data" failed", __func__); \
49             return;                                                                     \
50         }                                                                               \
51     } while (0)                                                                         \
52 
53 #define DEVICESTATUS_READ_PARCEL_WITH_RET(parcel, type, out, retval)                    \
54     do {                                                                                \
55         if (!(parcel).Read##type(out)) {                                                \
56             DEV_HILOGE(COMMON, "%{public}s read "#out" failed", __func__); \
57             return (retval);                                                            \
58         }                                                                               \
59     } while (0)                                                                         \
60 
61 #define DEVICESTATUS_WRITE_PARCEL_WITH_RET(parcel, type, data, retval)                  \
62     do {                                                                                \
63         if (!(parcel).Write##type(data)) {                                              \
64             DEV_HILOGE(COMMON, "%{public}s write "#data" failed", __func__); \
65             return (retval);                                                            \
66         }                                                                               \
67     } while (0)
68 
69 template<typename E>
DevicestatusToUnderlying(E e)70 constexpr auto DevicestatusToUnderlying(E e) noexcept
71 {
72     return static_cast<std::underlying_type_t<E>>(e);
73 }
74 } // namespace Msdp
75 } // namespace OHOS
76 
77 #endif // DEVICESTATUS_COMMON_H
78