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 27 #undef LOG_DOMAIN 28 #define LOG_DOMAIN 0xD002B12 29 #ifndef OHOS_DEBUG 30 #define DECORATOR_HILOG(op, fmt, args...) \ 31 do { \ 32 op(LOG_CORE, "[%{public}s]" fmt, __FUNCTION__, ##args); \ 33 } while (0) 34 #else 35 #define DECORATOR_HILOG(op, fmt, args...) \ 36 do { \ 37 op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \ 38 } while (0) 39 #endif 40 41 #define AUDIO_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) 42 #define AUDIO_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) 43 #define AUDIO_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) 44 #define AUDIO_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) 45 #define AUDIO_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) 46 47 #define AUDIO_OK 0 48 #define AUDIO_INVALID_PARAM (-1) 49 #define AUDIO_INIT_FAIL (-2) 50 #define AUDIO_ERR (-3) 51 #define AUDIO_PERMISSION_DENIED (-4) 52 53 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 54 do { \ 55 if (!(cond)) { \ 56 AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ 57 return ret; \ 58 } \ 59 } while (0) 60 61 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 62 do { \ 63 if (!(cond)) { \ 64 AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ 65 return; \ 66 } \ 67 } while (0) 68 69 #define CHECK_AND_BREAK_LOG(cond, fmt, ...) \ 70 do { \ 71 if (!(cond)) { \ 72 AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ 73 break; \ 74 } \ 75 } while (0) 76 77 #endif // OHOS_AUDIO_LOG_H 78