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