platform_sensor_ambient_light_mac.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2016 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 SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_AMBIENT_LIGHT_MAC_H_
  5. #define SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_AMBIENT_LIGHT_MAC_H_
  6. #include <IOKit/IOKitLib.h>
  7. #include "base/mac/scoped_ionotificationportref.h"
  8. #include "base/mac/scoped_ioobject.h"
  9. #include "services/device/generic_sensor/platform_sensor.h"
  10. namespace device {
  11. // Implementation of PlatformSensor for macOS to query the ambient light sensor.
  12. // This is a single instance object per browser process which is created by
  13. // PlatformSensorProviderMac. If there are no clients, this instance is not
  14. // created.
  15. class PlatformSensorAmbientLightMac : public PlatformSensor {
  16. public:
  17. // Construct a platform sensor of AMBIENT_LIGHT, given a buffer |mapping|
  18. // to write the result back.
  19. PlatformSensorAmbientLightMac(SensorReadingSharedBuffer* reading_buffer,
  20. PlatformSensorProvider* provider);
  21. PlatformSensorAmbientLightMac(const PlatformSensorAmbientLightMac&) = delete;
  22. PlatformSensorAmbientLightMac& operator=(
  23. const PlatformSensorAmbientLightMac&) = delete;
  24. mojom::ReportingMode GetReportingMode() override;
  25. // Can only be called once, the first time or after a StopSensor call.
  26. bool StartSensor(const PlatformSensorConfiguration& configuration) override;
  27. void StopSensor() override;
  28. protected:
  29. ~PlatformSensorAmbientLightMac() override;
  30. bool CheckSensorConfiguration(
  31. const PlatformSensorConfiguration& configuration) override;
  32. PlatformSensorConfiguration GetDefaultConfiguration() override;
  33. private:
  34. bool ReadAndUpdate();
  35. static void IOServiceCallback(void* context,
  36. io_service_t service,
  37. natural_t message_type,
  38. void* message_argument);
  39. // IOService representing the LMU sensor.
  40. base::mac::ScopedIOObject<io_service_t> light_sensor_service_;
  41. // Port used to get the notifications from the sensor.
  42. base::mac::ScopedIONotificationPortRef light_sensor_port_;
  43. // IO Object used to query the value of the sensor.
  44. base::mac::ScopedIOObject<io_object_t> light_sensor_object_;
  45. // IO Notifications created by IOServiceAddInterestNotification.
  46. base::mac::ScopedIOObject<io_object_t> light_sensor_notification_;
  47. // IO Notifications created by IOServiceAddInterestNotification when the
  48. // sensor is busy.
  49. base::mac::ScopedIOObject<io_object_t> light_sensor_busy_notification_;
  50. double current_lux_;
  51. };
  52. } // namespace device
  53. #endif // SERVICES_DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_AMBIENT_LIGHT_MAC_H_