• 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_MEDIA_LOG_H
17 #define OHOS_MEDIA_LOG_H
18 
19 #include <stdio.h>
20 
21 #include "hilog/log.h"
22 
23 #undef LOG_DOMAIN
24 #undef LOG_TAG
25 #define LOG_DOMAIN 0xD002B00
26 #define LOG_TAG "MultiMedia"
27 
28 #ifndef OHOS_DEBUG
29 #define DECORATOR_HILOG(op, fmt, args...) \
30     do {                                  \
31         op(LOG_CORE, fmt, ##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 MEDIA_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__)
41 #define MEDIA_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__)
42 #define MEDIA_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__)
43 #define MEDIA_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__)
44 #define MEDIA_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__)
45 
46 #define MEDIA_OK 0
47 #define MEDIA_INVALID_PARAM (-1)
48 #define MEDIA_INIT_FAIL (-2)
49 #define MEDIA_ERR (-3)
50 #define MEDIA_PERMISSION_DENIED (-4)
51 
52 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
53     do {                                               \
54         if (!(cond)) {                                 \
55             MEDIA_ERR_LOG(fmt, ##__VA_ARGS__);            \
56             return ret;                                \
57         }                                              \
58     } while (0)
59 
60 #define CHECK_AND_RETURN(cond)                      \
61     do {                                            \
62         if (!(cond)) {                                \
63             MEDIA_ERR_LOG("%{public}s, check failed!", #cond); \
64             return;                                 \
65         }                                           \
66     } while (0)
67 
68 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
69     do {                                               \
70         if (!(cond)) {                                 \
71             MEDIA_ERR_LOG(fmt, ##__VA_ARGS__);            \
72             return;                                    \
73         }                                              \
74     } while (0)
75 
76 #define CHECK_AND_BREAK_LOG(cond, fmt, ...)            \
77     do {                                               \
78         if (!(cond)) {                                 \
79             MEDIA_ERR_LOG(fmt, ##__VA_ARGS__);            \
80             break;                                     \
81         }                                              \
82     } while (0)
83 
84 #endif // OHOS_MEDIA_LOG_H
85