iopm_power_source_sampling_event_source.h 1.4 KB

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