1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <string>
20 #include <unordered_map>
21 
22 namespace android {
23 namespace hardware {
24 namespace thermal {
25 namespace V2_0 {
26 namespace implementation {
27 
28 class ThermalFiles {
29   public:
30     ThermalFiles() = default;
31     ~ThermalFiles() = default;
32     ThermalFiles(const ThermalFiles &) = delete;
33     void operator=(const ThermalFiles &) = delete;
34 
35     std::string getThermalFilePath(std::string_view thermal_name) const;
36     // Returns true if add was successful, false otherwise.
37     bool addThermalFile(std::string_view thermal_name, std::string_view path);
38     // If thermal_name is not found in the thermal names to path map, this will set
39     // data to empty and return false. If the thermal_name is found and its content
40     // is read, this function will fill in data accordingly then return true.
41     bool readThermalFile(std::string_view thermal_name, std::string *data) const;
42     bool writeCdevFile(std::string_view thermal_name, std::string_view data);
getNumThermalFiles()43     size_t getNumThermalFiles() const { return thermal_name_to_path_map_.size(); }
44 
45   private:
46     std::unordered_map<std::string, std::string> thermal_name_to_path_map_;
47 };
48 
49 }  // namespace implementation
50 }  // namespace V2_0
51 }  // namespace thermal
52 }  // namespace hardware
53 }  // namespace android
54