• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_AUDIO_LOG_H
17 #define OHOS_AUDIO_LOG_H
18 
19 #ifndef LOG_TAG
20 #define LOG_TAG "AudioFramework"
21 #endif
22 
23 #include <stdio.h>
24 #include "hilog/log.h"
25 
26 #undef LOG_DOMAIN
27 #define LOG_DOMAIN 0xD002B12
28 #ifndef OHOS_DEBUG
29 #define DECORATOR_HILOG(op, fmt, args...) \
30     do {                                  \
31         op(LOG_CORE, "[%{public}s]" fmt, __FUNCTION__, ##args);        \
32     } while (0)
33 #else
34 #define DECORATOR_HILOG(op, fmt, args...)                                                \
35     do {                                                                                 \
36         op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
37     } while (0)
38 #endif
39 
40 #define AUDIO_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
41 #define AUDIO_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
42 #define AUDIO_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
43 #define AUDIO_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
44 #define AUDIO_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
45 
46 #define AUDIO_OK 0
47 #define AUDIO_INVALID_PARAM (-1)
48 #define AUDIO_INIT_FAIL (-2)
49 #define AUDIO_ERR (-3)
50 #define AUDIO_PERMISSION_DENIED (-4)
51 
52 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
53     do {                                               \
54         if (!(cond)) {                                 \
55             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);         \
56             return ret;                                \
57         }                                              \
58     } while (0)
59 
60 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
61     do {                                               \
62         if (!(cond)) {                                 \
63             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);         \
64             return;                                    \
65         }                                              \
66     } while (0)
67 
68 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)            \
69     if (1) {                                           \
70         if (!(cond)) {                                 \
71             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);         \
72             break;                                     \
73         }                                              \
74     } else void (0)
75 
76 #define CHECK_AND_RETURN_RET(cond, ret, ...)           \
77     do {                                               \
78         if (!(cond)) {                                 \
79             return ret;                                \
80         }                                              \
81     } while (0)
82 
83 #define CHECK_AND_RETURN(cond, ...)                    \
84     do {                                               \
85         if (!(cond)) {                                 \
86             return;                                    \
87         }                                              \
88     } while (0)
89 
90 #define CHECK_AND_CONTINUE(cond)                       \
91     if (1) {                                           \
92         if (!(cond)) {                                 \
93             continue;                                  \
94         }                                              \
95     } else void (0)
96 
97 #define CHECK_AND_CONTINUE_LOG(cond, fmt, ...)         \
98     if (1) {                                           \
99         if (!(cond)) {                                 \
100             AUDIO_DEBUG_LOG(fmt, ##__VA_ARGS__);       \
101             continue;                                  \
102         }                                              \
103     } else void (0)
104 
105 #define JUDGE_AND_INFO_LOG(cond, fmt, ...)             \
106     if (1) {                                           \
107         if (cond) {                                    \
108             AUDIO_INFO_LOG(fmt, ##__VA_ARGS__);        \
109         }                                              \
110     } else void (0)
111 
112 #define JUDGE_AND_ERR_LOG(cond, fmt, ...)              \
113     if (1) {                                           \
114         if (cond) {                                    \
115             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);         \
116         }                                              \
117     } else void (0)
118 
119 #ifndef OHOS_DEBUG
120 #define DECORATOR_PRERELEASE_HILOG(op, fmt, args...) \
121     do {                                  \
122         op(LOG_ONLY_PRERELEASE, "[%{public}s]" fmt, __FUNCTION__, ##args);        \
123     } while (0)
124 #else
125 #define DECORATOR_PRERELEASE_HILOG(op, fmt, args...)                                                \
126     do {                                                                                 \
127         op(LOG_ONLY_PRERELEASE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
128     } while (0)
129 #endif
130 
131 #define AUDIO_PRERELEASE_LOGD(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
132 #define AUDIO_PRERELEASE_LOGE(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
133 #define AUDIO_PRERELEASE_LOGW(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
134 #define AUDIO_PRERELEASE_LOGI(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
135 #define AUDIO_PRERELEASE_LOGF(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
136 
137 #define CHECK_AND_RETURN_RET_PRELOG(cond, ret, fmt, ...)  \
138     do {                                                  \
139         if (!(cond)) {                                    \
140             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
141             return ret;                                   \
142         }                                                 \
143     } while (0)
144 
145 #define CHECK_AND_RETURN_PRELOG(cond, fmt, ...)           \
146     do {                                                  \
147         if (!(cond)) {                                    \
148             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
149             return;                                       \
150         }                                                 \
151     } while (0)
152 
153 #define CHECK_AND_BREAK_PRELOG(cond, fmt, ...)            \
154     if (1) {                                              \
155         if (!(cond)) {                                    \
156             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
157             break;                                        \
158         }                                                 \
159     } else void (0)
160 
161 #define CHECK_AND_CONTINUE_PRELOG(cond, fmt, ...)         \
162     if (1) {                                              \
163         if (!(cond)) {                                    \
164             AUDIO_PRERELEASE_LOGD(fmt, ##__VA_ARGS__);    \
165             continue;                                     \
166         }                                                 \
167     } else void (0)
168 #endif // OHOS_AUDIO_LOG_H
169