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 #ifndef LUX_HTRESHOLD_CONFIG_PARSER_H 17 #define LUX_HTRESHOLD_CONFIG_PARSER_H 18 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #include <cJSON.h> 24 #include "calculation_config_parser.h" 25 26 namespace OHOS { 27 namespace DisplayPowerMgr { 28 namespace LuxThresholdConfig { 29 struct Mode { 30 int brightenDebounceTime{-1}; 31 int darkenDebounceTime{-1}; 32 std::vector<PointXy> brightenPoints{}; 33 std::vector<PointXy> darkenPoints{}; 34 }; 35 struct Data { 36 std::unordered_map<std::string, LuxThresholdConfig::Mode> modeArray{}; 37 bool isLevelEnable{false}; 38 std::vector<PointXy> brightenPointsForLevel{}; 39 std::vector<PointXy> darkenPointsForLevel{}; 40 }; 41 } 42 class LuxThresholdConfigParser { 43 public: 44 LuxThresholdConfigParser() = default; 45 virtual ~LuxThresholdConfigParser() = default; 46 LuxThresholdConfigParser(const LuxThresholdConfigParser&) = delete; 47 LuxThresholdConfigParser& operator=(const LuxThresholdConfigParser&) = delete; 48 LuxThresholdConfigParser(LuxThresholdConfigParser&&) = delete; 49 LuxThresholdConfigParser& operator=(LuxThresholdConfigParser&&) = delete; 50 51 static void LuxThresholdParseConfigParams(cJSON* item, LuxThresholdConfig::Data& data); 52 static bool ParseConfig(int displayId, LuxThresholdConfig::Data& data); 53 static bool ParseConfigJsonRoot(const std::string& fileContent, LuxThresholdConfig::Data& data); 54 static void PrintConfig(int displayId, const LuxThresholdConfig::Data& data); 55 }; 56 } // namespace DisplayPowerMgr 57 } // namespace OHOS 58 #endif // LUX_HTRESHOLD_CONFIG_PARSER_H 59