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_H
17 #define CONFIG_PARSER_H
18 
19 #include <mutex>
20 
21 #include "calculation_config_parser.h"
22 #include "lux_filter_config_parser.h"
23 #include "lux_threshold_config_parser.h"
24 #include "brightness_config_parser.h"
25 
26 namespace OHOS {
27 namespace DisplayPowerMgr {
28 struct Config {
29     CalculationConfig::Data calculationConfig{};
30     std::unordered_map<std::string, LuxFilterConfig::Data> luxFilterConfig{};
31     LuxThresholdConfig::Data luxThresholdConfig{};
32 };
33 struct ScreenConfig {
34     BrightnessConfig::Data brightnessConfig{};
35 };
36 class ConfigParse {
37 public:
38     ConfigParse(const ConfigParse&) = delete;
39     ConfigParse& operator=(const ConfigParse&) = delete;
40     ConfigParse(ConfigParse&&) = delete;
41     ConfigParse& operator=(ConfigParse&&) = delete;
42 
43     static ConfigParse& Get();
44 
45     void Initialize();
46     const std::unordered_map<int, Config>& GetBrightnessConfig() const;
47     const ScreenConfig& GetScreenConfig() const;
48 
49 private:
50     ConfigParse() = default;
51     virtual ~ConfigParse() = default;
52 
53     bool ParseConfig(int displayId, Config& data) const;
54     void PrintConfig(int displayId, const Config& data) const;
55 
56     mutable std::mutex mLock{};
57     // Guarded by mLock begin
58     std::atomic<bool> mIsInitialized{false};
59     std::unordered_map<int, Config> mConfig{};
60     ScreenConfig mScreenConfig{};
61 };
62 } // namespace DisplayPowerMgr
63 } // namespace OHOS
64 #endif // CONFIG_PARSER_H
65