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

Unified 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, 4 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
« no previous file with comments | « device/generic_sensor/OWNERS ('k') | device/generic_sensor/platform_sensor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/platform_sensor.h
diff --git a/device/generic_sensor/platform_sensor.h b/device/generic_sensor/platform_sensor.h
new file mode 100644
index 0000000000000000000000000000000000000000..0eeb247332df3ced66eda12cc73074bee5cb3abe
--- /dev/null
+++ b/device/generic_sensor/platform_sensor.h
@@ -0,0 +1,81 @@
+// 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_GENERIC_SENSOR_PLATFORM_SENSOR_H_
+#define DEVICE_GENERIC_SENSOR_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 "device/generic_sensor/public/interfaces/sensor.mojom.h"
+#include "mojo/public/cpp/system/buffer.h"
+
+namespace device {
+
+class PlatformSensorProvider;
+class PlatformSensorConfiguration;
+
+// 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() = 0;
+ virtual void OnSensorError() = 0;
+ virtual bool IsNotificationSuspended() = 0;
+
+ protected:
+ virtual ~Client() {}
+ };
+
+ virtual mojom::ReportingMode GetReportingMode() = 0;
+
+ mojom::SensorType GetType() const;
+
+ bool StartListening(Client* client,
+ const PlatformSensorConfiguration& config);
+ bool StopListening(Client* client, const PlatformSensorConfiguration& config);
+
+ void UpdateSensor();
+
+ void AddClient(Client*);
+ void RemoveClient(Client*);
+
+ protected:
+ virtual ~PlatformSensor();
+ PlatformSensor(mojom::SensorType type,
+ mojo::ScopedSharedBufferMapping mapping,
+ PlatformSensorProvider* provider);
+
+ using ConfigMap = std::map<Client*, std::list<PlatformSensorConfiguration>>;
+
+ virtual bool UpdateSensorInternal(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>;
+
+ mojom::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_GENERIC_SENSOR_PLATFORM_SENSOR_H_
« 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