1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2021 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 THERMAL_LOG_H
17094332d3Sopenharmony_ci#define THERMAL_LOG_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#define CONFIG_HILOG
20094332d3Sopenharmony_ci#ifdef CONFIG_HILOG
21094332d3Sopenharmony_ci#include "hilog/log.h"
22094332d3Sopenharmony_cinamespace OHOS {
23094332d3Sopenharmony_cinamespace HDI {
24094332d3Sopenharmony_ci
25094332d3Sopenharmony_ci#ifdef THERMAL_HILOGF
26094332d3Sopenharmony_ci#undef THERMAL_HILOGF
27094332d3Sopenharmony_ci#endif
28094332d3Sopenharmony_ci
29094332d3Sopenharmony_ci#ifdef THERMAL_HILOGE
30094332d3Sopenharmony_ci#undef THERMAL_HILOGE
31094332d3Sopenharmony_ci#endif
32094332d3Sopenharmony_ci
33094332d3Sopenharmony_ci#ifdef THERMAL_HILOGW
34094332d3Sopenharmony_ci#undef THERMAL_HILOGW
35094332d3Sopenharmony_ci#endif
36094332d3Sopenharmony_ci
37094332d3Sopenharmony_ci#ifdef THERMAL_HILOGI
38094332d3Sopenharmony_ci#undef THERMAL_HILOGI
39094332d3Sopenharmony_ci#endif
40094332d3Sopenharmony_ci
41094332d3Sopenharmony_ci#ifdef THERMAL_HILOGD
42094332d3Sopenharmony_ci#undef THERMAL_HILOGD
43094332d3Sopenharmony_ci#endif
44094332d3Sopenharmony_ci
45094332d3Sopenharmony_cinamespace {
46094332d3Sopenharmony_ci// Thermal manager reserved domain id range
47094332d3Sopenharmony_ciconstexpr unsigned int THERMAL_DOMAIN_ID_START = 0xD002940;
48094332d3Sopenharmony_ciconstexpr unsigned int THERMAL_DOMAIN_ID_END = THERMAL_DOMAIN_ID_START + 32;
49094332d3Sopenharmony_ciconstexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
50094332d3Sopenharmony_ci}
51094332d3Sopenharmony_ci
52094332d3Sopenharmony_cienum ThermalManagerLogLabel {
53094332d3Sopenharmony_ci    // Component labels, you can add if needed
54094332d3Sopenharmony_ci    COMP_APP = 0,
55094332d3Sopenharmony_ci    COMP_FWK = 1,
56094332d3Sopenharmony_ci    COMP_SVC = 2,
57094332d3Sopenharmony_ci    COMP_HDI = 3,
58094332d3Sopenharmony_ci    COMP_DRV = 4,
59094332d3Sopenharmony_ci    // Feature labels, use to mark major features
60094332d3Sopenharmony_ci    FEATURE_PROTECTOR,
61094332d3Sopenharmony_ci    // Test label
62094332d3Sopenharmony_ci    LABEL_TEST,
63094332d3Sopenharmony_ci    // The end of labels, max to the domain id range length 32
64094332d3Sopenharmony_ci    LABEL_END,
65094332d3Sopenharmony_ci};
66094332d3Sopenharmony_ci
67094332d3Sopenharmony_cienum ThermalManagerLogDomain {
68094332d3Sopenharmony_ci    DOMAIN_APP = THERMAL_DOMAIN_ID_START + COMP_APP, // 0xD002940
69094332d3Sopenharmony_ci    DOMAIN_FRAMEWORK, // 0xD002941
70094332d3Sopenharmony_ci    DOMAIN_SERVICE, // 0xD002942
71094332d3Sopenharmony_ci    DOMAIN_HDI, // 0xD002943
72094332d3Sopenharmony_ci    DOMAIN_DRIVER, // 0xD002944
73094332d3Sopenharmony_ci    DOMAIN_FEATURE_PROTECTOR,
74094332d3Sopenharmony_ci    DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
75094332d3Sopenharmony_ci    DOMAIN_END = THERMAL_DOMAIN_ID_END, // Max to 0xD002960, keep the sequence and length same as ThermalManagerLogLabel
76094332d3Sopenharmony_ci};
77094332d3Sopenharmony_ci
78094332d3Sopenharmony_cistruct ThermalManagerLogLabelDomain {
79094332d3Sopenharmony_ci    uint32_t domainId;
80094332d3Sopenharmony_ci    const char* tag;
81094332d3Sopenharmony_ci};
82094332d3Sopenharmony_ci
83094332d3Sopenharmony_ci// Keep the sequence and length same as ThermalManagerLogDomain
84094332d3Sopenharmony_cistatic const ThermalManagerLogLabelDomain THERMAL_LABEL[LABEL_END] = {
85094332d3Sopenharmony_ci    {DOMAIN_APP,               "ThermalApp"},
86094332d3Sopenharmony_ci    {DOMAIN_FRAMEWORK,         "ThermalFwk"},
87094332d3Sopenharmony_ci    {DOMAIN_SERVICE,           "ThermalSvc"},
88094332d3Sopenharmony_ci    {DOMAIN_HDI,               "ThermalHdi"},
89094332d3Sopenharmony_ci    {DOMAIN_DRIVER,            "ThermalDrv"},
90094332d3Sopenharmony_ci    {DOMAIN_FEATURE_PROTECTOR, "ThermalProtector"},
91094332d3Sopenharmony_ci    {DOMAIN_TEST,              "ThermalTest"},
92094332d3Sopenharmony_ci};
93094332d3Sopenharmony_ci
94094332d3Sopenharmony_ci// In order to improve performance, do not check the module range, module should less than THERMALMGR_MODULE_BUTT.
95094332d3Sopenharmony_ci#define THERMAL_HILOGF(module, ...) \
96094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
97094332d3Sopenharmony_ci#define THERMAL_HILOGE(module, ...) \
98094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
99094332d3Sopenharmony_ci#define THERMAL_HILOGW(module, ...) \
100094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
101094332d3Sopenharmony_ci#define THERMAL_HILOGI(module, ...) \
102094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
103094332d3Sopenharmony_ci#define THERMAL_HILOGD(module, ...) \
104094332d3Sopenharmony_ci    ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
105094332d3Sopenharmony_ci} // namespace PowerMgr
106094332d3Sopenharmony_ci} // namespace OHOS
107094332d3Sopenharmony_ci
108094332d3Sopenharmony_ci#else
109094332d3Sopenharmony_ci
110094332d3Sopenharmony_ci#define THERMAL_HILOGF(...)
111094332d3Sopenharmony_ci#define THERMAL_HILOGE(...)
112094332d3Sopenharmony_ci#define THERMAL_HILOGW(...)
113094332d3Sopenharmony_ci#define THERMAL_HILOGI(...)
114094332d3Sopenharmony_ci#define THERMAL_HILOGD(...)
115094332d3Sopenharmony_ci
116094332d3Sopenharmony_ci#endif // CONFIG_HILOG
117094332d3Sopenharmony_ci#endif // THERMAL_LOG_H
118