1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef BATTERY_LOG_H
17094332d3Sopenharmony_ci#define BATTERY_LOG_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include "hdf_base.h"
20094332d3Sopenharmony_ci#include "hilog/log.h"
21094332d3Sopenharmony_ci
22094332d3Sopenharmony_cinamespace OHOS {
23094332d3Sopenharmony_cinamespace HDI {
24094332d3Sopenharmony_cinamespace Battery {
25094332d3Sopenharmony_ci
26094332d3Sopenharmony_ci#ifdef BATTERY_HILOGF
27094332d3Sopenharmony_ci#undef BATTERY_HILOGF
28094332d3Sopenharmony_ci#endif
29094332d3Sopenharmony_ci
30094332d3Sopenharmony_ci#ifdef BATTERY_HILOGE
31094332d3Sopenharmony_ci#undef BATTERY_HILOGE
32094332d3Sopenharmony_ci#endif
33094332d3Sopenharmony_ci
34094332d3Sopenharmony_ci#ifdef BATTERY_HILOGW
35094332d3Sopenharmony_ci#undef BATTERY_HILOGW
36094332d3Sopenharmony_ci#endif
37094332d3Sopenharmony_ci
38094332d3Sopenharmony_ci#ifdef BATTERY_HILOGI
39094332d3Sopenharmony_ci#undef BATTERY_HILOGI
40094332d3Sopenharmony_ci#endif
41094332d3Sopenharmony_ci
42094332d3Sopenharmony_ci#ifdef BATTERY_HILOGD
43094332d3Sopenharmony_ci#undef BATTERY_HILOGD
44094332d3Sopenharmony_ci#endif
45094332d3Sopenharmony_ci
46094332d3Sopenharmony_cinamespace {
47094332d3Sopenharmony_ci// Battery manager reserved domain id range
48094332d3Sopenharmony_ciconstexpr unsigned int BATTERY_DOMAIN_ID_START = 0xD002920;
49094332d3Sopenharmony_ciconstexpr unsigned int BATTERY_DOMAIN_ID_END = BATTERY_DOMAIN_ID_START + 32;
50094332d3Sopenharmony_ciconstexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
51094332d3Sopenharmony_ci} // namespace
52094332d3Sopenharmony_ci
53094332d3Sopenharmony_cienum BatteryManagerLogLabel {
54094332d3Sopenharmony_ci    // Component labels, you can add if needed
55094332d3Sopenharmony_ci    COMP_APP = 0,
56094332d3Sopenharmony_ci    COMP_FWK = 1,
57094332d3Sopenharmony_ci    COMP_SVC = 2,
58094332d3Sopenharmony_ci    COMP_HDI = 3,
59094332d3Sopenharmony_ci    // Write to kmsg log
60094332d3Sopenharmony_ci    COMP_DRV = 4,
61094332d3Sopenharmony_ci    // Feature labels, use to mark major features
62094332d3Sopenharmony_ci    FEATURE_CHARGING,
63094332d3Sopenharmony_ci    FEATURE_BATT_INFO,
64094332d3Sopenharmony_ci    // Test label
65094332d3Sopenharmony_ci    LABEL_TEST,
66094332d3Sopenharmony_ci    // The end of labels, max to the domain id range length 32
67094332d3Sopenharmony_ci    LABEL_END,
68094332d3Sopenharmony_ci};
69094332d3Sopenharmony_ci
70094332d3Sopenharmony_cienum BatteryManagerLogDomain {
71094332d3Sopenharmony_ci    DOMAIN_APP = BATTERY_DOMAIN_ID_START + COMP_APP, // 0xD002920
72094332d3Sopenharmony_ci    DOMAIN_FRAMEWORK,                                // 0xD002921
73094332d3Sopenharmony_ci    DOMAIN_SERVICE,                                  // 0xD002922
74094332d3Sopenharmony_ci    DOMAIN_HDI,                                      // 0xD002923
75094332d3Sopenharmony_ci    DOMAIN_DRIVER,                                   // 0xD002924
76094332d3Sopenharmony_ci    DOMAIN_FEATURE_CHARGING,
77094332d3Sopenharmony_ci    DOMAIN_FEATURE_BATT_INFO,
78094332d3Sopenharmony_ci    DOMAIN_TEST = TEST_DOMAIN_ID,       // 0xD000F00
79094332d3Sopenharmony_ci    DOMAIN_END = BATTERY_DOMAIN_ID_END, // Max to 0xD002940, keep the sequence and length same as BatteryManagerLogLabel
80094332d3Sopenharmony_ci};
81094332d3Sopenharmony_ci
82094332d3Sopenharmony_cistruct BatteryManagerLogLabelDomain {
83094332d3Sopenharmony_ci    uint32_t domainId;
84094332d3Sopenharmony_ci    const char* tag;
85094332d3Sopenharmony_ci};
86094332d3Sopenharmony_ci
87094332d3Sopenharmony_ci// Keep the sequence and length same as BatteryManagerLogDomain
88094332d3Sopenharmony_cistatic const BatteryManagerLogLabelDomain BATTERY_LABEL[LABEL_END] = {
89094332d3Sopenharmony_ci    {DOMAIN_APP,               "BatteryApp"     },
90094332d3Sopenharmony_ci    {DOMAIN_FRAMEWORK,         "BatteryFwk"     },
91094332d3Sopenharmony_ci    {DOMAIN_SERVICE,           "BatterySvc"     },
92094332d3Sopenharmony_ci    {DOMAIN_HDI,               "BatteryHdi"     },
93094332d3Sopenharmony_ci    {DOMAIN_DRIVER,            "BatteryDrv"     },
94094332d3Sopenharmony_ci    {DOMAIN_FEATURE_CHARGING,  "BatteryCharging"},
95094332d3Sopenharmony_ci    {DOMAIN_FEATURE_BATT_INFO, "BatteryInfo"    },
96094332d3Sopenharmony_ci    {DOMAIN_TEST,              "BatteryTest"    },
97094332d3Sopenharmony_ci};
98094332d3Sopenharmony_ci
99094332d3Sopenharmony_ci#define BATTERY_HILOGF(domain, ...) \
100094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
101094332d3Sopenharmony_ci#define BATTERY_HILOGE(domain, ...) \
102094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
103094332d3Sopenharmony_ci#define BATTERY_HILOGW(domain, ...) \
104094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
105094332d3Sopenharmony_ci#define BATTERY_HILOGI(domain, ...) \
106094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
107094332d3Sopenharmony_ci#define BATTERY_HILOGD(domain, ...) \
108094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, BATTERY_LABEL[domain].domainId, BATTERY_LABEL[domain].tag, ##__VA_ARGS__))
109094332d3Sopenharmony_ci} // namespace Battery
110094332d3Sopenharmony_ci} // namespace HDI
111094332d3Sopenharmony_ci} // namespace OHOS
112094332d3Sopenharmony_ci
113094332d3Sopenharmony_ci#endif // BATTERY_LOG_H
114