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

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

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Definition for PlatformSensorProvider ctor/dtor Created 4 years, 3 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
« no previous file with comments | « device/generic_sensor/OWNERS ('k') | device/generic_sensor/platform_sensor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_GENERIC_SENSOR_PLATFORM_SENSOR_H_
6 #define DEVICE_GENERIC_SENSOR_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 "device/generic_sensor/public/interfaces/sensor.mojom.h"
16 #include "mojo/public/cpp/system/buffer.h"
17
18 namespace device {
19
20 class PlatformSensorProvider;
21 class PlatformSensorConfiguration;
22
23 // Base class for the sensors provided by the platform. Concrete instances of
24 // this class are created by platform specific PlatformSensorProvider.
25 class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> {
26 public:
27 // The interface that must be implemented by PlatformSensor clients.
28 class Client {
29 public:
30 virtual void OnSensorReadingChanged() = 0;
31 virtual void OnSensorError() = 0;
32 virtual bool IsNotificationSuspended() = 0;
33
34 protected:
35 virtual ~Client() {}
36 };
37
38 virtual mojom::ReportingMode GetReportingMode() = 0;
39
40 mojom::SensorType GetType() const;
41
42 bool StartListening(Client* client,
43 const PlatformSensorConfiguration& config);
44 bool StopListening(Client* client, const PlatformSensorConfiguration& config);
45
46 void UpdateSensor();
47
48 void AddClient(Client*);
49 void RemoveClient(Client*);
50
51 protected:
52 virtual ~PlatformSensor();
53 PlatformSensor(mojom::SensorType type,
54 mojo::ScopedSharedBufferMapping mapping,
55 PlatformSensorProvider* provider);
56
57 using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
58
59 virtual bool UpdateSensorInternal(const ConfigMap& configurations) = 0;
60 virtual bool CheckSensorConfiguration(
61 const PlatformSensorConfiguration& configuration) = 0;
62
63 void NotifySensorReadingChanged();
64 void NotifySensorError();
65
66 mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
67
68 private:
69 friend class base::RefCountedThreadSafe<PlatformSensor>;
70
71 mojom::SensorType type_;
72 base::ObserverList<Client, true> clients_;
73 ConfigMap config_map_;
74 PlatformSensorProvider* provider_;
75 base::WeakPtrFactory<PlatformSensor> weak_factory_;
76 DISALLOW_COPY_AND_ASSIGN(PlatformSensor);
77 };
78
79 } // namespace device
80
81 #endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_H_
OLDNEW
« no previous file with comments | « device/generic_sensor/OWNERS ('k') | device/generic_sensor/platform_sensor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698