• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 DEVICESTATUS_HILOG_WRAPPER_H
17 #define DEVICESTATUS_HILOG_WRAPPER_H
18 
19 #define CONFIG_HILOG
20 #ifdef CONFIG_HILOG
21 
22 #include "hilog/log.h"
23 
24 namespace OHOS {
25 namespace Msdp {
26 #define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
27 #define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__
28 
29 #ifdef DEV_HILOGF
30 #undef DEV_HILOGF
31 #endif
32 
33 #ifdef DEV_HILOGE
34 #undef DEV_HILOGE
35 #endif
36 
37 #ifdef DEV_HILOGW
38 #undef DEV_HILOGW
39 #endif
40 
41 #ifdef DEV_HILOGI
42 #undef DEV_HILOGI
43 #endif
44 
45 #ifdef DEV_HILOGD
46 #undef DEV_HILOGD
47 #endif
48 
49 // param of log interface, such as DEV_HILOGF.
50 enum DevicestatusSubModule {
51     INNERKIT = 0,
52     SERVICE,
53     JS_NAPI,
54     COMMON,
55     BUTT,
56 };
57 
58 // 0xD002220: subsystem:Msdp module:Devicestatus, 8 bits reserved.
59 static constexpr unsigned int BASE_MSDP_DOMAIN_ID = 0xD002220;
60 
61 enum DevicestatusDomainId {
62     DEVICESTATUS_INNERKIT_DOMAIN = BASE_MSDP_DOMAIN_ID + INNERKIT,
63     DEVICESTATUS_SERVICE_DOMAIN,
64     DEVICESTATUS_JS_NAPI,
65     DEVICESTATUS_COMMON,
66     DEVICESTATUS_BUTT,
67 };
68 
69 static constexpr OHOS::HiviewDFX::HiLogLabel DEVICESTATUS_LABEL[BUTT] = {
70     {LOG_CORE, DEVICESTATUS_INNERKIT_DOMAIN, "DevicestatusClient"},
71     {LOG_CORE, DEVICESTATUS_SERVICE_DOMAIN, "DevicestatusService"},
72     {LOG_CORE, DEVICESTATUS_JS_NAPI, "DevicestatusJsNapi"},
73     {LOG_CORE, DEVICESTATUS_COMMON, "DevicestatusCommon"},
74 };
75 
76 // In order to improve performance, do not check the module range.
77 // Besides, make sure module is less than BUTT.
78 #define DEV_HILOGF(module, ...) \
79     (void)OHOS::HiviewDFX::HiLog::Fatal(DEVICESTATUS_LABEL[module], __FORMATED(__VA_ARGS__))
80 #define DEV_HILOGE(module, ...) \
81     (void)OHOS::HiviewDFX::HiLog::Error(DEVICESTATUS_LABEL[module], __FORMATED(__VA_ARGS__))
82 #define DEV_HILOGW(module, ...) \
83     (void)OHOS::HiviewDFX::HiLog::Warn(DEVICESTATUS_LABEL[module], __FORMATED(__VA_ARGS__))
84 #define DEV_HILOGI(module, ...) \
85     (void)OHOS::HiviewDFX::HiLog::Info(DEVICESTATUS_LABEL[module], __FORMATED(__VA_ARGS__))
86 #define DEV_HILOGD(module, ...) \
87     (void)OHOS::HiviewDFX::HiLog::Debug(DEVICESTATUS_LABEL[module], __FORMATED(__VA_ARGS__))
88 } // namespace Msdp
89 } // namespace OHOS
90 
91 #else
92 
93 #define DEV_HILOGF(...)
94 #define DEV_HILOGE(...)
95 #define DEV_HILOGW(...)
96 #define DEV_HILOGI(...)
97 #define DEV_HILOGD(...)
98 
99 #endif // CONFIG_HILOG
100 
101 #endif // DEVICESTATUS_HILOG_WRAPPER_H
102