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