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 BATTERY_LOG_H
17 #define BATTERY_LOG_H
18 
19 #include "hilog/log.h"
20 
21 namespace OHOS {
22 namespace HDI {
23 namespace Battery {
24 
25 #ifdef BATTERY_HILOGF
26 #undef BATTERY_HILOGF
27 #endif
28 
29 #ifdef BATTERY_HILOGE
30 #undef BATTERY_HILOGE
31 #endif
32 
33 #ifdef BATTERY_HILOGW
34 #undef BATTERY_HILOGW
35 #endif
36 
37 #ifdef BATTERY_HILOGI
38 #undef BATTERY_HILOGI
39 #endif
40 
41 #ifdef BATTERY_HILOGD
42 #undef BATTERY_HILOGD
43 #endif
44 
45 namespace {
46 // Battery manager reserved domain id range
47 constexpr unsigned int BATTERY_DOMAIN_ID_START = 0xD002920;
48 constexpr unsigned int BATTERY_DOMAIN_ID_END = BATTERY_DOMAIN_ID_START + 32;
49 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
50 } // namespace
51 
52 enum BatteryManagerLogLabel {
53     // Component labels, you can add if needed
54     COMP_APP = 0,
55     COMP_FWK = 1,
56     COMP_SVC = 2,
57     COMP_HDI = 3,
58     // Write to kmsg log
59     COMP_DRV = 4,
60     // Feature labels, use to mark major features
61     FEATURE_CHARGING,
62     FEATURE_BATT_INFO,
63     // Test label
64     LABEL_TEST,
65     // The end of labels, max to the domain id range length 32
66     LABEL_END,
67 };
68 
69 enum BatteryManagerLogDomain {
70     DOMAIN_APP = BATTERY_DOMAIN_ID_START + COMP_APP, // 0xD002920
71     DOMAIN_FRAMEWORK,                                // 0xD002921
72     DOMAIN_SERVICE,                                  // 0xD002922
73     DOMAIN_HDI,                                      // 0xD002923
74     DOMAIN_DRIVER,                                   // 0xD002924
75     DOMAIN_FEATURE_CHARGING,
76     DOMAIN_FEATURE_BATT_INFO,
77     DOMAIN_TEST = TEST_DOMAIN_ID,       // 0xD000F00
78     DOMAIN_END = BATTERY_DOMAIN_ID_END, // Max to 0xD002940, keep the sequence and length same as BatteryManagerLogLabel
79 };
80 
81 struct BatteryManagerLogLabelDomain {
82     uint32_t domainId;
83     const char* tag;
84 };
85 
86 // Keep the sequence and length same as BatteryManagerLogDomain
87 static const BatteryManagerLogLabelDomain BATTERY_LABEL[LABEL_END] = {
88     {DOMAIN_APP,               "BatteryApp"     },
89     {DOMAIN_FRAMEWORK,         "BatteryFwk"     },
90     {DOMAIN_SERVICE,           "BatterySvc"     },
91     {DOMAIN_HDI,               "BatteryHdi"     },
92     {DOMAIN_DRIVER,            "BatteryDrv"     },
93     {DOMAIN_FEATURE_CHARGING,  "BatteryCharging"},
94     {DOMAIN_FEATURE_BATT_INFO, "BatteryInfo"    },
95     {DOMAIN_TEST,              "BatteryTest"    },
96 };
97 
98 #define BATTERY_HILOGF(domain, ...) \
99     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
100 #define BATTERY_HILOGE(domain, ...) \
101     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
102 #define BATTERY_HILOGW(domain, ...) \
103     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
104 #define BATTERY_HILOGI(domain, ...) \
105     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
106 #define BATTERY_HILOGD(domain, ...) \
107     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
108 } // namespace Battery
109 } // namespace HDI
110 } // namespace OHOS
111 
112 #endif // BATTERY_LOG_H
113