• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ExternalDeviceManager {
24 #define FORMATED_EDM(fmt, ...) "[%{public}s]" fmt, __FUNCTION__, ##__VA_ARGS__
25 
26 #ifdef EDM_LOGF
27 #undef EDM_LOGF
28 #endif
29 
30 #ifdef EDM_LOGE
31 #undef EDM_LOGE
32 #endif
33 
34 #ifdef EDM_LOGW
35 #undef EDM_LOGW
36 #endif
37 
38 #ifdef EDM_LOGI
39 #undef EDM_LOGI
40 #endif
41 
42 #ifdef EDM_LOGD
43 #undef EDM_LOGD
44 #endif
45 
46 // param of log interface, such as EDM_LOGF.
47 enum UsbMgrSubModule {
48     MODULE_FRAMEWORK = 0,
49     MODULE_SERVICE,
50     MODULE_DEV_MGR,
51     MODULE_PKG_MGR,
52     MODULE_EA_MGR,
53     MODULE_BUS_USB,
54     MODULE_COMMON,
55     MODULE_USB_DDK,
56     EDM_MODULE_TEST,
57     EDM_MODULE_BUTT,
58 };
59 
60 // 0xD002550: part:ExternalDeviceManager module:Edm.
61 constexpr unsigned int BASE_EDM_DOMAIN_ID = 0xD002550;
62 
63 enum UsbMgrDomainId {
64     EDM_FRAMEWORK_DOMAIN = BASE_EDM_DOMAIN_ID + MODULE_FRAMEWORK,
65     EDM_SERVICE_DOMAIN,
66     EDM_DEV_MGR_DOMAIN,
67     EDM_PKG_MGR_DOMAIN,
68     EDM_EA_MGR_DOMAIN,
69     EDM_BUS_USB_DOMAIN,
70     EDM_COMMON_DOMAIN,
71     EDM_USB_DDK_DOMAIN,
72     EDM_TEST,
73     EDM_BUTT,
74 };
75 
76 constexpr OHOS::HiviewDFX::HiLogLabel EDM_MGR_LABEL[EDM_MODULE_BUTT] = {
77     {LOG_CORE, EDM_FRAMEWORK_DOMAIN, "EdmFwk"      },
78     {LOG_CORE, EDM_SERVICE_DOMAIN,   "EdmService"  },
79     {LOG_CORE, EDM_DEV_MGR_DOMAIN,   "EdmDevMgr"   },
80     {LOG_CORE, EDM_PKG_MGR_DOMAIN,   "EdmPkgMgr"   },
81     {LOG_CORE, EDM_EA_MGR_DOMAIN,    "EdmEaMgr"    },
82     {LOG_CORE, EDM_BUS_USB_DOMAIN,   "EdmBusUsbMgr"},
83     {LOG_CORE, EDM_COMMON_DOMAIN,    "EdmCommon"   },
84     {LOG_CORE, EDM_USB_DDK_DOMAIN,   "EdmUsbDdk"   },
85     {LOG_CORE, EDM_TEST,             "EdmTest"     },
86 };
87 
88 // In order to improve performance, do not check the module range, module should less than EDM_MODULE_BUTT.
89 #define EDM_LOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
90 #define EDM_LOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
91 #define EDM_LOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
92 #define EDM_LOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
93 #define EDM_LOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(EDM_MGR_LABEL[module], FORMATED_EDM(__VA_ARGS__))
94 } // namespace ExternalDeviceManager
95 } // namespace OHOS
96 
97 #else
98 
99 #define EDM_LOGF(...)
100 #define EDM_LOGE(...)
101 #define EDM_LOGW(...)
102 #define EDM_LOGI(...)
103 #define EDM_LOGD(...)
104 
105 #endif // CONFIG_HILOG
106 
107 #endif // HILOG_WRAPPER_H
108