11c1b0f19Sopenharmony_ci/* 21c1b0f19Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 31c1b0f19Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 41c1b0f19Sopenharmony_ci * you may not use this file except in compliance with the License. 51c1b0f19Sopenharmony_ci * You may obtain a copy of the License at 61c1b0f19Sopenharmony_ci * 71c1b0f19Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 81c1b0f19Sopenharmony_ci * 91c1b0f19Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 101c1b0f19Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 111c1b0f19Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 121c1b0f19Sopenharmony_ci * See the License for the specific language governing permissions and 131c1b0f19Sopenharmony_ci * limitations under the License. 141c1b0f19Sopenharmony_ci */ 151c1b0f19Sopenharmony_ci 161c1b0f19Sopenharmony_ci#ifndef OHOS_DCAMERA_LOG_H 171c1b0f19Sopenharmony_ci#define OHOS_DCAMERA_LOG_H 181c1b0f19Sopenharmony_ci 191c1b0f19Sopenharmony_cinamespace OHOS { 201c1b0f19Sopenharmony_cinamespace DistributedHardware { 211c1b0f19Sopenharmony_citypedef enum { 221c1b0f19Sopenharmony_ci DH_LOG_DEBUG, 231c1b0f19Sopenharmony_ci DH_LOG_INFO, 241c1b0f19Sopenharmony_ci DH_LOG_WARN, 251c1b0f19Sopenharmony_ci DH_LOG_ERROR, 261c1b0f19Sopenharmony_ci} DHLogLevel; 271c1b0f19Sopenharmony_ci 281c1b0f19Sopenharmony_civoid DHLog(DHLogLevel logLevel, const char *fmt, ...); 291c1b0f19Sopenharmony_ci#define CHECK_NULL_RETURN(cond, ret, ...) \ 301c1b0f19Sopenharmony_ci do { \ 311c1b0f19Sopenharmony_ci if ((cond)) { \ 321c1b0f19Sopenharmony_ci return (ret); \ 331c1b0f19Sopenharmony_ci } \ 341c1b0f19Sopenharmony_ci } while (0) 351c1b0f19Sopenharmony_ci 361c1b0f19Sopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 371c1b0f19Sopenharmony_ci do { \ 381c1b0f19Sopenharmony_ci if ((cond)) { \ 391c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 401c1b0f19Sopenharmony_ci return (ret); \ 411c1b0f19Sopenharmony_ci } \ 421c1b0f19Sopenharmony_ci } while (0) 431c1b0f19Sopenharmony_ci 441c1b0f19Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 451c1b0f19Sopenharmony_ci do { \ 461c1b0f19Sopenharmony_ci if ((cond)) { \ 471c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 481c1b0f19Sopenharmony_ci return; \ 491c1b0f19Sopenharmony_ci } \ 501c1b0f19Sopenharmony_ci } while (0) 511c1b0f19Sopenharmony_ci 521c1b0f19Sopenharmony_ci#define CHECK_AND_LOG(cond, fmt, ...) \ 531c1b0f19Sopenharmony_ci do { \ 541c1b0f19Sopenharmony_ci if ((cond)) { \ 551c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 561c1b0f19Sopenharmony_ci } \ 571c1b0f19Sopenharmony_ci } while (0) 581c1b0f19Sopenharmony_ci 591c1b0f19Sopenharmony_ci#define CHECK_NULL_FREE_RETURN(ptr, ret, root, ...) \ 601c1b0f19Sopenharmony_ci do { \ 611c1b0f19Sopenharmony_ci if ((ptr) == nullptr) { \ 621c1b0f19Sopenharmony_ci DHLOGE("Address pointer is null"); \ 631c1b0f19Sopenharmony_ci cJSON_Delete((root)); \ 641c1b0f19Sopenharmony_ci return (ret); \ 651c1b0f19Sopenharmony_ci } \ 661c1b0f19Sopenharmony_ci } while (0) 671c1b0f19Sopenharmony_ci 681c1b0f19Sopenharmony_ci#define CHECK_AND_FREE_RETURN_RET_LOG(cond, ret, root, fmt, ...) \ 691c1b0f19Sopenharmony_ci do { \ 701c1b0f19Sopenharmony_ci if ((cond)) { \ 711c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 721c1b0f19Sopenharmony_ci cJSON_Delete((root)); \ 731c1b0f19Sopenharmony_ci return (ret); \ 741c1b0f19Sopenharmony_ci } \ 751c1b0f19Sopenharmony_ci } while (0) 761c1b0f19Sopenharmony_ci 771c1b0f19Sopenharmony_ci#define ULOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ 781c1b0f19Sopenharmony_ci (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 791c1b0f19Sopenharmony_ci 801c1b0f19Sopenharmony_ci#define ULOGI(fmt, ...) DHLog(DH_LOG_INFO, \ 811c1b0f19Sopenharmony_ci (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 821c1b0f19Sopenharmony_ci 831c1b0f19Sopenharmony_ci#define ULOGW(fmt, ...) DHLog(DH_LOG_WARN, \ 841c1b0f19Sopenharmony_ci (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 851c1b0f19Sopenharmony_ci 861c1b0f19Sopenharmony_ci#define ULOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ 871c1b0f19Sopenharmony_ci (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) 881c1b0f19Sopenharmony_ci} // namespace DistributedHardware 891c1b0f19Sopenharmony_ci} // namespace OHOS 901c1b0f19Sopenharmony_ci#endif // OHOS_DCAMERA_LOG_H 91