• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BASE_POWER_MONITOR_IOPM_POWER_SOURCE_SAMPLING_EVENT_SOURCE_H_
6 #define BASE_POWER_MONITOR_IOPM_POWER_SOURCE_SAMPLING_EVENT_SOURCE_H_
7 
8 #include "base/base_export.h"
9 #include "base/functional/callback.h"
10 #include "base/mac/scoped_ionotificationportref.h"
11 #include "base/mac/scoped_ioobject.h"
12 #include "base/power_monitor/sampling_event_source.h"
13 
14 namespace base {
15 
16 // Generates a sampling event when a state change notification is dispatched by
17 // the IOPMPowerSource service.
18 class BASE_EXPORT IOPMPowerSourceSamplingEventSource
19     : public SamplingEventSource {
20  public:
21   IOPMPowerSourceSamplingEventSource();
22 
23   ~IOPMPowerSourceSamplingEventSource() override;
24 
25   // SamplingEventSource:
26   bool Start(SamplingEventCallback callback) override;
27 
28  private:
29   static void OnNotification(void* context,
30                              io_service_t service,
31                              natural_t message_type,
32                              void* message_argument);
33 
34   mac::ScopedIONotificationPortRef notify_port_;
35   mac::ScopedIOObject<io_service_t> service_;
36   mac::ScopedIOObject<io_object_t> notification_;
37   SamplingEventCallback callback_;
38 };
39 
40 }  // namespace base
41 
42 #endif  // BASE_POWER_MONITOR_IOPM_POWER_SOURCE_SAMPLING_EVENT_SOURCE_H_
43