1 /* 2 * Copyright (c) 2022-2025 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 OHOS_HDI_POWER_V1_2_POWER_CONFIG_H 17 #define OHOS_HDI_POWER_V1_2_POWER_CONFIG_H 18 19 #include <fstream> 20 #include <map> 21 #include <mutex> 22 #include <string> 23 #include <vector> 24 25 #include <cJSON.h> 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace HDI { 30 namespace Power { 31 namespace V1_2 { 32 class PowerConfig : public NoCopyable { 33 public: 34 struct PowerSceneConfig { 35 std::string getPath; 36 std::string setPath; 37 }; 38 static PowerConfig& GetInstance(); 39 static void DestroyInstance(); 40 bool ParseConfig(); 41 const std::map<std::string, PowerConfig::PowerSceneConfig>& GetPowerSceneConfigMap() const; 42 43 private: 44 bool OpenFile(std::ifstream& ifsConf, const std::string& configPath); 45 void ParseConfInner(const cJSON* config); 46 bool SplitKey(const std::string& key, std::vector<std::string>& keys) const; 47 cJSON* GetValue(const cJSON* config, std::string key) const; 48 void ParseSceneConfig(const cJSON* sceneConfig); 49 cJSON* ParseJsonStream(std::istream& ifsConf); 50 bool IsValidJsonString(const cJSON* config) const; 51 bool IsValidJsonObject(const cJSON* jsonValue) const; 52 std::map<std::string, PowerConfig::PowerSceneConfig> sceneConfigMap_; 53 static std::mutex mutex_; 54 static std::shared_ptr<PowerConfig> instance_; 55 }; 56 } // namespace V1_2 57 } // namespace Power 58 } // namespace HDI 59 } // namespace OHOS 60 #endif // OHOS_HDI_POWER_V1_2_POWER_CONFIG_H