• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 DISPLAY_LOG_H
17 #define DISPLAY_LOG_H
18 
19 #define CONFIG_HILOG
20 #ifdef CONFIG_HILOG
21 
22 #include "hilog/log.h"
23 
24 namespace OHOS {
25 namespace DisplayPowerMgr  {
26 
27 #ifdef DISPLAY_HILOGF
28 #undef DISPLAY_HILOGF
29 #endif
30 
31 #ifdef DISPLAY_HILOGE
32 #undef DISPLAY_HILOGE
33 #endif
34 
35 #ifdef DISPLAY_HILOGW
36 #undef DISPLAY_HILOGW
37 #endif
38 
39 #ifdef DISPLAY_HILOGI
40 #undef DISPLAY_HILOGI
41 #endif
42 
43 #ifdef DISPLAY_HILOGD
44 #undef DISPLAY_HILOGD
45 #endif
46 
47 namespace {
48 // Display manager reserved domain id range
49 constexpr unsigned int DISPLAY_DOMAIN_ID_START = 0xD002980;
50 constexpr unsigned int DISPLAY_DOMAIN_ID_END = DISPLAY_DOMAIN_ID_START + 32;
51 constexpr unsigned int TEST_DOMAIN_ID = 0xD000F00;
52 }
53 
54 enum DisplayManagerLogLabel {
55     // Component labels, you can add if needed
56     COMP_APP = 0,
57     COMP_FWK = 1,
58     COMP_SVC = 2,
59     COMP_HDI = 3,
60     COMP_DRV = 4,
61     COMP_UTS = 5,
62     FEAT_BRIGHTNESS,
63     FEAT_STATE,
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 DisplayManagerLogDomain {
71     DOMAIN_APP = DISPLAY_DOMAIN_ID_START + COMP_APP, // 0xD002980
72     DOMAIN_FRAMEWORK, // 0xD002981
73     DOMAIN_SERVICE, // 0xD002982
74     DOMAIN_HDI, // 0xD002983
75     DOMAIN_DRIVER, // 0xD002984
76     DOMAIN_UTILS, // 0xD002985
77     DOMAIN_FEAT_BRIGHTNESS,
78     DOMAIN_FEAT_STATE,
79     DOMAIN_TEST = TEST_DOMAIN_ID, // 0xD000F00
80     DOMAIN_END = DISPLAY_DOMAIN_ID_END, // Max to 0xD00299F, keep the sequence and length same as DisplayManagerLogLabel
81 };
82 
83 struct DisplayManagerLogLabelDomain {
84     uint32_t domainId;
85     const char* tag;
86 };
87 
88 // Keep the sequence and length same as DisplayManagerLogDomain
89 static const DisplayManagerLogLabelDomain DISPLAY_LABEL[LABEL_END] = {
90     {DOMAIN_APP,               "DisplayPowerApp"},
91     {DOMAIN_FRAMEWORK,         "DisplayPowerFwk"},
92     {DOMAIN_SERVICE,           "DisplayPowerSvc"},
93     {DOMAIN_HDI,               "DisplayPowerHdi"},
94     {DOMAIN_DRIVER,            "DisplayPowerDrv"},
95     {DOMAIN_UTILS,             "DisplayPowerUts"},
96     {DOMAIN_FEAT_BRIGHTNESS,   "DisplayPowerBrightness"},
97     {DOMAIN_FEAT_STATE,        "DisplayPowerState"},
98     {DOMAIN_TEST,              "DisplayPowerTest"},
99 };
100 
101 // In order to improve performance, do not check the module range.
102 // Besides, make sure module is less than LABEL_END.
103 #define DISPLAY_HILOGF(domain, ...) \
104     ((void)HILOG_IMPL(LOG_CORE, LOG_FATAL, DISPLAY_LABEL[domain].domainId, DISPLAY_LABEL[domain].tag, ##__VA_ARGS__))
105 #define DISPLAY_HILOGE(domain, ...) \
106     ((void)HILOG_IMPL(LOG_CORE, LOG_ERROR, DISPLAY_LABEL[domain].domainId, DISPLAY_LABEL[domain].tag, ##__VA_ARGS__))
107 #define DISPLAY_HILOGW(domain, ...) \
108     ((void)HILOG_IMPL(LOG_CORE, LOG_WARN, DISPLAY_LABEL[domain].domainId, DISPLAY_LABEL[domain].tag, ##__VA_ARGS__))
109 #define DISPLAY_HILOGI(domain, ...) \
110     ((void)HILOG_IMPL(LOG_CORE, LOG_INFO, DISPLAY_LABEL[domain].domainId, DISPLAY_LABEL[domain].tag, ##__VA_ARGS__))
111 #define DISPLAY_HILOGD(domain, ...) \
112     ((void)HILOG_IMPL(LOG_CORE, LOG_DEBUG, DISPLAY_LABEL[domain].domainId, DISPLAY_LABEL[domain].tag, ##__VA_ARGS__))
113 } // namespace DisplayPowerMgr
114 } // namespace OHOS
115 
116 #else
117 
118 #define DISPLAY_HILOGF(...)
119 #define DISPLAY_HILOGE(...)
120 #define DISPLAY_HILOGW(...)
121 #define DISPLAY_HILOGI(...)
122 #define DISPLAY_HILOGD(...)
123 
124 #endif // CONFIG_HILOG
125 
126 #endif // DISPLAY_LOG_H
127