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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: device/sensors/platform_sensor.h
diff --git a/device/sensors/platform_sensor.h b/device/sensors/platform_sensor.h
new file mode 100644
index 0000000000000000000000000000000000000000..4aa4445eb8909af1839b1b2f860708bbbfb30127
--- /dev/null
+++ b/device/sensors/platform_sensor.h
@@ -0,0 +1,96 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef DEVICE_SENSORS_PLATFORM_SENSOR_H_
+#define DEVICE_SENSORS_PLATFORM_SENSOR_H_
+
+#include <list>
+#include <map>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/observer_list.h"
+#include "mojo/public/cpp/system/buffer.h"
+
+namespace device {
+
+class PlatformSensorProvider;
+class PlatformSensorConfiguration;
+
+// Note: this enum must be in sync with mojo enum SensorType that is defined
+// in public/interfaces/sensor.mojom.
+enum class SensorType : int32_t {
+ FIRST = 1,
+ AMBIENT_LIGHT = FIRST,
+ PROXIMITY,
+ ACCELEROMETER,
+ GYROSCOPE,
+ PRESSURE,
+ LAST = PRESSURE,
+};
+
+// Note: this enum must be in sync with mojo enum ReportingMode that is defined
+// in public/interfaces/sensor.mojom.
+enum class ReportingMode : int32_t {
+ ON_CHANGE,
+ CONTINUOUS,
+};
+
+// Base class for the sensors provided by the platform. Concrete instances of
+// this class are created by platform specific PlatformSensorProvider.
+class PlatformSensor : public base::RefCountedThreadSafe<PlatformSensor> {
+ public:
+ // The interface that must be implemented by PlatformSensor clients.
+ class Client {
+ public:
+ virtual void OnSensorReadingChanged() {}
+ virtual void OnSensorError() {}
+
+ protected:
+ virtual ~Client() {}
+ };
+
+ virtual ReportingMode GetReportingMode() = 0;
+
+ SensorType GetType() const;
+
+ bool StartListening(Client* client,
+ const PlatformSensorConfiguration& config);
+ bool StopListening(Client* client, const PlatformSensorConfiguration& config);
+
+ void AddClient(Client*);
+ void RemoveClient(Client*);
+
+ protected:
+ virtual ~PlatformSensor();
+ PlatformSensor(SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ PlatformSensorProvider* provider);
+
+ using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
+
+ virtual bool UpdateSensor(const ConfigMap& configurations) = 0;
+ virtual bool CheckSensorConfiguration(
+ const PlatformSensorConfiguration& configuration) = 0;
+
+ void NotifySensorReadingChanged();
+ void NotifySensorError();
+
+ mojo::ScopedSharedBufferMapping shared_buffer_mapping_;
+
+ private:
+ friend class base::RefCountedThreadSafe<PlatformSensor>;
+
+ SensorType type_;
+ base::ObserverList<Client, true> clients_;
+ ConfigMap config_map_;
+ PlatformSensorProvider* provider_;
+ base::WeakPtrFactory<PlatformSensor> weak_factory_;
+ DISALLOW_COPY_AND_ASSIGN(PlatformSensor);
+};
+
+} // namespace device
+
+#endif // DEVICE_SENSORS_PLATFORM_SENSOR_H_

Powered by Google App Engine
This is Rietveld 408576698