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_WIFI_LOGGER_H 17 #define OHOS_WIFI_LOGGER_H 18 19 #include <stdint.h> 20 #ifdef OHOS_ARCH_LITE 21 #include "hilog/log.h" 22 #else 23 #include "hilog/log_c.h" 24 #include "hilog/log_cpp.h" 25 #endif 26 27 namespace OHOS { 28 namespace Wifi { 29 30 const unsigned int LOG_ID_WIFI = 0xD001560; 31 const unsigned int LOG_ID_WIFI_HOTSPOT = LOG_ID_WIFI | 0x01; 32 const unsigned int LOG_ID_WIFI_SCAN = LOG_ID_WIFI | 0x02; 33 const unsigned int LOG_ID_WIFI_P2P = LOG_ID_WIFI | 0x03; 34 const unsigned int LOG_ID_WIFI_AWARE = LOG_ID_WIFI | 0x04; 35 const unsigned int LOG_ID_WIFI_DHCP = LOG_ID_WIFI | 0x05; 36 37 #ifdef OHOS_ARCH_LITE 38 39 #define DEFINE_WIFILOG_LABEL(name) \ 40 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI, name}; 41 #define DEFINE_WIFILOG_HOTSPOT_LABEL(name) \ 42 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI_HOTSPOT, name}; 43 #define DEFINE_WIFILOG_SCAN_LABEL(name) \ 44 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI_SCAN, name}; 45 #define DEFINE_WIFILOG_P2P_LABEL(name) \ 46 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI_P2P, name}; 47 #define DEFINE_WIFILOG_AWARE_LABEL(name) \ 48 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI_AWARE, name}; 49 #define DEFINE_WIFILOG_DHCP_LABEL(name) \ 50 static constexpr OHOS::HiviewDFX::HiLogLabel WIFI_LOG_LABEL = {LOG_CORE, OHOS::Wifi::LOG_ID_WIFI_DHCP, name}; 51 52 #define WIFI_LOGF(...) (void)OHOS::HiviewDFX::HiLog::Fatal(WIFI_LOG_LABEL, ##__VA_ARGS__) 53 #define WIFI_LOGE(...) (void)OHOS::HiviewDFX::HiLog::Error(WIFI_LOG_LABEL, ##__VA_ARGS__) 54 #define WIFI_LOGW(...) (void)OHOS::HiviewDFX::HiLog::Warn(WIFI_LOG_LABEL, ##__VA_ARGS__) 55 #define WIFI_LOGI(...) (void)OHOS::HiviewDFX::HiLog::Info(WIFI_LOG_LABEL, ##__VA_ARGS__) 56 #define WIFI_LOGD(...) (void)OHOS::HiviewDFX::HiLog::Debug(WIFI_LOG_LABEL, ##__VA_ARGS__) 57 58 #else 59 60 struct LogLable { 61 uint32_t dominId; 62 const char* tag; 63 }; 64 65 #define DEFINE_WIFILOG_LABEL(name) \ 66 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI, name}; 67 #define DEFINE_WIFILOG_HOTSPOT_LABEL(name) \ 68 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI_HOTSPOT, name}; 69 #define DEFINE_WIFILOG_SCAN_LABEL(name) \ 70 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI_SCAN, name}; 71 #define DEFINE_WIFILOG_P2P_LABEL(name) \ 72 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI_P2P, name}; 73 #define DEFINE_WIFILOG_AWARE_LABEL(name) \ 74 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI_AWARE, name}; 75 #define DEFINE_WIFILOG_DHCP_LABEL(name) \ 76 static constexpr OHOS::Wifi::LogLable WIFI_LOG_LABEL = {OHOS::Wifi::LOG_ID_WIFI_DHCP, name}; 77 78 #define WIFI_LOGF(...) HILOG_IMPL(LOG_CORE, LOG_FATAL, WIFI_LOG_LABEL.dominId, WIFI_LOG_LABEL.tag, __VA_ARGS__) 79 #define WIFI_LOGE(...) HILOG_IMPL(LOG_CORE, LOG_ERROR, WIFI_LOG_LABEL.dominId, WIFI_LOG_LABEL.tag, __VA_ARGS__) 80 #define WIFI_LOGW(...) HILOG_IMPL(LOG_CORE, LOG_WARN, WIFI_LOG_LABEL.dominId, WIFI_LOG_LABEL.tag, __VA_ARGS__) 81 #define WIFI_LOGI(...) HILOG_IMPL(LOG_CORE, LOG_INFO, WIFI_LOG_LABEL.dominId, WIFI_LOG_LABEL.tag, __VA_ARGS__) 82 #define WIFI_LOGD(...) HILOG_IMPL(LOG_CORE, LOG_DEBUG, WIFI_LOG_LABEL.dominId, WIFI_LOG_LABEL.tag, __VA_ARGS__) 83 84 #endif 85 86 #ifndef CHECK_NULL_AND_RETURN 87 #define CHECK_NULL_AND_RETURN(ptr, retValue) \ 88 if (!(ptr)) { \ 89 WIFI_LOGI("Pointer %{public}s in %{public}s is NULL!", #ptr, __func__); \ 90 return retValue; \ 91 } 92 #endif 93 } // namespace Wifi 94 } // namespace OHOS 95 #endif