Chromium Code Reviews| Index: chromeos/system/cpu_temperature_reader.h |
| diff --git a/chromeos/system/cpu_temperature_reader.h b/chromeos/system/cpu_temperature_reader.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7fb3dbc30d720bd9af2cdd2a4b962fd0770af991 |
| --- /dev/null |
| +++ b/chromeos/system/cpu_temperature_reader.h |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ |
| +#define CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ |
| + |
| +#include <string> |
| +#include <utility> |
| +#include <vector> |
| + |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| + |
| +namespace chromeos { |
| +namespace system { |
| + |
| +// Used to read CPU temperature info from sysfs hwmon. |
| +class CPUTemperatureReader { |
| + public: |
| + // Contains info from a CPU temperature sensor. |
| + struct CPUTemperatureInfo { |
| + // The temperature read by a CPU temperature sensor in degrees Celsius. |
| + double temp_celsius; |
| + |
| + // The name of the CPU temperature zone monitored by this sensor. Used to |
| + // identify the source of each temperature reading. Taken from sysfs "name" |
| + // or "label" field, if it exists. |
| + std::string label; |
| + |
| + bool operator<(const CPUTemperatureInfo& other) const { |
| + return std::make_pair(temp_celsius, label) < |
| + std::make_pair(other.temp_celsius, label); |
| + } |
| + }; |
| + |
| + using GetCPUTemperaturesCallback = |
| + base::Callback<void(const std::vector<CPUTemperatureInfo>&)>; |
| + |
| + CPUTemperatureReader(); |
|
Daniel Erat
2017/04/20 21:23:53
declare a d'tor here and define it in the .cc file
Simon Que
2017/04/21 08:52:26
Done.
|
| + |
| + // Read temperature from each thermal sensor of the CPU. Returns a vector |
| + // containing a reading from each sensor to |callback|. This function can be |
|
Daniel Erat
2017/04/20 21:23:53
nit: change second sentence to "Asynchronously run
Simon Que
2017/04/21 08:52:26
Done.
|
| + // called on the main UI thread. |
| + void GetCPUTemperatures(const GetCPUTemperaturesCallback& callback); |
| + |
| + void set_hwmon_dir_for_test(const std::string& dir) { hwmon_dir_ = dir; } |
|
Daniel Erat
2017/04/20 21:23:53
nit: inline getters/setters usually come after d't
Simon Que
2017/04/21 08:52:26
Done.
|
| + |
| + private: |
| + // Sysfs hwmon directory path. Gets initialized to a default value but can be |
| + // overriden by set_hwmon_dir_for_test(). |
|
Daniel Erat
2017/04/20 21:23:53
nit: don't need second sentence
Simon Que
2017/04/21 08:52:26
Done.
|
| + std::string hwmon_dir_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader); |
| +}; |
| + |
| +} // namespace system |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_ |