| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ | 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ | 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
| 7 | 7 |
| 8 #include "device/generic_sensor/platform_sensor.h" | 8 #include "device/generic_sensor/platform_sensor.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| 11 class RepeatingTimer; | |
| 12 class SingleThreadTaskRunner; | 11 class SingleThreadTaskRunner; |
| 13 class Thread; | |
| 14 } | 12 } |
| 15 | 13 |
| 16 namespace device { | 14 namespace device { |
| 17 | 15 |
| 18 class SensorReader; | 16 class SensorReader; |
| 19 struct SensorDataLinux; | 17 struct SensorDeviceLinux; |
| 20 | 18 |
| 21 class PlatformSensorLinux : public PlatformSensor { | 19 class PlatformSensorLinux : public PlatformSensor { |
| 22 public: | 20 public: |
| 23 PlatformSensorLinux( | 21 PlatformSensorLinux( |
| 24 mojom::SensorType type, | 22 mojom::SensorType type, |
| 25 mojo::ScopedSharedBufferMapping mapping, | 23 mojo::ScopedSharedBufferMapping mapping, |
| 26 PlatformSensorProvider* provider, | 24 PlatformSensorProvider* provider, |
| 27 const SensorDataLinux& data, | 25 SensorDeviceLinux* sensor_device, |
| 28 std::unique_ptr<SensorReader> sensor_reader, | |
| 29 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); | 26 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); |
| 30 | 27 |
| 31 // Thread safe. | |
| 32 mojom::ReportingMode GetReportingMode() override; | 28 mojom::ReportingMode GetReportingMode() override; |
| 33 | 29 |
| 30 // Called by a sensor reader. Takes new readings. |
| 31 void UpdatePlatformSensorReading(SensorReading reading); |
| 32 |
| 33 // Called by a sensor reader if an error occurs. |
| 34 void NotifyPlatformSensorError(); |
| 35 |
| 34 protected: | 36 protected: |
| 35 ~PlatformSensorLinux() override; | 37 ~PlatformSensorLinux() override; |
| 36 bool StartSensor(const PlatformSensorConfiguration& configuration) override; | 38 bool StartSensor(const PlatformSensorConfiguration& configuration) override; |
| 37 void StopSensor() override; | 39 void StopSensor() override; |
| 38 bool CheckSensorConfiguration( | 40 bool CheckSensorConfiguration( |
| 39 const PlatformSensorConfiguration& configuration) override; | 41 const PlatformSensorConfiguration& configuration) override; |
| 40 PlatformSensorConfiguration GetDefaultConfiguration() override; | 42 PlatformSensorConfiguration GetDefaultConfiguration() override; |
| 41 | 43 |
| 42 private: | 44 private: |
| 43 void BeginPoll(const PlatformSensorConfiguration& configuration); | |
| 44 void StopPoll(); | |
| 45 | |
| 46 // Triggers |sensor_reader_| to read new sensor data. | |
| 47 // If new data is read, UpdateSensorReading() is called. | |
| 48 void PollForReadingData(); | |
| 49 | |
| 50 // Owned timer to be deleted on a polling thread. | |
| 51 base::RepeatingTimer* timer_; | |
| 52 | |
| 53 const PlatformSensorConfiguration default_configuration_; | 45 const PlatformSensorConfiguration default_configuration_; |
| 54 const mojom::ReportingMode reporting_mode_; | 46 const mojom::ReportingMode reporting_mode_; |
| 55 | 47 |
| 56 // A sensor reader that reads values from sensor files | 48 // A sensor reader that reads values from sensor files |
| 57 // and stores them to a SensorReading structure. | 49 // and stores them to a SensorReading structure. |
| 58 std::unique_ptr<SensorReader> sensor_reader_; | 50 std::unique_ptr<SensorReader> sensor_reader_; |
| 59 | 51 |
| 60 // A task runner that is used to poll sensor data. | |
| 61 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; | |
| 62 | |
| 63 // Stores previously read values that are used to | 52 // Stores previously read values that are used to |
| 64 // determine whether the recent values are changed | 53 // determine whether the recent values are changed |
| 65 // and IPC can be notified that updates are available. | 54 // and IPC can be notified that updates are available. |
| 66 SensorReading old_values_; | 55 SensorReading old_values_; |
| 67 | 56 |
| 68 base::WeakPtrFactory<PlatformSensorLinux> weak_factory_; | 57 base::WeakPtrFactory<PlatformSensorLinux> weak_factory_; |
| 69 | 58 |
| 70 DISALLOW_COPY_AND_ASSIGN(PlatformSensorLinux); | 59 DISALLOW_COPY_AND_ASSIGN(PlatformSensorLinux); |
| 71 }; | 60 }; |
| 72 | 61 |
| 73 } // namespace device | 62 } // namespace device |
| 74 | 63 |
| 75 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ | 64 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
| OLD | NEW |