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 CONFIG_PARSER_BASE_H 17 #define CONFIG_PARSER_BASE_H 18 19 #include <json/json.h> 20 #include <mutex> 21 #include <optional> 22 #include <string> 23 24 #include "calculation_config_parser.h" 25 #include "brightness_config_parser.h" 26 27 namespace OHOS { 28 namespace DisplayPowerMgr { 29 class ConfigParserBase { 30 public: 31 ConfigParserBase(const ConfigParserBase&) = delete; 32 ConfigParserBase& operator=(const ConfigParserBase&) = delete; 33 ConfigParserBase(ConfigParserBase&&) = delete; 34 ConfigParserBase& operator=(ConfigParserBase&&) = delete; 35 36 static ConfigParserBase& Get(); 37 38 void Initialize(); 39 const std::string LoadConfigPath(int displayId, const std::string& configName) const; 40 const Json::Value LoadConfigRoot(int displayId, const std::string& configName) const; 41 void ParsePointXy(const Json::Value& root, const std::string& name, std::vector<PointXy>& data) const; 42 const std::string PointXyToString(const std::string& name, const std::vector<PointXy>& data) const; 43 void ParseScreenData(const Json::Value& root, const std::string& name, std::unordered_map<int, ScreenData>& data, 44 const std::string paramName) const; 45 const std::string ScreenDataToString(const std::string& name, const std::unordered_map<int, ScreenData>& data, 46 const std::string paramName) const; 47 48 private: 49 struct ConfigInfo { 50 std::string panelName{}; 51 std::string panelVersion{}; 52 }; 53 54 ConfigParserBase() = default; 55 virtual ~ConfigParserBase() = default; 56 57 std::unordered_map<int, ConfigInfo>::iterator GetDispIter(int displayId); 58 std::unordered_map<int, ConfigInfo>::const_iterator GetConstDispIter(int displayId) const; 59 60 mutable std::mutex mLock{}; 61 // Guarded by mLock begin 62 std::atomic<bool> mIsInitialized{false}; 63 std::unordered_map<int, ConfigInfo> mConfigInfo{}; 64 }; 65 } // namespace DisplayPowerMgr 66 } // namespace OHOS 67 #endif // CONFIG_PARSER_BASE_H 68