1 /*
2  * Copyright (c) 2022 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 OHOS_AVSESSION_LOG_H
17 #define OHOS_AVSESSION_LOG_H
18 
19 #include <cinttypes>
20 
21 #include "hilog/log.h"
22 
23 #undef LOG_DOMAIN
24 #define LOG_DOMAIN 0xD002B91
25 
26 #undef LOG_TAG
27 #define LOG_TAG "AVSession"
28 
29 #define AV_SESSION_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
30 
31 #define DECORATOR_HILOG(func, fmt, args...)                                                      \
32     do {                                                                                         \
33         (void)func(LOG_CORE, "[%{public}s()-%{public}s:%{public}d] " fmt, __FUNCTION__, AV_SESSION_FILENAME, __LINE__, \
34                    ##args); \
35     } while (0)
36 
37 #define SLOGD(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
38 #define SLOGI(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
39 #define SLOGW(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
40 #define SLOGE(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
41 #define SLOGF(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
42 
43 #define POINTER_MASK 0x00FFFFFF
44 #define FAKE_POINTER(addr) (POINTER_MASK & reinterpret_cast<uintptr_t>(addr))
45 
46 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
47     do {                                               \
48         if (!(cond)) {                                 \
49             SLOGE(fmt, ##__VA_ARGS__);                 \
50             return ret;                                \
51         }                                              \
52     } while (0)
53 
54 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
55     do {                                               \
56         if (!(cond)) {                                 \
57             SLOGE(fmt, ##__VA_ARGS__);                 \
58             return;                                    \
59         }                                              \
60     } while (0)
61 
62 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)            \
63     do {                                               \
64         if (!(cond)) {                                 \
65             SLOGE(fmt, ##__VA_ARGS__);                 \
66             break;                                     \
67         }                                              \
68     } while (0)
69 
70 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...)         \
71     do {                                               \
72         if (!(cond)) {                                 \
73             SLOGE(fmt, ##__VA_ARGS__);                 \
74             continue;                                  \
75         }                                              \
76     } while (0)
77 
78 #define CHECK_AND_PRINT_LOG(cond, fmt, ...)            \
79     do {                                               \
80         if (!(cond)) {                                 \
81             SLOGE(fmt, ##__VA_ARGS__);                 \
82         }                                              \
83     } while (0)
84 
85 #define CHECK_AND_RETURN_RET(cond, ret)                \
86     do {                                               \
87         if (!(cond)) {                                 \
88             SLOGE("%{public}s, check failed! ret = %{public}s", #cond, #ret); \
89             return ret;                                \
90         }                                              \
91     } while (0)
92 
93 #define CHECK_AND_RETURN(cond)                         \
94     do {                                               \
95         if (!(cond)) {                                 \
96             SLOGE("%{public}s, check failed!", #cond); \
97             return;                                    \
98         }                                              \
99     } while (0)
100 
101 #define CHECK_AND_BREAK(cond)                          \
102     do {                                               \
103         if (!(cond)) {                                 \
104             SLOGE("%{public}s, check failed!", #cond); \
105             break;                                     \
106         }                                              \
107     } while (0)
108 
109 #define CHECK_AND_CONTINUE(cond)                       \
110         if (!(cond)) {                                 \
111             SLOGE("%{public}s, check failed!", #cond); \
112             continue;                                  \
113         }
114 #endif // OHOS_AVSESSION_LOG_H
115