• 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_AV_TRANSPORT_LOG_H
17 #define OHOS_AV_TRANSPORT_LOG_H
18 
19 #include <cinttypes>
20 #include <string>
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 typedef enum {
25     DH_LOG_DEBUG,
26     DH_LOG_INFO,
27     DH_LOG_WARN,
28     DH_LOG_ERROR,
29 } DHLogLevel;
30 
31 void AVTransLog(DHLogLevel logLevel, const char *fmt, ...);
32 
33 #define AVTRANS_LOGD(fmt, ...) AVTransLog(DH_LOG_DEBUG, \
34     (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
35 
36 #define AVTRANS_LOGI(fmt, ...) AVTransLog(DH_LOG_INFO, \
37     (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
38 
39 #define AVTRANS_LOGW(fmt, ...) AVTransLog(DH_LOG_WARN, \
40     (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
41 
42 #define AVTRANS_LOGE(fmt, ...) AVTransLog(DH_LOG_ERROR, \
43     (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__)
44 
45 std::string GetAnonyString(const std::string &value);
46 std::string GetAnonyInt32(const int32_t value);
47 
48 #ifndef TRUE_RETURN
49 #define TRUE_RETURN(exec, fmt, args...)                                                                       \
50     do {                                                                                                      \
51         bool retCode = (exec);                                                                                \
52         if (retCode) {                                                                                        \
53             AVTRANS_LOGE(fmt, ##args);                                                                        \
54             return;                                                                                           \
55         }                                                                                                     \
56     } while (0)
57 #endif
58 
59 #ifndef TRUE_RETURN_V
60 #define TRUE_RETURN_V(exec, ret)                                                                              \
61     do {                                                                                                      \
62         bool retCode = (exec);                                                                                \
63         if (retCode) {                                                                                        \
64             return ret;                                                                                       \
65         }                                                                                                     \
66     } while (0)
67 #endif
68 
69 #ifndef TRUE_RETURN_V_MSG_E
70 #define TRUE_RETURN_V_MSG_E(exec, ret, fmt, args...)                                                          \
71     do {                                                                                                      \
72         bool retCode = (exec);                                                                                \
73         if (retCode) {                                                                                        \
74             AVTRANS_LOGE(fmt, ##args);                                                                        \
75             return ret;                                                                                       \
76         }                                                                                                     \
77     } while (0)
78 #endif
79 
80 #ifndef TRUE_RETURN_V_MSG_D
81 #define TRUE_RETURN_V_MSG_D(exec, ret, fmt, args...)                                                          \
82     do {                                                                                                      \
83         bool retCode = (exec);                                                                                \
84         if (retCode) {                                                                                        \
85             AVTRANS_LOGD(fmt, ##args);                                                                        \
86             return ret;                                                                                       \
87         }                                                                                                     \
88     } while (0)
89 #endif
90 
91 #ifndef TRUE_LOG_MSG
92 #define TRUE_LOG_MSG(exec, fmt, args...)                                                                      \
93     do {                                                                                                      \
94         bool retCode = (exec);                                                                                \
95         if (retCode) {                                                                                        \
96             AVTRANS_LOGE(fmt, ##args);                                                                        \
97         }                                                                                                     \
98     } while (0)
99 #endif
100 } // namespace DistributedHardware
101 } // namespace OHOS
102 #endif // OHOS_AV_TRANSPORT_LOG_H