1 /* 2 * Copyright (c) 2022-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 POWERMGR_BATTERY_MANAGER_BATTERY_CONFIG_H 17 #define POWERMGR_BATTERY_MANAGER_BATTERY_CONFIG_H 18 19 #include <fstream> 20 #include <memory> 21 #include <mutex> 22 #include <vector> 23 #include <string> 24 25 #include <json/json.h> 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace PowerMgr { 30 class BatteryConfig : public NoCopyable { 31 public: 32 struct LightConf { 33 int32_t beginSoc; 34 int32_t endSoc; 35 uint32_t rgb; 36 }; 37 struct CommonEventConf { 38 std::string eventName; 39 std::string uevent; 40 std::string sceneConfigName; 41 bool sceneConfigEqual; 42 std::string sceneConfigValue; 43 }; 44 static BatteryConfig& GetInstance(); 45 bool ParseConfig(); 46 bool IsExist(std::string key) const; 47 int32_t GetInt(std::string key, int32_t defVal = 0) const; 48 const std::vector<LightConf>& GetLightConf() const; 49 const std::vector<BatteryConfig::CommonEventConf>& GetCommonEventConf() const; 50 51 private: 52 bool OpenFile(std::ifstream& ifsConf, const std::string& configPath); 53 void ParseConfInner(); 54 void ParseLightConf(std::string level); 55 void ParseBootActionsConf(); 56 void ParseCommonEventConf(const Json::Value &bootActionsConfig); 57 Json::Value FindConf(const std::string& key) const; 58 bool SplitKey(const std::string& key, std::vector<std::string>& keys) const; 59 Json::Value GetValue(std::string key) const; 60 Json::Value config_; 61 std::vector<BatteryConfig::LightConf> lightConf_; 62 std::vector<BatteryConfig::CommonEventConf> commonEventConf_; 63 static std::mutex mutex_; 64 static std::shared_ptr<BatteryConfig> instance_; 65 }; 66 } // namespace PowerMgr 67 } // namespace OHOS 68 #endif // POWERMGR_BATTERY_MANAGER_BATTERY_CONFIG_H 69