1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // The System Management Controller (SMC) is a hardware component that controls
6 // the power functions of Intel-based Macs. This file defines a class to read
9 #ifndef COMPONENTS_POWER_METRICS_SMC_MAC_H_
10 #define COMPONENTS_POWER_METRICS_SMC_MAC_H_
12 #import <Foundation/Foundation.h>
16 #include "base/containers/flat_map.h"
17 #include "base/mac/scoped_ioobject.h"
18 #include "components/power_metrics/smc_internal_types_mac.h"
19 #include "third_party/abseil-cpp/absl/types/optional.h"
21 namespace power_metrics {
25 // Creates an SMC Reader. Returns nullptr in case of failure.
26 static std::unique_ptr<SMCReader> Create();
30 // Returns the value of a key, or nullopt if not available.
31 // Virtual for testing.
32 virtual absl::optional<double> ReadKey(SMCKeyIdentifier identifier);
35 explicit SMCReader(base::mac::ScopedIOObject<io_object_t> connect);
40 SMCKey(base::mac::ScopedIOObject<io_object_t> connect,
41 SMCKeyIdentifier key_identifier);
43 SMCKey& operator=(SMCKey&&);
47 absl::optional<double> Read();
50 bool CallSMCFunction(uint8_t function, SMCParamStruct* out);
52 base::mac::ScopedIOObject<io_object_t> connect_;
53 SMCKeyIdentifier key_identifier_;
54 SMCKeyInfoData key_info_;
57 base::mac::ScopedIOObject<io_object_t> connect_;
58 base::flat_map<SMCKeyIdentifier, SMCKey> keys_;
61 } // namespace power_metrics
63 #endif // COMPONENTS_POWER_METRICS_SMC_MAC_H_