[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / power_metrics / smc_mac.h
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.
4
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
7 // known SMC keys.
8
9 #ifndef COMPONENTS_POWER_METRICS_SMC_MAC_H_
10 #define COMPONENTS_POWER_METRICS_SMC_MAC_H_
11
12 #import <Foundation/Foundation.h>
13
14 #include <memory>
15
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"
20
21 namespace power_metrics {
22
23 class SMCReader {
24  public:
25   // Creates an SMC Reader. Returns nullptr in case of failure.
26   static std::unique_ptr<SMCReader> Create();
27
28   virtual ~SMCReader();
29
30   // Returns the value of a key, or nullopt if not available.
31   // Virtual for testing.
32   virtual absl::optional<double> ReadKey(SMCKeyIdentifier identifier);
33
34  protected:
35   explicit SMCReader(base::mac::ScopedIOObject<io_object_t> connect);
36
37  private:
38   class SMCKey {
39    public:
40     SMCKey(base::mac::ScopedIOObject<io_object_t> connect,
41            SMCKeyIdentifier key_identifier);
42     SMCKey(SMCKey&&);
43     SMCKey& operator=(SMCKey&&);
44     ~SMCKey();
45
46     bool Exists() const;
47     absl::optional<double> Read();
48
49    private:
50     bool CallSMCFunction(uint8_t function, SMCParamStruct* out);
51
52     base::mac::ScopedIOObject<io_object_t> connect_;
53     SMCKeyIdentifier key_identifier_;
54     SMCKeyInfoData key_info_;
55   };
56
57   base::mac::ScopedIOObject<io_object_t> connect_;
58   base::flat_map<SMCKeyIdentifier, SMCKey> keys_;
59 };
60
61 }  // namespace power_metrics
62
63 #endif  // COMPONENTS_POWER_METRICS_SMC_MAC_H_