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_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
| 7 |
| 8 #include "device/generic_sensor/platform_sensor.h" |
| 9 |
| 10 namespace base { |
| 11 class RepeatingTimer; |
| 12 class SingleThreadTaskRunner; |
| 13 class Thread; |
| 14 } |
| 15 |
| 16 namespace device { |
| 17 |
| 18 class SensorReader; |
| 19 struct SensorDataLinux; |
| 20 |
| 21 class PlatformSensorLinux : public PlatformSensor { |
| 22 public: |
| 23 PlatformSensorLinux( |
| 24 mojom::SensorType type, |
| 25 mojo::ScopedSharedBufferMapping mapping, |
| 26 PlatformSensorProvider* provider, |
| 27 const SensorDataLinux& data, |
| 28 std::unique_ptr<SensorReader> sensor_reader, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); |
| 30 |
| 31 // Thread safe. |
| 32 mojom::ReportingMode GetReportingMode() override; |
| 33 |
| 34 protected: |
| 35 ~PlatformSensorLinux() override; |
| 36 bool StartSensor(const PlatformSensorConfiguration& configuration) override; |
| 37 void StopSensor() override; |
| 38 bool CheckSensorConfiguration( |
| 39 const PlatformSensorConfiguration& configuration) override; |
| 40 PlatformSensorConfiguration GetDefaultConfiguration() override; |
| 41 |
| 42 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_; |
| 54 const mojom::ReportingMode reporting_mode_; |
| 55 |
| 56 // A sensor reader that reads values from sensor files |
| 57 // and stores them to a SensorReading structure. |
| 58 std::unique_ptr<SensorReader> sensor_reader_; |
| 59 |
| 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 |
| 64 // determine whether the recent values are changed |
| 65 // and IPC can be notified that updates are available. |
| 66 SensorReading old_values_; |
| 67 |
| 68 base::WeakPtrFactory<PlatformSensorLinux> weak_factory_; |
| 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(PlatformSensorLinux); |
| 71 }; |
| 72 |
| 73 } // namespace device |
| 74 |
| 75 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_LINUX_H_ |
OLD | NEW |