• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static BatteryConfig& GetInstance();
38     bool ParseConfig();
39     bool IsExist(std::string key) const;
40     int32_t GetInt(std::string key, int32_t defVal = 0) const;
41     const std::vector<LightConf>& GetLightConf() const;
42     bool GetWirelessChargerConf() const;
43 
44 private:
45     bool OpenFile(std::ifstream& ifsConf, const std::string& configPath);
46     void ParseConfInner();
47     void ParseLightConf(std::string level);
48     void ParseWirelessChargerConf();
49     Json::Value FindConf(const std::string& key) const;
50     bool SplitKey(const std::string& key, std::vector<std::string>& keys) const;
51     Json::Value GetValue(std::string key) const;
52     Json::Value config_;
53     std::vector<BatteryConfig::LightConf> lightConf_;
54     bool wirelessChargerEnable_ { false };
55     static std::mutex mutex_;
56     static std::shared_ptr<BatteryConfig> instance_;
57 };
58 } // namespace PowerMgr
59 } // namespace OHOS
60 #endif // POWERMGR_BATTERY_MANAGER_BATTERY_CONFIG_H
61