• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_DEFINE_H
17 #define DEVICESTATUS_DEFINE_H
18 
19 #include <chrono>
20 
21 #include "devicestatus_errors.h"
22 #include "fi_log.h"
23 #include "include/util.h"
24 
25 namespace OHOS {
26 namespace Msdp {
27 namespace DeviceStatus {
28 #define FI_PKG_NAME "ohos.msdp.fusioninteraction"
29 #define COOPERATE_PERMISSION "ohos.permission.COOPERATE_MANAGER"
30 
31 using TimeStamp = std::chrono::high_resolution_clock::time_point;
32 
33 #ifndef RET_OK
34     #define RET_OK (0)
35 #endif
36 
37 #ifndef RET_ERR
38     #define RET_ERR (-1)
39 #endif
40 
41 #define CHKEF(errCode, desc) \
42     do { \
43         if ((errCode) != RET_OK) { \
44             FI_HILOGE("%{public}s", desc); \
45             return false; \
46         } \
47     } while (0)
48 
49 #define CHKPL(cond) \
50     do { \
51         if ((cond) == nullptr) { \
52             FI_HILOGW("CHKPL(%{public}s) is null, do nothing", #cond); \
53         } \
54     } while (0)
55 
56 #define CHKPV(cond) \
57     do { \
58         if ((cond) == nullptr) { \
59             FI_HILOGE("CHKPV(%{public}s) is null", #cond); \
60             return; \
61         } \
62     } while (0)
63 
64 #define CHKPF(cond) \
65     do { \
66         if ((cond) == nullptr) { \
67             FI_HILOGE("CHKPF(%{public}s) is null", #cond); \
68             return false; \
69         } \
70     } while (0)
71 
72 #define CHKPS(cond) \
73     do { \
74         if ((cond) == nullptr) { \
75             FI_HILOGE("CHKPS(%{public}s) is null", #cond); \
76             return {}; \
77         } \
78     } while (0)
79 
80 #define CHKPC(cond) \
81     { \
82         if ((cond) == nullptr) { \
83             FI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \
84             continue; \
85         } \
86     }
87 
88 #define CHKPB(cond) \
89     { \
90         if ((cond) == nullptr) { \
91             FI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \
92             break; \
93         } \
94     }
95 
96 #define CHKPR(cond, r) \
97     do { \
98         if ((cond) == nullptr) { \
99             FI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \
100             return r; \
101         } \
102     } while (0)
103 
104 #define CHKPP(cond) \
105     do { \
106         if ((cond) == nullptr) { \
107             FI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \
108             return nullptr; \
109         } \
110     } while (0)
111 
112 #define CHKPO(cond) \
113     do { \
114         if ((cond) == nullptr) { \
115             FI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \
116                 __FILE__, __LINE__, #cond); \
117             return {}; \
118         } \
119     } while (0)
120 
121 #define CHK_PID_AND_TID() \
122     do { \
123         FI_HILOGD("%{public}s, (%{public}d), pid:%{public}d, threadId:%{public}" PRIu64, \
124             __FILE__, __LINE__, GetPid(), GetThisThreadId()); \
125     } while (0)
126 } // namespace DeviceStatus
127 } // namespace Msdp
128 } // namespace OHOS
129 #endif // DEVICESTATUS_DEFINE_H
130