1 /* 2 * Copyright (c) 2021 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 HILOG_WRAPPER_H 17 #define HILOG_WRAPPER_H 18 19 #define CONFIG_HILOG 20 #ifdef CONFIG_HILOG 21 #include "hilog/log.h" 22 namespace OHOS { 23 namespace USB { 24 #define USBFILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) 25 #define FORMATED_USB(fmt, ...) "[%{public}s] %{public}s# " fmt, USBFILENAME, __FUNCTION__, ##__VA_ARGS__ 26 27 #ifdef USB_HILOGF 28 #undef USB_HILOGF 29 #endif 30 31 #ifdef USB_HILOGE 32 #undef USB_HILOGE 33 #endif 34 35 #ifdef USB_HILOGW 36 #undef USB_HILOGW 37 #endif 38 39 #ifdef USB_HILOGI 40 #undef USB_HILOGI 41 #endif 42 43 #ifdef USB_HILOGD 44 #undef USB_HILOGD 45 #endif 46 47 // param of log interface, such as USB_HILOGF. 48 enum UsbMgrSubModule { 49 MODULE_INNERKIT = 0, 50 MODULE_SERVICE, 51 MODULE_JAVAKIT, // java kit used, define to avoid repeat used domain 52 MODULE_JNI, 53 MODULE_USB_INNERKIT, // below used by usb service 54 MODULE_USB_SERVICE, 55 MODULE_USBD, 56 MODULE_COMMON, 57 MODULE_JS_NAPI, 58 USBMGR_MODULE_BUTT, 59 }; 60 61 // 0xD002900: subsystem:Usb module:Usb, reserved 8 bit. 62 constexpr unsigned int BASE_USB_DOMAIN_ID = 0xD002900; 63 64 enum UsbMgrDomainId { 65 USBMGR_INNERKIT_DOMAIN = BASE_USB_DOMAIN_ID + MODULE_INNERKIT, 66 USBMGR_SERVICE_DOMAIN, 67 USBMGR_JAVAKIT_DOMAIN, // 0xD002902 68 USB_INNERKIT_DOMAIN, 69 USB_SERVICE_DOMAIN, 70 USBD_DOMAIN, 71 COMMON_DOMAIN, 72 USB_JS_NAPI, 73 USB_BUTT, 74 }; 75 76 constexpr OHOS::HiviewDFX::HiLogLabel USB_MGR_LABEL[USBMGR_MODULE_BUTT] = { 77 {LOG_CORE, USBMGR_INNERKIT_DOMAIN, "UsbMgrClient"}, 78 {LOG_CORE, USBMGR_SERVICE_DOMAIN, "UsbMgrService"}, 79 {LOG_CORE, USBMGR_JAVAKIT_DOMAIN, "UsbMgrJavaService"}, 80 {LOG_CORE, USBMGR_INNERKIT_DOMAIN, "UsbMgrJni"}, 81 {LOG_CORE, USB_INNERKIT_DOMAIN, "UsbSrvClient"}, 82 {LOG_CORE, USB_SERVICE_DOMAIN, "UsbService"}, 83 {LOG_CORE, USBD_DOMAIN, "Usbd"}, 84 {LOG_CORE, COMMON_DOMAIN, "UsbMgrCommon"}, 85 {LOG_CORE, USB_JS_NAPI, "UsbMgrJSNAPI"}, 86 }; 87 88 // In order to improve performance, do not check the module range, module should less than USBMGR_MODULE_BUTT. 89 #define USB_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(USB_MGR_LABEL[module], FORMATED_USB(__VA_ARGS__)) 90 #define USB_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(USB_MGR_LABEL[module], FORMATED_USB(__VA_ARGS__)) 91 #define USB_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(USB_MGR_LABEL[module], FORMATED_USB(__VA_ARGS__)) 92 #define USB_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(USB_MGR_LABEL[module], FORMATED_USB(__VA_ARGS__)) 93 #define USB_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(USB_MGR_LABEL[module], FORMATED_USB(__VA_ARGS__)) 94 } // namespace USB 95 } // namespace OHOS 96 97 #else 98 99 #define USB_HILOGF(...) 100 #define USB_HILOGE(...) 101 #define USB_HILOGW(...) 102 #define USB_HILOGI(...) 103 #define USB_HILOGD(...) 104 105 #endif // CONFIG_HILOG 106 107 #endif // HILOG_WRAPPER_H 108