11c1b0f19Sopenharmony_ci/* 21c1b0f19Sopenharmony_ci * Copyright (c) 2022-2023 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_SA_LOG_H 171c1b0f19Sopenharmony_ci#define OHOS_DCAMERA_SA_LOG_H 181c1b0f19Sopenharmony_ci 191c1b0f19Sopenharmony_ci#include "hilog/log.h" 201c1b0f19Sopenharmony_ci#include <inttypes.h> 211c1b0f19Sopenharmony_ci 221c1b0f19Sopenharmony_cinamespace OHOS { 231c1b0f19Sopenharmony_cinamespace DistributedHardware { 241c1b0f19Sopenharmony_ci#undef LOG_TAG 251c1b0f19Sopenharmony_ci#define LOG_TAG "DCAMERA" 261c1b0f19Sopenharmony_ci 271c1b0f19Sopenharmony_ci#define DCAMERA_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 281c1b0f19Sopenharmony_ci#define _sl_(x) #x 291c1b0f19Sopenharmony_ci#define _strline_(x) _sl_(x) 301c1b0f19Sopenharmony_ci#define DCAMERA_STR_LINE _strline_(__LINE__) 311c1b0f19Sopenharmony_ci 321c1b0f19Sopenharmony_ci#define DHLOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "[%{public}s][%{public}s][%{public}s:%{public}s]:" fmt, \ 331c1b0f19Sopenharmony_ci DH_LOG_TAG, __FUNCTION__, DCAMERA_FILENAME, DCAMERA_STR_LINE, ##__VA_ARGS__) 341c1b0f19Sopenharmony_ci 351c1b0f19Sopenharmony_ci#define DHLOGI(fmt, ...) HILOG_INFO(LOG_CORE, "[%{public}s][%{public}s][%{public}s:%{public}s]:" fmt, \ 361c1b0f19Sopenharmony_ci DH_LOG_TAG, __FUNCTION__, DCAMERA_FILENAME, DCAMERA_STR_LINE, ##__VA_ARGS__) 371c1b0f19Sopenharmony_ci 381c1b0f19Sopenharmony_ci#define DHLOGW(fmt, ...) HILOG_WARN(LOG_CORE, "[%{public}s][%{public}s][%{public}s:%{public}s]:" fmt, \ 391c1b0f19Sopenharmony_ci DH_LOG_TAG, __FUNCTION__, DCAMERA_FILENAME, DCAMERA_STR_LINE, ##__VA_ARGS__) 401c1b0f19Sopenharmony_ci 411c1b0f19Sopenharmony_ci#define DHLOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "[%{public}s][%{public}s][%{public}s:%{public}s]:" fmt, \ 421c1b0f19Sopenharmony_ci DH_LOG_TAG, __FUNCTION__, DCAMERA_FILENAME, DCAMERA_STR_LINE, ##__VA_ARGS__) 431c1b0f19Sopenharmony_ci 441c1b0f19Sopenharmony_ci#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ 451c1b0f19Sopenharmony_ci do { \ 461c1b0f19Sopenharmony_ci if ((cond)) { \ 471c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 481c1b0f19Sopenharmony_ci return (ret); \ 491c1b0f19Sopenharmony_ci } \ 501c1b0f19Sopenharmony_ci } while (0) 511c1b0f19Sopenharmony_ci 521c1b0f19Sopenharmony_ci#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ 531c1b0f19Sopenharmony_ci do { \ 541c1b0f19Sopenharmony_ci if ((cond)) { \ 551c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 561c1b0f19Sopenharmony_ci return; \ 571c1b0f19Sopenharmony_ci } \ 581c1b0f19Sopenharmony_ci } while (0) 591c1b0f19Sopenharmony_ci 601c1b0f19Sopenharmony_ci#define CHECK_AND_LOG(cond, fmt, ...) \ 611c1b0f19Sopenharmony_ci do { \ 621c1b0f19Sopenharmony_ci if ((cond)) { \ 631c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 641c1b0f19Sopenharmony_ci } \ 651c1b0f19Sopenharmony_ci } while (0) 661c1b0f19Sopenharmony_ci 671c1b0f19Sopenharmony_ci#define CHECK_NULL_RETURN(cond, ret, ...) \ 681c1b0f19Sopenharmony_ci do { \ 691c1b0f19Sopenharmony_ci if ((cond)) { \ 701c1b0f19Sopenharmony_ci return (ret); \ 711c1b0f19Sopenharmony_ci } \ 721c1b0f19Sopenharmony_ci } while (0) 731c1b0f19Sopenharmony_ci 741c1b0f19Sopenharmony_ci#define CHECK_NULL_FREE_RETURN(ptr, ret, root, ...) \ 751c1b0f19Sopenharmony_ci do { \ 761c1b0f19Sopenharmony_ci if ((ptr) == nullptr) { \ 771c1b0f19Sopenharmony_ci DHLOGE("Address pointer is null"); \ 781c1b0f19Sopenharmony_ci cJSON_Delete((root)); \ 791c1b0f19Sopenharmony_ci return (ret); \ 801c1b0f19Sopenharmony_ci } \ 811c1b0f19Sopenharmony_ci } while (0) 821c1b0f19Sopenharmony_ci 831c1b0f19Sopenharmony_ci#define CHECK_AND_FREE_RETURN_RET_LOG(cond, ret, root, fmt, ...) \ 841c1b0f19Sopenharmony_ci do { \ 851c1b0f19Sopenharmony_ci if ((cond)) { \ 861c1b0f19Sopenharmony_ci DHLOGE(fmt, ##__VA_ARGS__); \ 871c1b0f19Sopenharmony_ci cJSON_Delete((root)); \ 881c1b0f19Sopenharmony_ci return (ret); \ 891c1b0f19Sopenharmony_ci } \ 901c1b0f19Sopenharmony_ci } while (0) 911c1b0f19Sopenharmony_ci} // namespace DistributedHardware 921c1b0f19Sopenharmony_ci} // namespace OHOS 931c1b0f19Sopenharmony_ci#endif // OHOS_DCAMERA_SA_LOG_H 94