| // 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. |
| |
| #include "thermald/thermal_zone_temperature_sensor.h" |
| |
| #include <string> |
| |
| #include "base/files/file_util.h" |
| #include "base/logging.h" |
| #include "base/strings/stringprintf.h" |
| |
| using std::stoi; |
| using std::string; |
| using std::to_string; |
| |
| namespace thermald { |
| |
| ThermalZoneTemperatureSensor::ThermalZoneTemperatureSensor( |
| int zone_id, const string &sensor_name) |
| : TemperatureSensorCommon(sensor_name), |
| sysfs_attr_path_(base::StringPrintf( |
| "/sys/class/thermal/thermal_zone%d/temp", zone_id)) { |
| } |
| |
| ThermalZoneTemperatureSensor::ThermalZoneTemperatureSensor(int zone_id) |
| : ThermalZoneTemperatureSensor(zone_id, |
| "thermal_zone" + to_string(zone_id)) { |
| } |
| |
| bool ThermalZoneTemperatureSensor::ReadTemperature(int *value) { |
| DCHECK(value); |
| |
| string contents; |
| |
| if (!base::ReadFileToString(sysfs_attr_path_, &contents)) { |
| LOG(ERROR) << "[" << name() << "] failed to read '" |
| << sysfs_attr_path_.value() << "'"; |
| return false; |
| } |
| |
| *value = stoi(contents); |
| |
| return true; |
| } |
| |
| } // namespace thermald |