150a07fd2Sopenharmony_ci/*
250a07fd2Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
350a07fd2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
450a07fd2Sopenharmony_ci * you may not use this file except in compliance with the License.
550a07fd2Sopenharmony_ci * You may obtain a copy of the License at
650a07fd2Sopenharmony_ci *
750a07fd2Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
850a07fd2Sopenharmony_ci *
950a07fd2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1050a07fd2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1150a07fd2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1250a07fd2Sopenharmony_ci * See the License for the specific language governing permissions and
1350a07fd2Sopenharmony_ci * limitations under the License.
1450a07fd2Sopenharmony_ci */
1550a07fd2Sopenharmony_ci
1650a07fd2Sopenharmony_ci#ifndef OHOS_DAUDIO_LOG_H
1750a07fd2Sopenharmony_ci#define OHOS_DAUDIO_LOG_H
1850a07fd2Sopenharmony_ci#include "cJSON.h"
1950a07fd2Sopenharmony_ci
2050a07fd2Sopenharmony_ci#include "hilog/log.h"
2150a07fd2Sopenharmony_ci#include <inttypes.h>
2250a07fd2Sopenharmony_ci
2350a07fd2Sopenharmony_cinamespace OHOS {
2450a07fd2Sopenharmony_cinamespace DistributedHardware {
2550a07fd2Sopenharmony_ci#undef LOG_TAG
2650a07fd2Sopenharmony_ci#define LOG_TAG "DAUDIO"
2750a07fd2Sopenharmony_ci
2850a07fd2Sopenharmony_ci#define DHLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, \
2950a07fd2Sopenharmony_ci    "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__)
3050a07fd2Sopenharmony_ci
3150a07fd2Sopenharmony_ci#define DHLOGI(fmt, ...) HILOG_INFO(LOG_CORE, \
3250a07fd2Sopenharmony_ci    "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__)
3350a07fd2Sopenharmony_ci
3450a07fd2Sopenharmony_ci#define DHLOGW(fmt, ...) HILOG_WARN(LOG_CORE, \
3550a07fd2Sopenharmony_ci    "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__)
3650a07fd2Sopenharmony_ci
3750a07fd2Sopenharmony_ci#define DHLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, \
3850a07fd2Sopenharmony_ci    "[%{public}s][%{public}s]:" fmt, DH_LOG_TAG, __FUNCTION__, ##__VA_ARGS__)
3950a07fd2Sopenharmony_ci
4050a07fd2Sopenharmony_ci#define CHECK_NULL_VOID(ptr)                    \
4150a07fd2Sopenharmony_ci    do {                                        \
4250a07fd2Sopenharmony_ci        if ((ptr) == nullptr) {                 \
4350a07fd2Sopenharmony_ci            DHLOGE("Address pointer is null");  \
4450a07fd2Sopenharmony_ci            return;                             \
4550a07fd2Sopenharmony_ci        }                                       \
4650a07fd2Sopenharmony_ci    } while (0)
4750a07fd2Sopenharmony_ci
4850a07fd2Sopenharmony_ci#define CHECK_NULL_AND_FREE_VOID(ptr, root, ...)     \
4950a07fd2Sopenharmony_ci    do {                                             \
5050a07fd2Sopenharmony_ci        if ((ptr) == nullptr) {                      \
5150a07fd2Sopenharmony_ci            DHLOGE("Address pointer is null");       \
5250a07fd2Sopenharmony_ci            cJSON_Delete(root);                      \
5350a07fd2Sopenharmony_ci            return;                                  \
5450a07fd2Sopenharmony_ci        }                                            \
5550a07fd2Sopenharmony_ci    } while (0)
5650a07fd2Sopenharmony_ci
5750a07fd2Sopenharmony_ci#define CHECK_NULL_RETURN(ptr, ret)             \
5850a07fd2Sopenharmony_ci    do {                                        \
5950a07fd2Sopenharmony_ci        if ((ptr) == nullptr) {                 \
6050a07fd2Sopenharmony_ci            DHLOGE("Address pointer is null");  \
6150a07fd2Sopenharmony_ci            return (ret);                       \
6250a07fd2Sopenharmony_ci        }                                       \
6350a07fd2Sopenharmony_ci    } while (0)
6450a07fd2Sopenharmony_ci
6550a07fd2Sopenharmony_ci#define CHECK_NULL_FREE_RETURN(ptr, ret, root, ...)    \
6650a07fd2Sopenharmony_ci    do {                                               \
6750a07fd2Sopenharmony_ci        if ((ptr) == nullptr) {                        \
6850a07fd2Sopenharmony_ci            DHLOGE("Address pointer is null");         \
6950a07fd2Sopenharmony_ci            cJSON_Delete(root);                        \
7050a07fd2Sopenharmony_ci            return (ret);                              \
7150a07fd2Sopenharmony_ci        }                                              \
7250a07fd2Sopenharmony_ci    } while (0)
7350a07fd2Sopenharmony_ci
7450a07fd2Sopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)   \
7550a07fd2Sopenharmony_ci    do {                                                \
7650a07fd2Sopenharmony_ci        if ((cond)) {                                   \
7750a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);                 \
7850a07fd2Sopenharmony_ci            return (ret);                               \
7950a07fd2Sopenharmony_ci        }                                               \
8050a07fd2Sopenharmony_ci    } while (0)
8150a07fd2Sopenharmony_ci
8250a07fd2Sopenharmony_ci#define CHECK_AND_FREE_RETURN_RET_LOG(cond, ret, root, fmt, ...)    \
8350a07fd2Sopenharmony_ci    do {                                                            \
8450a07fd2Sopenharmony_ci        if ((cond)) {                                               \
8550a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);                             \
8650a07fd2Sopenharmony_ci            cJSON_Delete(root);                                     \
8750a07fd2Sopenharmony_ci            return (ret);                                           \
8850a07fd2Sopenharmony_ci        }                                                           \
8950a07fd2Sopenharmony_ci    } while (0)
9050a07fd2Sopenharmony_ci
9150a07fd2Sopenharmony_ci#define CHECK_AND_FREECHAR_RETURN_RET_LOG(cond, ret, data, fmt, ...)    \
9250a07fd2Sopenharmony_ci    do {                                                                \
9350a07fd2Sopenharmony_ci        if ((cond)) {                                                   \
9450a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);                                 \
9550a07fd2Sopenharmony_ci            cJSON_free(data);                                           \
9650a07fd2Sopenharmony_ci            return (ret);                                               \
9750a07fd2Sopenharmony_ci        }                                                               \
9850a07fd2Sopenharmony_ci    } while (0)
9950a07fd2Sopenharmony_ci
10050a07fd2Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...)   \
10150a07fd2Sopenharmony_ci    do {                                       \
10250a07fd2Sopenharmony_ci        if ((cond)) {                          \
10350a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);        \
10450a07fd2Sopenharmony_ci            return;                            \
10550a07fd2Sopenharmony_ci        }                                      \
10650a07fd2Sopenharmony_ci    } while (0)
10750a07fd2Sopenharmony_ci
10850a07fd2Sopenharmony_ci#define CHECK_AND_FREE_RETURN_LOG(cond, root, fmt, ...)   \
10950a07fd2Sopenharmony_ci    do {                                                  \
11050a07fd2Sopenharmony_ci        if ((cond)) {                                     \
11150a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);                   \
11250a07fd2Sopenharmony_ci            cJSON_Delete(root);                           \
11350a07fd2Sopenharmony_ci            return;                                       \
11450a07fd2Sopenharmony_ci        }                                                 \
11550a07fd2Sopenharmony_ci    } while (0)
11650a07fd2Sopenharmony_ci
11750a07fd2Sopenharmony_ci#define CHECK_AND_LOG(cond, fmt, ...)          \
11850a07fd2Sopenharmony_ci    do {                                       \
11950a07fd2Sopenharmony_ci        if ((cond)) {                          \
12050a07fd2Sopenharmony_ci            DHLOGE(fmt, ##__VA_ARGS__);        \
12150a07fd2Sopenharmony_ci        }                                      \
12250a07fd2Sopenharmony_ci    } while (0)
12350a07fd2Sopenharmony_ci} // namespace DistributedHardware
12450a07fd2Sopenharmony_ci} // namespace OHOS
12550a07fd2Sopenharmony_ci#endif // OHOS_DAUDIO_LOG_H
126