1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#ifndef DEVICESTATUS_DEFINE_H 17f857971dSopenharmony_ci#define DEVICESTATUS_DEFINE_H 18f857971dSopenharmony_ci 19f857971dSopenharmony_ci#include <chrono> 20f857971dSopenharmony_ci 21f857971dSopenharmony_ci#include "devicestatus_errors.h" 22f857971dSopenharmony_ci#include "fi_log.h" 23f857971dSopenharmony_ci#include "include/util.h" 24f857971dSopenharmony_ci 25f857971dSopenharmony_cinamespace OHOS { 26f857971dSopenharmony_cinamespace Msdp { 27f857971dSopenharmony_cinamespace DeviceStatus { 28f857971dSopenharmony_ci#define FI_PKG_NAME "ohos.msdp.fusioninteraction" 29f857971dSopenharmony_ci#define COOPERATE_PERMISSION "ohos.permission.COOPERATE_MANAGER" 30f857971dSopenharmony_ci 31f857971dSopenharmony_ciusing TimeStamp = std::chrono::high_resolution_clock::time_point; 32f857971dSopenharmony_ci 33f857971dSopenharmony_ci#ifndef RET_OK 34f857971dSopenharmony_ci #define RET_OK (0) 35f857971dSopenharmony_ci#endif 36f857971dSopenharmony_ci 37f857971dSopenharmony_ci#ifndef RET_ERR 38f857971dSopenharmony_ci #define RET_ERR (-1) 39f857971dSopenharmony_ci#endif 40f857971dSopenharmony_ci 41f857971dSopenharmony_ci#define CHKPL(cond) \ 42f857971dSopenharmony_ci do { \ 43f857971dSopenharmony_ci if ((cond) == nullptr) { \ 44f857971dSopenharmony_ci FI_HILOGW("CHKPL(%{public}s) is null, do nothing", #cond); \ 45f857971dSopenharmony_ci } \ 46f857971dSopenharmony_ci } while (0) 47f857971dSopenharmony_ci 48f857971dSopenharmony_ci#define CHKPV(cond) \ 49f857971dSopenharmony_ci do { \ 50f857971dSopenharmony_ci if ((cond) == nullptr) { \ 51f857971dSopenharmony_ci FI_HILOGE("CHKPV(%{public}s) is null", #cond); \ 52f857971dSopenharmony_ci return; \ 53f857971dSopenharmony_ci } \ 54f857971dSopenharmony_ci } while (0) 55f857971dSopenharmony_ci 56f857971dSopenharmony_ci#define CHKPF(cond) \ 57f857971dSopenharmony_ci do { \ 58f857971dSopenharmony_ci if ((cond) == nullptr) { \ 59f857971dSopenharmony_ci FI_HILOGE("CHKPF(%{public}s) is null", #cond); \ 60f857971dSopenharmony_ci return false; \ 61f857971dSopenharmony_ci } \ 62f857971dSopenharmony_ci } while (0) 63f857971dSopenharmony_ci 64f857971dSopenharmony_ci#define CHKPS(cond) \ 65f857971dSopenharmony_ci do { \ 66f857971dSopenharmony_ci if ((cond) == nullptr) { \ 67f857971dSopenharmony_ci FI_HILOGE("CHKPS(%{public}s) is null", #cond); \ 68f857971dSopenharmony_ci return {}; \ 69f857971dSopenharmony_ci } \ 70f857971dSopenharmony_ci } while (0) 71f857971dSopenharmony_ci 72f857971dSopenharmony_ci#define CHKPC(cond) \ 73f857971dSopenharmony_ci { \ 74f857971dSopenharmony_ci if ((cond) == nullptr) { \ 75f857971dSopenharmony_ci FI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \ 76f857971dSopenharmony_ci continue; \ 77f857971dSopenharmony_ci } \ 78f857971dSopenharmony_ci } 79f857971dSopenharmony_ci 80f857971dSopenharmony_ci#define CHKPB(cond) \ 81f857971dSopenharmony_ci { \ 82f857971dSopenharmony_ci if ((cond) == nullptr) { \ 83f857971dSopenharmony_ci FI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \ 84f857971dSopenharmony_ci break; \ 85f857971dSopenharmony_ci } \ 86f857971dSopenharmony_ci } 87f857971dSopenharmony_ci 88f857971dSopenharmony_ci#define CHKPR(cond, r) \ 89f857971dSopenharmony_ci do { \ 90f857971dSopenharmony_ci if ((cond) == nullptr) { \ 91f857971dSopenharmony_ci FI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \ 92f857971dSopenharmony_ci return r; \ 93f857971dSopenharmony_ci } \ 94f857971dSopenharmony_ci } while (0) 95f857971dSopenharmony_ci 96f857971dSopenharmony_ci#define CHKPP(cond) \ 97f857971dSopenharmony_ci do { \ 98f857971dSopenharmony_ci if ((cond) == nullptr) { \ 99f857971dSopenharmony_ci FI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \ 100f857971dSopenharmony_ci return nullptr; \ 101f857971dSopenharmony_ci } \ 102f857971dSopenharmony_ci } while (0) 103f857971dSopenharmony_ci 104f857971dSopenharmony_ci#define CHKPO(cond) \ 105f857971dSopenharmony_ci do { \ 106f857971dSopenharmony_ci if ((cond) == nullptr) { \ 107f857971dSopenharmony_ci FI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \ 108f857971dSopenharmony_ci __FILE__, __LINE__, #cond); \ 109f857971dSopenharmony_ci return {}; \ 110f857971dSopenharmony_ci } \ 111f857971dSopenharmony_ci } while (0) 112f857971dSopenharmony_ci 113f857971dSopenharmony_ci#define CHK_PID_AND_TID() \ 114f857971dSopenharmony_ci do { \ 115f857971dSopenharmony_ci FI_HILOGD("%{public}s, (%{public}d), pid:%{public}d, threadId:%{public}" PRIu64, \ 116f857971dSopenharmony_ci __FILE__, __LINE__, GetPid(), GetThisThreadId()); \ 117f857971dSopenharmony_ci } while (0) 118f857971dSopenharmony_ci} // namespace DeviceStatus 119f857971dSopenharmony_ci} // namespace Msdp 120f857971dSopenharmony_ci} // namespace OHOS 121f857971dSopenharmony_ci#endif // DEVICESTATUS_DEFINE_H 122