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