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_H_ | 5 #ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ |
6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ | 6 #define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 15 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
15 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" | 16 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" |
16 #include "mojo/public/cpp/system/buffer.h" | 17 #include "mojo/public/cpp/system/buffer.h" |
17 | 18 |
18 namespace device { | 19 namespace device { |
19 | 20 |
20 class PlatformSensorProvider; | 21 class PlatformSensorProvider; |
21 class PlatformSensorConfiguration; | 22 class PlatformSensorConfiguration; |
22 | 23 |
23 // Base class for the sensors provided by the platform. Concrete instances of | 24 // Base class for the sensors provided by the platform. Concrete instances of |
24 // this class are created by platform specific PlatformSensorProvider. | 25 // this class are created by platform specific PlatformSensorProvider. |
(...skipping 21 matching lines...) Expand all Loading... |
46 | 47 |
47 void UpdateSensor(); | 48 void UpdateSensor(); |
48 | 49 |
49 void AddClient(Client*); | 50 void AddClient(Client*); |
50 void RemoveClient(Client*); | 51 void RemoveClient(Client*); |
51 | 52 |
52 protected: | 53 protected: |
53 virtual ~PlatformSensor(); | 54 virtual ~PlatformSensor(); |
54 PlatformSensor(mojom::SensorType type, | 55 PlatformSensor(mojom::SensorType type, |
55 mojo::ScopedSharedBufferMapping mapping, | 56 mojo::ScopedSharedBufferMapping mapping, |
56 PlatformSensorProvider* provider); | 57 PlatformSensorProvider* provider, |
| 58 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
57 | 59 |
58 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>; | 60 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>; |
| 61 using ReadingBuffer = SensorReadingSharedBuffer; |
59 | 62 |
60 virtual bool UpdateSensorInternal(const ConfigMap& configurations); | 63 virtual bool UpdateSensorInternal(const ConfigMap& configurations); |
61 virtual bool StartSensor( | 64 virtual bool StartSensor( |
62 const PlatformSensorConfiguration& configuration) = 0; | 65 const PlatformSensorConfiguration& configuration) = 0; |
63 virtual void StopSensor() = 0; | 66 virtual void StopSensor() = 0; |
64 virtual bool CheckSensorConfiguration( | 67 virtual bool CheckSensorConfiguration( |
65 const PlatformSensorConfiguration& configuration) = 0; | 68 const PlatformSensorConfiguration& configuration) = 0; |
66 | 69 |
| 70 // Updates shared buffer with new sensor reading data. |
| 71 // Note: this method is thread-safe. |
| 72 void UpdateSensorReading(const SensorReading& reading, bool notify_clients); |
| 73 |
67 void NotifySensorReadingChanged(); | 74 void NotifySensorReadingChanged(); |
68 void NotifySensorError(); | 75 void NotifySensorError(); |
69 | 76 |
70 mojo::ScopedSharedBufferMapping shared_buffer_mapping_; | |
71 | |
72 // For testing purposes. | 77 // For testing purposes. |
73 const ConfigMap& config_map() const { return config_map_; } | 78 const ConfigMap& config_map() const { return config_map_; } |
74 | 79 |
| 80 // Task runner that is used by mojo objects for the IPC. |
| 81 // If platfrom sensor events are processed on a different |
| 82 // thread, notifications are forwarded to |task_runner_|. |
| 83 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 84 |
75 private: | 85 private: |
76 friend class base::RefCountedThreadSafe<PlatformSensor>; | 86 friend class base::RefCountedThreadSafe<PlatformSensor>; |
77 | 87 mojo::ScopedSharedBufferMapping shared_buffer_mapping_; |
78 mojom::SensorType type_; | 88 mojom::SensorType type_; |
79 base::ObserverList<Client, true> clients_; | 89 base::ObserverList<Client, true> clients_; |
80 ConfigMap config_map_; | 90 ConfigMap config_map_; |
81 PlatformSensorProvider* provider_; | 91 PlatformSensorProvider* provider_; |
82 base::WeakPtrFactory<PlatformSensor> weak_factory_; | 92 base::WeakPtrFactory<PlatformSensor> weak_factory_; |
83 DISALLOW_COPY_AND_ASSIGN(PlatformSensor); | 93 DISALLOW_COPY_AND_ASSIGN(PlatformSensor); |
84 }; | 94 }; |
85 | 95 |
86 } // namespace device | 96 } // namespace device |
87 | 97 |
88 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ | 98 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ |
OLD | NEW |