1 /* 2 * Copyright (c) 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_DCAMERA_LOG_H 17 #define OHOS_DCAMERA_LOG_H 18 19 namespace OHOS { 20 namespace DistributedHardware { 21 typedef enum { 22 DH_LOG_DEBUG, 23 DH_LOG_INFO, 24 DH_LOG_WARN, 25 DH_LOG_ERROR, 26 } DHLogLevel; 27 28 void DHLog(DHLogLevel logLevel, const char *fmt, ...); 29 #define CHECK_NULL_RETURN(cond, ret, ...) \ 30 do { \ 31 if ((cond)) { \ 32 return (ret); \ 33 } \ 34 } while (0) 35 36 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 37 do { \ 38 if ((cond)) { \ 39 DHLOGE(fmt, ##__VA_ARGS__); \ 40 return (ret); \ 41 } \ 42 } while (0) 43 44 #define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 45 do { \ 46 if ((cond)) { \ 47 DHLOGE(fmt, ##__VA_ARGS__); \ 48 return; \ 49 } \ 50 } while (0) 51 52 #define CHECK_AND_LOG(cond, fmt, ...) \ 53 do { \ 54 if ((cond)) { \ 55 DHLOGE(fmt, ##__VA_ARGS__); \ 56 } \ 57 } while (0) 58 59 #define CHECK_NULL_FREE_RETURN(ptr, ret, root, ...) \ 60 do { \ 61 if ((ptr) == nullptr) { \ 62 DHLOGE("Address pointer is null"); \ 63 cJSON_Delete((root)); \ 64 return (ret); \ 65 } \ 66 } while (0) 67 68 #define CHECK_AND_FREE_RETURN_RET_LOG(cond, ret, root, fmt, ...) \ 69 do { \ 70 if ((cond)) { \ 71 DHLOGE(fmt, ##__VA_ARGS__); \ 72 cJSON_Delete((root)); \ 73 return (ret); \ 74 } \ 75 } while (0) 76 77 #define ULOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ 78 (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 79 80 #define ULOGI(fmt, ...) DHLog(DH_LOG_INFO, \ 81 (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 82 83 #define ULOGW(fmt, ...) DHLog(DH_LOG_WARN, \ 84 (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 85 86 #define ULOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ 87 (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 88 } // namespace DistributedHardware 89 } // namespace OHOS 90 #endif // OHOS_DCAMERA_LOG_H 91