blob: 54ad997c4c724e6b6d153c7f5b00e596df5b652e [file] [log] [blame]
// 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/fake_temperature_sensor.h"
#include <string>
#include "base/check.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/stringprintf.h"
using std::stoi;
using std::string;
namespace thermald {
FakeTemperatureSensor::FakeTemperatureSensor(
const base::FilePath &fake_data_file, const string &name)
: TemperatureSensorCommon(name),
fake_data_file_(fake_data_file) {
}
bool FakeTemperatureSensor::ReadTemperature(int *value) {
DCHECK(value);
string contents;
if (!base::ReadFileToString(fake_data_file_, &contents)) {
LOG(ERROR) << "[" << name() << "] Failed to read '"
<< fake_data_file_.value() << "'";
return false;
}
*value = stoi(contents);
return true;
}
} // namespace thermald