OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
Reilly Grant (use Gerrit)
2016/11/29 20:19:56
Put this in //device/generic_sensor alongside plat
maksims (do not use this acc)
2016/12/05 13:06:59
Done.
| |
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_LINUX_PLATFORM_SENSOR_READER_LINUX_H_ | |
6 #define DEVICE_GENERIC_SENSOR_LINUX_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 SensorDeviceLinux; | |
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 SensorDeviceLinux* sensor_device, | |
29 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner); | |
30 | |
31 virtual ~SensorReader(); | |
32 | |
33 // Starts fetching data based on strategy this reader has chosen. | |
34 // Only polling strategy is supported at the moment. Thread safe. | |
35 virtual bool StartFetchingData( | |
36 const PlatformSensorConfiguration& configuration, | |
37 PlatformSensorLinux* sensor) = 0; | |
38 | |
39 // Stops fetching data. Thread safe. | |
40 virtual void StopFetchingData() = 0; | |
41 | |
42 protected: | |
43 SensorReader(scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner); | |
44 | |
45 // Notifies |sensor_| about an error. | |
46 void NotifyReadError(); | |
47 | |
48 // Non-owned pointer to a sensor that created this reader. | |
49 PlatformSensorLinux* sensor_; | |
50 | |
51 // A task runner that is used to poll data. | |
52 scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner_; | |
53 | |
54 // A task runner that belongs to a thread this reader is created on. | |
55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(SensorReader); | |
58 }; | |
59 | |
60 } // namespace device | |
61 | |
62 #endif // DEVICE_GENERIC_SENSOR_LINUX_PLATFORM_SENSOR_READER_LINUX_H_ | |
OLD | NEW |