180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef OHOS_AVSESSION_LOG_H 1780922886Sopenharmony_ci#define OHOS_AVSESSION_LOG_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <cinttypes> 2080922886Sopenharmony_ci 2180922886Sopenharmony_ci#include "hilog/log.h" 2280922886Sopenharmony_ci 2380922886Sopenharmony_ci#undef LOG_DOMAIN 2480922886Sopenharmony_ci#define LOG_DOMAIN 0xD002B91 2580922886Sopenharmony_ci 2680922886Sopenharmony_ci#undef LOG_TAG 2780922886Sopenharmony_ci#define LOG_TAG "AVSession" 2880922886Sopenharmony_ci 2980922886Sopenharmony_ci#define AV_SESSION_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 3080922886Sopenharmony_ci 3180922886Sopenharmony_ci#define DECORATOR_HILOG(func, fmt, args...) \ 3280922886Sopenharmony_ci do { \ 3380922886Sopenharmony_ci (void)func(LOG_CORE, "[%{public}s()-%{public}s:%{public}d] " fmt, __FUNCTION__, AV_SESSION_FILENAME, __LINE__, \ 3480922886Sopenharmony_ci ##args); \ 3580922886Sopenharmony_ci } while (0) 3680922886Sopenharmony_ci 3780922886Sopenharmony_ci#define SLOGD(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 3880922886Sopenharmony_ci#define SLOGI(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) 3980922886Sopenharmony_ci#define SLOGW(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) 4080922886Sopenharmony_ci#define SLOGE(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 4180922886Sopenharmony_ci#define SLOGF(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 4280922886Sopenharmony_ci 4380922886Sopenharmony_ci#define POINTER_MASK 0x00FFFFFF 4480922886Sopenharmony_ci#define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr)) 4580922886Sopenharmony_ci 4680922886Sopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 4780922886Sopenharmony_ci do { \ 4880922886Sopenharmony_ci if (!(cond)) { \ 4980922886Sopenharmony_ci SLOGE(fmt, ##__VA_ARGS__); \ 5080922886Sopenharmony_ci return ret; \ 5180922886Sopenharmony_ci } \ 5280922886Sopenharmony_ci } while (0) 5380922886Sopenharmony_ci 5480922886Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 5580922886Sopenharmony_ci do { \ 5680922886Sopenharmony_ci if (!(cond)) { \ 5780922886Sopenharmony_ci SLOGE(fmt, ##__VA_ARGS__); \ 5880922886Sopenharmony_ci return; \ 5980922886Sopenharmony_ci } \ 6080922886Sopenharmony_ci } while (0) 6180922886Sopenharmony_ci 6280922886Sopenharmony_ci#define CHECK_AND_BREAK_LOG(cond, fmt, ...) \ 6380922886Sopenharmony_ci do { \ 6480922886Sopenharmony_ci if (!(cond)) { \ 6580922886Sopenharmony_ci SLOGE(fmt, ##__VA_ARGS__); \ 6680922886Sopenharmony_ci break; \ 6780922886Sopenharmony_ci } \ 6880922886Sopenharmony_ci } while (0) 6980922886Sopenharmony_ci 7080922886Sopenharmony_ci#define CHECK_AND_CONTINUE_LOG(cond, fmt, ...) \ 7180922886Sopenharmony_ci do { \ 7280922886Sopenharmony_ci if (!(cond)) { \ 7380922886Sopenharmony_ci SLOGE(fmt, ##__VA_ARGS__); \ 7480922886Sopenharmony_ci continue; \ 7580922886Sopenharmony_ci } \ 7680922886Sopenharmony_ci } while (0) 7780922886Sopenharmony_ci 7880922886Sopenharmony_ci#define CHECK_AND_PRINT_LOG(cond, fmt, ...) \ 7980922886Sopenharmony_ci do { \ 8080922886Sopenharmony_ci if (!(cond)) { \ 8180922886Sopenharmony_ci SLOGE(fmt, ##__VA_ARGS__); \ 8280922886Sopenharmony_ci } \ 8380922886Sopenharmony_ci } while (0) 8480922886Sopenharmony_ci 8580922886Sopenharmony_ci#define CHECK_AND_RETURN_RET(cond, ret) \ 8680922886Sopenharmony_ci do { \ 8780922886Sopenharmony_ci if (!(cond)) { \ 8880922886Sopenharmony_ci SLOGE("%{public}s, check failed! ret = %{public}s", #cond, #ret); \ 8980922886Sopenharmony_ci return ret; \ 9080922886Sopenharmony_ci } \ 9180922886Sopenharmony_ci } while (0) 9280922886Sopenharmony_ci 9380922886Sopenharmony_ci#define CHECK_AND_RETURN(cond) \ 9480922886Sopenharmony_ci do { \ 9580922886Sopenharmony_ci if (!(cond)) { \ 9680922886Sopenharmony_ci SLOGE("%{public}s, check failed!", #cond); \ 9780922886Sopenharmony_ci return; \ 9880922886Sopenharmony_ci } \ 9980922886Sopenharmony_ci } while (0) 10080922886Sopenharmony_ci 10180922886Sopenharmony_ci#define CHECK_AND_BREAK(cond) \ 10280922886Sopenharmony_ci do { \ 10380922886Sopenharmony_ci if (!(cond)) { \ 10480922886Sopenharmony_ci SLOGE("%{public}s, check failed!", #cond); \ 10580922886Sopenharmony_ci break; \ 10680922886Sopenharmony_ci } \ 10780922886Sopenharmony_ci } while (0) 10880922886Sopenharmony_ci 10980922886Sopenharmony_ci#define CHECK_AND_CONTINUE(cond) \ 11080922886Sopenharmony_ci do { \ 11180922886Sopenharmony_ci if (!(cond)) { \ 11280922886Sopenharmony_ci SLOGE("%{public}s, check failed!", #cond); \ 11380922886Sopenharmony_ci continue; \ 11480922886Sopenharmony_ci } \ 11580922886Sopenharmony_ci } while (0) 11680922886Sopenharmony_ci 11780922886Sopenharmony_ci#endif // OHOS_AVSESSION_LOG_H 118