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