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