Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Side by Side Diff: chromeos/system/cpu_temperature_reader.h

Issue 2823583002: chromeos: Add CPU temperature reader (Closed)
Patch Set: Make runnable on main UI thread Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
6 #define CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
7
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/macros.h"
15
16 namespace chromeos {
17 namespace system {
18
19 // Used to read CPU temperature info from sysfs hwmon.
20 class CPUTemperatureReader {
21 public:
22 // Contains info from a CPU temperature sensor.
23 struct CPUTemperatureInfo {
24 // The temperature read by a CPU temperature sensor in degrees Celsius.
25 double temp_celsius;
26
27 // The name of the CPU temperature zone monitored by this sensor. Used to
28 // identify the source of each temperature reading. Taken from sysfs "name"
29 // or "label" field, if it exists.
30 std::string label;
31
32 bool operator<(const CPUTemperatureInfo& other) const {
33 return std::make_pair(temp_celsius, label) <
34 std::make_pair(other.temp_celsius, label);
35 }
36 };
37
38 using GetCPUTemperaturesCallback =
39 base::Callback<void(const std::vector<CPUTemperatureInfo>&)>;
40
41 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.
42
43 // Read temperature from each thermal sensor of the CPU. Returns a vector
44 // 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.
45 // called on the main UI thread.
46 void GetCPUTemperatures(const GetCPUTemperaturesCallback& callback);
47
48 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.
49
50 private:
51 // Sysfs hwmon directory path. Gets initialized to a default value but can be
52 // 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.
53 std::string hwmon_dir_;
54
55 DISALLOW_COPY_AND_ASSIGN(CPUTemperatureReader);
56 };
57
58 } // namespace system
59 } // namespace chromeos
60
61 #endif // CHROMEOS_SYSTEM_CPU_TEMPERATURE_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698