summaryrefslogtreecommitdiff
path: root/Config.h
blob: f4a2fa521a0ac4c1616916f5c079b6a56b171888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef THERMAL_CONFIG_PARSER_H__
#define THERMAL_CONFIG_PARSER_H__

#include <android/hardware/thermal/2.0/IThermal.h>

#include <map>
#include <string>

#include <json/reader.h>
#include <json/value.h>

namespace android {
namespace hardware {
namespace thermal {
namespace V2_0 {
namespace implementation {

using Temperature_1_0 = ::android::hardware::thermal::V1_0::Temperature;
using Temperature_2_0 = ::android::hardware::thermal::V2_0::Temperature;
using CoolingDevice_1_0 = ::android::hardware::thermal::V1_0::CoolingDevice;
using CoolingDevice_2_0 = ::android::hardware::thermal::V2_0::CoolingDevice;

using ::android::hardware::thermal::V2_0::TemperatureThreshold;
using ::android::hardware::thermal::V2_0::TemperatureType;

class Config {
private:
	template<class T> bool typeToEnum(std::string &type, T &t);

	std::string toUpper(const std::string &str);

	bool read(std::string file);

	void initThreshold(TemperatureThreshold &tempThreshold);

	bool readHotColdThrottling(Json::Value &throttling, float *tempThreshold);

	bool readHotThrottling(Json::Value &throttling,
			       TemperatureThreshold &tempThreshold);
	
	bool readColdThrottling(Json::Value &throttling,
				TemperatureThreshold &tempThreshold);

	bool readVrThrottling(Json::Value &throttling,
			      TemperatureThreshold &tempThreshold);

	bool readThrottling(const std::string &name,
			    Json::Value &throttling);

	bool readCoolingDevice(Json::Value &coolingDevice);
	
	bool readSensor(Json::Value &sensor);

	bool readFile(const std::string path,
		      std::stringstream &config);

	bool parseFile(std::string path, Json::Value &root);

public:
	std::vector<Temperature_1_0> m_temperature_1_0;
	std::vector<Temperature_2_0> m_temperature_2_0;

	std::vector<CoolingDevice_1_0> m_cooling_device_1_0;
	std::vector<CoolingDevice_2_0> m_cooling_device_2_0;
	
	/*
	 * Each sensor can have associated a configuration for the
	 * threshold, the key is the name of the sensor.
	 */
	std::map<const std::string, TemperatureThreshold> m_threshold;

	/*
	 * Contains the list of the skin temperature sensors.
	 */
	std::vector<const std::string> m_skin_sensors;
	
	bool init(void);
};

}  // namespace implementation
}  // namespace V2_0
}  // namespace thermal
}  // namespace hardware
}  // namespace android

#endif