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_READER_LINUX_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "device/generic_sensor/generic_sensor_export.h" |
| 10 |
| 11 namespace base { |
| 12 class SingleThreadTaskRunner; |
| 13 } |
| 14 |
| 15 namespace device { |
| 16 |
| 17 class PlatformSensorLinux; |
| 18 class PlatformSensorConfiguration; |
| 19 struct SensorInfoLinux; |
| 20 |
| 21 // A generic reader class that can be implemented with two different strategies: |
| 22 // polling and on trigger. |
| 23 class SensorReader { |
| 24 public: |
| 25 // Creates a new instance of SensorReader. At the moment, only polling |
| 26 // reader is supported. |
| 27 static std::unique_ptr<SensorReader> Create( |
| 28 const SensorInfoLinux* sensor_device, |
| 29 PlatformSensorLinux* sensor, |
| 30 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); |
| 31 |
| 32 virtual ~SensorReader(); |
| 33 |
| 34 // Starts fetching data based on strategy this reader has chosen. |
| 35 // Only polling strategy is supported at the moment. Thread safe. |
| 36 virtual bool StartFetchingData( |
| 37 const PlatformSensorConfiguration& configuration) = 0; |
| 38 |
| 39 // Stops fetching data. Thread safe. |
| 40 virtual void StopFetchingData() = 0; |
| 41 |
| 42 protected: |
| 43 SensorReader(PlatformSensorLinux* sensor, |
| 44 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner); |
| 45 |
| 46 // Notifies |sensor_| about an error. |
| 47 void NotifyReadError(); |
| 48 |
| 49 // Non-owned pointer to a sensor that created this reader. |
| 50 PlatformSensorLinux* sensor_; |
| 51 |
| 52 // A task runner that is used to poll data. |
| 53 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; |
| 54 |
| 55 // A task runner that belongs to a thread this reader is created on. |
| 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 57 |
| 58 // Indicates if reading is active. |
| 59 bool is_reading_active_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SensorReader); |
| 62 }; |
| 63 |
| 64 } // namespace device |
| 65 |
| 66 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ |
OLD | NEW |