• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 THERMAL_LOG_H
17 #define THERMAL_LOG_H
18 
19 #define CONFIG_HILOG
20 #ifdef CONFIG_HILOG
21 
22 #include <cstdint>
23 
24 #include "hilog/log.h"
25 namespace OHOS {
26 namespace PowerMgr {
27 
28 #ifdef THERMAL_HILOGF
29 #undef THERMAL_HILOGF
30 #endif
31 
32 #ifdef THERMAL_HILOGE
33 #undef THERMAL_HILOGE
34 #endif
35 
36 #ifdef THERMAL_HILOGW
37 #undef THERMAL_HILOGW
38 #endif
39 
40 #ifdef THERMAL_HILOGI
41 #undef THERMAL_HILOGI
42 #endif
43 
44 #ifdef THERMAL_HILOGD
45 #undef THERMAL_HILOGD
46 #endif
47 
48 namespace {
49 // Thermal manager reserved domain id range
50 constexpr unsigned int THERMAL_DOMAIN_ID_START = 0xD002940;
51 constexpr unsigned int THERMAL_DOMAIN_ID_END = THERMAL_DOMAIN_ID_START + 32;
52 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
53 }
54 
55 enum ThermalManagerLogLabel {
56     // Component labels, you can add if needed
57     COMP_APP = 0,
58     COMP_FWK = 1,
59     COMP_SVC = 2,
60     COMP_HDI = 3,
61     COMP_DRV = 4,
62     // Feature labels, use to mark major features
63     FEATURE_PROTECTOR,
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 ThermalManagerLogDomain {
71     DOMAIN_APP = THERMAL_DOMAIN_ID_START + COMP_APP, // 0xD002940
72     DOMAIN_FRAMEWORK, // 0xD002941
73     DOMAIN_SERVICE, // 0xD002942
74     DOMAIN_HDI, // 0xD002943
75     DOMAIN_DRIVER, // 0xD002944
76     DOMAIN_FEATURE_PROTECTOR,
77     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
78     DOMAIN_END = THERMAL_DOMAIN_ID_END, // Max to 0xD002960, keep the sequence and length same as ThermalManagerLogLabel
79 };
80 
81 struct ThermalManagerLogLabelDomain {
82     uint32_t domainId;
83     const char* tag;
84 };
85 
86 // Keep the sequence and length same as ThermalManagerLogDomain
87 static const ThermalManagerLogLabelDomain THERMAL_LABEL[LABEL_END] = {
88     {DOMAIN_APP,                "ThermalApp"},
89     {DOMAIN_FRAMEWORK,          "ThermalFwk"},
90     {DOMAIN_SERVICE,            "ThermalSvc"},
91     {DOMAIN_HDI,                "ThermalHdi"},
92     {DOMAIN_DRIVER,             "ThermalDrv"},
93     {DOMAIN_FEATURE_PROTECTOR,  "ThermalProtector"},
94     {DOMAIN_TEST,               "ThermalTest"},
95 };
96 
97 // In order to improve performance, do not check the module range, module should less than THERMALMGR_MODULE_BUTT.
98 #define THERMAL_HILOGF(module, ...) \
99     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
100 #define THERMAL_HILOGE(module, ...) \
101     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
102 #define THERMAL_HILOGW(module, ...) \
103     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
104 #define THERMAL_HILOGI(module, ...) \
105     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
106 #define THERMAL_HILOGD(module, ...) \
107     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, THERMAL_LABEL[module].domainId, THERMAL_LABEL[module].tag, ##__VA_ARGS__))
108 } // namespace PowerMgr
109 } // namespace OHOS
110 
111 #else
112 
113 #define THERMAL_HILOGF(...)
114 #define THERMAL_HILOGE(...)
115 #define THERMAL_HILOGW(...)
116 #define THERMAL_HILOGI(...)
117 #define THERMAL_HILOGD(...)
118 
119 #endif // CONFIG_HILOG
120 #endif // THERMAL_LOG_H
121