• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "PulseAudio"
21 #endif
22 
23 #include <stdio.h>
24 
25 #include "hilog/log.h"
26 #ifdef FEATURE_HITRACE_METER
27 #include "hitrace_meter_c.h"
28 #define HITRACE_AUDIO_TAG (1ULL << 35)
29 #endif
30 
31 #undef LOG_DOMAIN
32 #define LOG_DOMAIN 0xD002B12
33 #ifndef OHOS_DEBUG
34 #define DECORATOR_HILOG(op, fmt, args...) \
35     do {                                  \
36         op(LOG_CORE, "[%{public}s]" fmt, __FUNCTION__, ##args);        \
37     } while (0)
38 #else
39 #define DECORATOR_HILOG(op, fmt, args...)                                                \
40     do {                                                                                 \
41         op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
42     } while (0)
43 #endif
44 
45 #define AUDIO_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
46 #define AUDIO_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
47 #define AUDIO_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
48 #define AUDIO_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
49 #define AUDIO_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
50 
51 #define AUDIO_OK 0
52 #define AUDIO_INVALID_PARAM (-1)
53 #define AUDIO_INIT_FAIL (-2)
54 #define AUDIO_ERR (-3)
55 #define AUDIO_PERMISSION_DENIED (-4)
56 
57 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
58     do {                                               \
59         if (!(cond)) {                                 \
60             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);            \
61             return ret;                                \
62         }                                              \
63     } while (0)
64 
65 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
66     do {                                               \
67         if (!(cond)) {                                 \
68             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);            \
69             return;                                    \
70         }                                              \
71     } while (0)
72 
73 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)            \
74     do {                                               \
75         if (!(cond)) {                                 \
76             AUDIO_ERR_LOG(fmt, ##__VA_ARGS__);            \
77             break;                                     \
78         }                                              \
79     } while (0)
80 
81 
82 #ifndef OHOS_DEBUG
83 #define DECORATOR_PRERELEASE_HILOG(op, fmt, args...) \
84     do {                                  \
85         op(LOG_ONLY_PRERELEASE, "[%{public}s]" fmt, __FUNCTION__, ##args);        \
86     } while (0)
87 #else
88 #define DECORATOR_PRERELEASE_HILOG(op, fmt, args...)                                                \
89     do {                                                                                 \
90         op(LOG_ONLY_PRERELEASE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \
91     } while (0)
92 #endif
93 
94 #define AUDIO_PRERELEASE_LOGD(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
95 #define AUDIO_PRERELEASE_LOGE(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
96 #define AUDIO_PRERELEASE_LOGW(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
97 #define AUDIO_PRERELEASE_LOGI(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
98 #define AUDIO_PRERELEASE_LOGF(fmt, ...) DECORATOR_PRERELEASE_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
99 
100 #define CHECK_AND_RETURN_RET_PRELOG(cond, ret, fmt, ...)  \
101     do {                                                  \
102         if (!(cond)) {                                    \
103             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
104             return ret;                                   \
105         }                                                 \
106     } while (0)
107 
108 #define CHECK_AND_RETURN_PRELOG(cond, fmt, ...)           \
109     do {                                                  \
110         if (!(cond)) {                                    \
111             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
112             return;                                       \
113         }                                                 \
114     } while (0)
115 
116 #define CHECK_AND_BREAK_PRELOG(cond, fmt, ...)            \
117     if (1) {                                              \
118         if (!(cond)) {                                    \
119             AUDIO_PRERELEASE_LOGE(fmt, ##__VA_ARGS__);    \
120             break;                                        \
121         }                                                 \
122     } else void (0)
123 
124 #define CHECK_AND_CONTINUE_PRELOG(cond, fmt, ...)         \
125     if (1) {                                              \
126         if (!(cond)) {                                    \
127             AUDIO_PRERELEASE_LOGD(fmt, ##__VA_ARGS__);    \
128             continue;                                     \
129         }                                                 \
130     } else void (0)
131 
132 //  for trace
133 // CallEnd is needed. Take care of the goto.
CallStart(const char * traceName)134 inline void CallStart(const char *traceName)
135 {
136 #ifdef FEATURE_HITRACE_METER
137     HiTraceStartTrace(HITRACE_AUDIO_TAG, traceName);
138 #endif
139 }
140 
CallEnd()141 inline void CallEnd()
142 {
143 #ifdef FEATURE_HITRACE_METER
144     HiTraceFinishTrace(HITRACE_AUDIO_TAG);
145 #endif
146 }
147 #endif // OHOS_AUDIO_LOG_H
148