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