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

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

Issue 2078433002: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cap frequency to 60Hz. Created 4 years, 5 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
(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_SENSORS_PLATFORM_SENSOR_H_
6 #define DEVICE_SENSORS_PLATFORM_SENSOR_H_
7
8 #include <list>
9 #include <map>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h"
15 #include "mojo/public/cpp/system/buffer.h"
16
17 namespace device {
18
19 class PlatformSensorProvider;
20 class PlatformSensorConfiguration;
21
22 // Note: this enum must be in sync with mojo enum SensorType that is defined
23 // in public/interfaces/sensor.mojom.
24 enum class SensorType : int32_t {
25 FIRST = 1,
26 AMBIENT_LIGHT = FIRST,
27 PROXIMITY,
28 ACCELEROMETER,
29 GYROSCOPE,
30 PRESSURE,
31 LAST = PRESSURE,
32 };
33
34 // Note: this enum must be in sync with mojo enum ReportingMode that is defined
35 // in public/interfaces/sensor.mojom.
36 enum class ReportingMode : int32_t {
37 ON_CHANGE,
38 CONTINUOUS,
39 };
40
41 // Base class for the sensors provided by the platform. Concrete instances of
42 // this class are created by platform specific PlatformSensorProvider.
43 class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> {
44 public:
45 // The interface that must be implemented by PlatformSensor clients.
46 class Client {
47 public:
48 virtual void OnSensorReadingChanged() {}
49 virtual void OnSensorError() {}
50
51 protected:
52 virtual ~Client() {}
53 };
54
55 virtual ReportingMode GetReportingMode() = 0;
56
57 SensorType GetType() const;
58
59 bool StartListening(Client* client,
60 const PlatformSensorConfiguration& config);
61 bool StopListening(Client* client, const PlatformSensorConfiguration& config);
62
63 void AddClient(Client*);
64 void RemoveClient(Client*);
65
66 protected:
67 virtual ~PlatformSensor();
68 PlatformSensor(SensorType type,
69 mojo::ScopedSharedBufferMapping mapping,
70 PlatformSensorProvider* provider);
71
72 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
73
74 virtual bool UpdateSensor(const ConfigMap& configurations) = 0;
75 virtual bool CheckSensorConfiguration(
76 const PlatformSensorConfiguration& configuration) = 0;
77
78 void NotifySensorReadingChanged();
79 void NotifySensorError();
80
81 mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
82
83 private:
84 friend class base::RefCountedThreadSafe<PlatformSensor>;
85
86 SensorType type_;
87 base::ObserverList<Client, true> clients_;
88 ConfigMap config_map_;
89 PlatformSensorProvider* provider_;
90 base::WeakPtrFactory<PlatformSensor> weak_factory_;
91 DISALLOW_COPY_AND_ASSIGN(PlatformSensor);
92 };
93
94 } // namespace device
95
96 #endif // DEVICE_SENSORS_PLATFORM_SENSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698