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 CHKPL(cond) \ 42 do { \ 43 if ((cond) == nullptr) { \ 44 FI_HILOGW("CHKPL(%{public}s) is null, do nothing", #cond); \ 45 } \ 46 } while (0) 47 48 #define CHKPV(cond) \ 49 do { \ 50 if ((cond) == nullptr) { \ 51 FI_HILOGE("CHKPV(%{public}s) is null", #cond); \ 52 return; \ 53 } \ 54 } while (0) 55 56 #define CHKPF(cond) \ 57 do { \ 58 if ((cond) == nullptr) { \ 59 FI_HILOGE("CHKPF(%{public}s) is null", #cond); \ 60 return false; \ 61 } \ 62 } while (0) 63 64 #define CHKPS(cond) \ 65 do { \ 66 if ((cond) == nullptr) { \ 67 FI_HILOGE("CHKPS(%{public}s) is null", #cond); \ 68 return {}; \ 69 } \ 70 } while (0) 71 72 #define CHKPC(cond) \ 73 { \ 74 if ((cond) == nullptr) { \ 75 FI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \ 76 continue; \ 77 } \ 78 } 79 80 #define CHKPB(cond) \ 81 { \ 82 if ((cond) == nullptr) { \ 83 FI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \ 84 break; \ 85 } \ 86 } 87 88 #define CHKPR(cond, r) \ 89 do { \ 90 if ((cond) == nullptr) { \ 91 FI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \ 92 return r; \ 93 } \ 94 } while (0) 95 96 #define CHKPP(cond) \ 97 do { \ 98 if ((cond) == nullptr) { \ 99 FI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \ 100 return nullptr; \ 101 } \ 102 } while (0) 103 104 #define CHKPO(cond) \ 105 do { \ 106 if ((cond) == nullptr) { \ 107 FI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \ 108 __FILE__, __LINE__, #cond); \ 109 return {}; \ 110 } \ 111 } while (0) 112 113 #define CHK_PID_AND_TID() \ 114 do { \ 115 FI_HILOGD("%{public}s, (%{public}d), pid:%{public}d, threadId:%{public}" PRIu64, \ 116 __FILE__, __LINE__, GetPid(), GetThisThreadId()); \ 117 } while (0) 118 } // namespace DeviceStatus 119 } // namespace Msdp 120 } // namespace OHOS 121 #endif // DEVICESTATUS_DEFINE_H 122