• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 THERMAL_SENSOR_PROVISION_H
17 #define THERMAL_SENSOR_PROVISION_H
18 
19 #include <list>
20 #include <map>
21 #include <limits.h>
22 
23 namespace OHOS {
24 namespace PowerMgr {
25 using SensorsMap = std::map<std::string, int32_t>;
26 
27 struct ThermalZoneSysfsPathInfo {
28     char* name;
29     char tempPath[PATH_MAX];
30     char typePath[PATH_MAX];
31     int32_t fd;
32 };
33 
34 struct ThermalSysfsPathInfo {
35     char* name;
36     char thermalZonePath[PATH_MAX];
37     char coolingDevicePath[PATH_MAX];
38     int32_t fd;
39 };
40 
41 class ThermalSensorProvision {
42 public:
ThermalSensorProvision()43     ThermalSensorProvision() {};
~ThermalSensorProvision()44     ~ThermalSensorProvision() {};
45 
46     bool InitProvision();
GetSensorData()47     SensorsMap GetSensorData()
48     {
49         return typeTempMap_;
50     }
51     int32_t GetMaxCd();
52     void ReportThermalZoneData(int32_t reportTime, std::vector<int32_t> &multipleList);
53 private:
54     int32_t ParseThermalZoneInfo();
55     int32_t InitThermalZoneSysfs();
56     int32_t ReadThermalSysfsToBuff(const char* path, char* buf, size_t size) const;
57     int32_t ReadSysfsFile(const char* path, char* buf, size_t size) const;
58     void FormatThermalSysfsPaths(struct ThermalSysfsPathInfo *pTSysPathInfo);
59     void FormatThermalPaths(char *path, size_t size, const char *format, const char* name);
60     void Trim(char* str) const;
61     SensorsMap typeTempMap_;
62 
63     /* timer related */
64     struct ThermalZoneSysfsPathInfo tzSysPathInfo_;
65     std::list<ThermalZoneSysfsPathInfo> lTzSysPathInfo_;
66 };
67 } // namespace PowerMgr
68 } // namespace OHOS
69 #endif
70