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

Unified Diff: device/sensors/public/interfaces/sensor_struct_traits.cc

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/public/interfaces/sensor_struct_traits.cc
diff --git a/device/sensors/public/interfaces/sensor_struct_traits.cc b/device/sensors/public/interfaces/sensor_struct_traits.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2265df8b611b3794d063b30d8e14666dd30dd803
--- /dev/null
+++ b/device/sensors/public/interfaces/sensor_struct_traits.cc
@@ -0,0 +1,117 @@
+// 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.
+
+#include "device/sensors/public/interfaces/sensor_struct_traits.h"
+
+#define CHECK_ENUM(VALUE1, VALUE2) \
+ static_assert(static_cast<int32_t>(VALUE1) == static_cast<int32_t>(VALUE2), \
+ "Enum value mismatch.")
+
+namespace mojo {
+
+// static
+bool StructTraits<device::mojom::SensorConfiguration,
+ device::PlatformSensorConfiguration>::
+ Read(device::mojom::SensorConfigurationDataView data,
+ device::PlatformSensorConfiguration* out) {
+ out->set_frequency(data.frequency());
+ return true;
+}
+
+// static asserts to verify that enums are in sync
+CHECK_ENUM(device::ReportingMode::ON_CHANGE,
+ device::mojom::ReportingMode::ON_CHANGE);
+CHECK_ENUM(device::ReportingMode::CONTINUOUS,
+ device::mojom::ReportingMode::CONTINUOUS);
+
+device::mojom::ReportingMode
+EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::ToMojom(
+ device::ReportingMode reporting_mode) {
+ switch (reporting_mode) {
+ case device::ReportingMode::ON_CHANGE:
+ return device::mojom::ReportingMode::ON_CHANGE;
+ case device::ReportingMode::CONTINUOUS:
+ return device::mojom::ReportingMode::CONTINUOUS;
+ }
+
+ NOTREACHED();
+ return device::mojom::ReportingMode::ON_CHANGE;
+}
+
+// static
+bool EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::FromMojom(
+ device::mojom::ReportingMode input,
+ device::ReportingMode* out) {
+ switch (input) {
+ case device::mojom::ReportingMode::ON_CHANGE:
+ *out = device::ReportingMode::ON_CHANGE;
+ return true;
+ case device::mojom::ReportingMode::CONTINUOUS:
+ *out = device::ReportingMode::CONTINUOUS;
+ return true;
+ }
+
+ NOTREACHED();
+ return false;
+}
+
+// static asserts to verify that enums are in sync
+CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST);
+CHECK_ENUM(device::SensorType::AMBIENT_LIGHT,
+ device::mojom::SensorType::AMBIENT_LIGHT);
+CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY);
+CHECK_ENUM(device::SensorType::ACCELEROMETER,
+ device::mojom::SensorType::ACCELEROMETER);
+CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE);
+CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE);
+CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST);
+
+// static
+device::mojom::SensorType
+EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom(
+ device::SensorType sensor_type) {
+ switch (sensor_type) {
+ case device::SensorType::AMBIENT_LIGHT:
+ return device::mojom::SensorType::AMBIENT_LIGHT;
+ case device::SensorType::PROXIMITY:
+ return device::mojom::SensorType::PROXIMITY;
+ case device::SensorType::ACCELEROMETER:
+ return device::mojom::SensorType::ACCELEROMETER;
+ case device::SensorType::GYROSCOPE:
+ return device::mojom::SensorType::GYROSCOPE;
+ case device::SensorType::PRESSURE:
+ return device::mojom::SensorType::PRESSURE;
+ }
+
+ NOTREACHED();
+ return device::mojom::SensorType::AMBIENT_LIGHT;
+}
+
+// static
+bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom(
+ device::mojom::SensorType input,
+ device::SensorType* out) {
+ switch (input) {
+ case device::mojom::SensorType::AMBIENT_LIGHT:
+ *out = device::SensorType::AMBIENT_LIGHT;
+ return true;
+ case device::mojom::SensorType::PROXIMITY:
+ *out = device::SensorType::PROXIMITY;
+ return true;
+ case device::mojom::SensorType::ACCELEROMETER:
+ *out = device::SensorType::ACCELEROMETER;
+ return true;
+ case device::mojom::SensorType::GYROSCOPE:
+ *out = device::SensorType::GYROSCOPE;
+ return true;
+ case device::mojom::SensorType::PRESSURE:
+ *out = device::SensorType::PRESSURE;
+ return true;
+ }
+
+ NOTREACHED();
+ return false;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698