| // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef THERMALD_CONFIG_PARSER_H_ |
| #define THERMALD_CONFIG_PARSER_H_ |
| |
| #include <string> |
| #include <vector> |
| |
| #include "base/files/file_path.h" |
| #include "base/macros.h" |
| #include "base/values.h" |
| |
| #include "thermald/configuration.h" |
| #include "thermald/thermal_zone.h" |
| |
| namespace thermald { |
| |
| // Parser for the thermal daemon configuration file. |
| // |
| // Parses a configuration file in JSON format and returns a data structure with |
| // the configuration. |
| // |
| // Below an example of a thermald configuration: |
| // |
| // { |
| // // Sensor configuration |
| // "sensors": [ |
| // // [sensor name, sensor type, [type specific parameters], sampling period] |
| // ["Wifi0", "ath10k", ["wifi0"], 500], |
| // ["Wifi1", "ath10k", ["wifi1"], 800], |
| // ["Cpu.0", "thermal_zone", [7], 1200] |
| // ], |
| // |
| // // Thermal zone configuration |
| // "thermal_zones": [ |
| // // Name of the zone |
| // ["Wifi0", |
| // // Temperatures monitored by the zone |
| // ["Wifi0", "Cpu.0"], |
| // // Thermal states |
| // [[1, [], |
| // {"ath10k.wifi0.max_tx_duty_cycle": 100, |
| // "wlan.wifi0.num_tx_chains": 3}], |
| // |
| // // [state id, [[Wifi0.activ, Wifi0.bottom], [Cpu.0.activ, Cpu.0.bottom]], |
| // // [outputs]] |
| // [2, [[60, 55], [70, 65]], |
| // {"ath10k.wifi0.max_tx_duty_cycle": 70, |
| // "wlan.wifi0.num_tx_chains": 2}], |
| // |
| // [3, [[80, 75], [80, 75]], |
| // {"ath10k.wifi0.max_tx_duty_cycle": 30}] |
| // ]], |
| // |
| // ["Cpu", |
| // ["Cpu.0"], |
| // [ |
| // [1, [], |
| // {"cpu.max_freq": 1400000}], |
| // |
| // [2, [[70, 65]], |
| // {"cpu.max_freq": 100000q0}], |
| // |
| // [3, [[90, 85]], |
| // {"cpu.max_freq": 800000}] |
| // ] |
| // ]] |
| // } |
| // |
| class ConfigParser { |
| public: |
| // Parses a thermald configuration file. |
| // |
| // The ownership of the returned data structure is passed to the caller. |
| static Configuration *ParseFile(const base::FilePath &config_file); |
| |
| private: |
| ConfigParser() {} |
| Configuration *ParseConfiguration(const base::Value &root_node_value); |
| bool ProcessSensorConfig(const base::Value &sensors); |
| bool ProcessOneSensor(const base::Value &sensor_node, int index_sensor); |
| bool ProcessThermalZoneConfig(const base::Value &thermal_zones); |
| bool ProcessOneThermalZone(const base::Value &thermal_zone, int index_zone); |
| bool ProcessOneThermalState(ThermalZoneCfg *zone_cfg, |
| const base::Value &state_node, int index_state); |
| bool ProcessUmaMetricPrefixConfig(const base::Value &uma_metric_prefix); |
| |
| struct Configuration *cfg_; |
| std::vector<ThermalPointThresholds> thresholds_prev_state_; |
| |
| DISALLOW_COPY_AND_ASSIGN(ConfigParser); |
| }; |
| |
| } // namespace thermald |
| |
| #endif // THERMALD_CONFIG_PARSER_H_ |