1/* 2 * Copyright (c) 2023-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#include "config_parser.h" 17 18#include "display_log.h" 19 20namespace OHOS { 21namespace DisplayPowerMgr { 22namespace { 23constexpr int DISPLAY_ID_MAX = 5; 24const std::string CONFIG_NAME = "brightness_lux_threshold_config"; 25} // namespace 26 27using namespace OHOS::DisplayPowerMgr; 28 29ConfigParse& ConfigParse::Get() 30{ 31 static ConfigParse ConfigParse; 32 return ConfigParse; 33} 34 35void ConfigParse::Initialize() 36{ 37 std::lock_guard<std::mutex> lock(mLock); 38 if (mIsInitialized.load()) [[unlikely]] { 39 DISPLAY_HILOGI(FEAT_BRIGHTNESS, "Already init!"); 40 return; 41 } 42 BrightnessConfigParser::ParseConfig(mScreenConfig.brightnessConfig); 43 BrightnessConfigParser::PrintConfig(mScreenConfig.brightnessConfig); 44 for (int displayId = 0; displayId < DISPLAY_ID_MAX; displayId++) { 45 DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[%{public}d] Already init!", displayId); 46 Config brightnessConfig{}; 47 ParseConfig(displayId, brightnessConfig); 48 PrintConfig(displayId, brightnessConfig); 49 mConfig[displayId] = brightnessConfig; 50 } 51 mIsInitialized = true; 52} 53 54const std::unordered_map<int, Config>& ConfigParse::GetBrightnessConfig() const 55{ 56 return mConfig; 57} 58 59const ScreenConfig& ConfigParse::GetScreenConfig() const 60{ 61 return mScreenConfig; 62} 63 64bool ConfigParse::ParseConfig(int displayId, Config& data) const 65{ 66 DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[%{public}d] parse Config start!", displayId); 67 CalculationConfigParser::ParseConfig(displayId, data.calculationConfig); 68 LuxFilterConfigParser::ParseConfig(displayId, data.luxFilterConfig); 69 LuxThresholdConfigParser::ParseConfig(displayId, data.luxThresholdConfig); 70 DISPLAY_HILOGI(FEAT_BRIGHTNESS, "[%{public}d] parse Config over!", displayId); 71 return true; 72} 73 74void ConfigParse::PrintConfig(int displayId, const Config& data) const 75{ 76 CalculationConfigParser::PrintConfig(displayId, data.calculationConfig); 77 LuxFilterConfigParser::PrintConfig(displayId, data.luxFilterConfig); 78 LuxThresholdConfigParser::PrintConfig(displayId, data.luxThresholdConfig); 79} 80} // namespace DisplayPowerMgr 81} // namespace OHOS 82