Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: device/generic_sensor/platform_sensor.h

Issue 2395853003: [Sensors] Improvements in shared buffer managing (Closed)
Patch Set: Fixed "gn check" Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 24 matching lines...) Expand all
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);
57 58
58 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>; 59 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
60 using ReadingBuffer = SensorReadingSharedBuffer;
59 61
60 virtual bool UpdateSensorInternal(const ConfigMap& configurations); 62 virtual bool UpdateSensorInternal(const ConfigMap& configurations);
61 virtual bool StartSensor( 63 virtual bool StartSensor(
62 const PlatformSensorConfiguration& configuration) = 0; 64 const PlatformSensorConfiguration& configuration) = 0;
63 virtual void StopSensor() = 0; 65 virtual void StopSensor() = 0;
64 virtual bool CheckSensorConfiguration( 66 virtual bool CheckSensorConfiguration(
65 const PlatformSensorConfiguration& configuration) = 0; 67 const PlatformSensorConfiguration& configuration) = 0;
66 68
69 // Updates shared buffer with new sensor reading data.
70 // Note: this method is thread-safe.
71 void UpdateSensorReading(const SensorReading& reading, bool notify_clients);
72
67 void NotifySensorReadingChanged(); 73 void NotifySensorReadingChanged();
68 void NotifySensorError(); 74 void NotifySensorError();
69 75
70 mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
71
72 // For testing purposes. 76 // For testing purposes.
73 const ConfigMap& config_map() const { return config_map_; } 77 const ConfigMap& config_map() const { return config_map_; }
74 78
79 // Task runner that is used by mojo objects for the IPC.
80 // If platfrom sensor events are processed on a different
81 // thread, notifications are forwarded to |task_runner_|.
82 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
83
75 private: 84 private:
76 friend class base::RefCountedThreadSafe<PlatformSensor>; 85 friend class base::RefCountedThreadSafe<PlatformSensor>;
77 86 mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
Ken Rockot(use gerrit already) 2016/10/10 19:12:43 This must be const if you want UpdateSensorReading
78 mojom::SensorType type_; 87 mojom::SensorType type_;
79 base::ObserverList<Client, true> clients_; 88 base::ObserverList<Client, true> clients_;
80 ConfigMap config_map_; 89 ConfigMap config_map_;
81 PlatformSensorProvider* provider_; 90 PlatformSensorProvider* provider_;
82 base::WeakPtrFactory<PlatformSensor> weak_factory_; 91 base::WeakPtrFactory<PlatformSensor> weak_factory_;
83 DISALLOW_COPY_AND_ASSIGN(PlatformSensor); 92 DISALLOW_COPY_AND_ASSIGN(PlatformSensor);
84 }; 93 };
85 94
86 } // namespace device 95 } // namespace device
87 96
88 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_ 97 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/fake_platform_sensor_provider.cc ('k') | device/generic_sensor/platform_sensor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698