| 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/callback.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "device/generic_sensor/generic_sensor_export.h" | |
| 13 | |
| 14 namespace base { | |
| 15 class SingleThreadTaskRunner; | |
| 16 } | |
| 17 | |
| 18 namespace device { | |
| 19 | |
| 20 class PlatformSensorConfiguration; | |
| 21 class PlatformSensorLinux; | |
| 22 struct SensorInfoLinux; | |
| 23 | |
| 24 // A generic reader class that can be implemented with two different strategies: | |
| 25 // polling and on trigger. All methods are not thread-safe and must be called | |
| 26 // on a polling thread that allows I/O. | |
| 27 class SensorReader { | |
| 28 public: | |
| 29 // Creates a new instance of SensorReader. At the moment, only polling | |
| 30 // reader is supported. | |
| 31 static std::unique_ptr<SensorReader> Create( | |
| 32 const SensorInfoLinux* sensor_device, | |
| 33 base::WeakPtr<PlatformSensorLinux> sensor, | |
| 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 35 | |
| 36 virtual ~SensorReader(); | |
| 37 | |
| 38 // Starts fetching data based on strategy this reader has chosen. | |
| 39 // Only polling strategy is supported at the moment. | |
| 40 virtual void StartFetchingData( | |
| 41 const PlatformSensorConfiguration& configuration) = 0; | |
| 42 | |
| 43 // Stops fetching data. | |
| 44 virtual void StopFetchingData() = 0; | |
| 45 | |
| 46 protected: | |
| 47 SensorReader(base::WeakPtr<PlatformSensorLinux> sensor, | |
| 48 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 49 | |
| 50 // Notifies |sensor_| about an error. | |
| 51 void NotifyReadError(); | |
| 52 | |
| 53 // In builds with DCHECK enabled checks that methods of this | |
| 54 // and derived classes are called on a right thread. | |
| 55 THREAD_CHECKER(thread_checker_); | |
| 56 | |
| 57 // A sensor that this reader is owned by and notifies about errors and | |
| 58 // readings to. | |
| 59 base::WeakPtr<PlatformSensorLinux> sensor_; | |
| 60 | |
| 61 // A task runner that is used to report about new readings and errors | |
| 62 // to a |sensor_|. | |
| 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 64 | |
| 65 // Indicates if reading is active. | |
| 66 bool is_reading_active_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(SensorReader); | |
| 69 }; | |
| 70 | |
| 71 } // namespace device | |
| 72 | |
| 73 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_READER_LINUX_H_ | |
| OLD | NEW |