Index: device/sensors/mojo/sensor_type_converters.cc |
diff --git a/device/sensors/mojo/sensor_type_converters.cc b/device/sensors/mojo/sensor_type_converters.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1ada4e67756331127ff54988151f9ca5667d1619 |
--- /dev/null |
+++ b/device/sensors/mojo/sensor_type_converters.cc |
@@ -0,0 +1,56 @@ |
+// 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/mojo/sensor_type_converters.h" |
+ |
+#include "device/sensors/platform/platform_sensor.h" |
+#include "device/sensors/platform/platform_sensor_configuration.h" |
+ |
+#define CHECK_ENUM(VALUE1, VALUE2) \ |
+ static_assert(static_cast<int32_t>(VALUE1) == static_cast<int32_t>(VALUE2), \ |
+ "Enum value mismatch.") |
+ |
+namespace mojo { |
+ |
+// static |
+device::PlatformSensorConfiguration |
+TypeConverter<device::PlatformSensorConfiguration, |
+ device::sensors::SensorConfigurationPtr>:: |
+ Convert( |
+ const device::sensors::SensorConfigurationPtr& sensor_configuration) { |
+ return device::PlatformSensorConfiguration(sensor_configuration->frequency); |
+} |
+ |
+// static |
+device::SensorType |
+TypeConverter<device::SensorType, device::sensors::SensorType>::Convert( |
+ device::sensors::SensorType sensor_type) { |
+ CHECK_ENUM(device::SensorType::FIRST, device::sensors::SensorType::FIRST); |
+ CHECK_ENUM(device::SensorType::AMBIENT_LIGHT, |
+ device::sensors::SensorType::AMBIENT_LIGHT); |
+ CHECK_ENUM(device::SensorType::PROXIMITY, |
+ device::sensors::SensorType::PROXIMITY); |
+ CHECK_ENUM(device::SensorType::LINEAR_ACCELERATION, |
+ device::sensors::SensorType::LINEAR_ACCELERATION); |
+ CHECK_ENUM(device::SensorType::GYROSCOPE, |
+ device::sensors::SensorType::GYROSCOPE); |
+ CHECK_ENUM(device::SensorType::PRESSURE, |
+ device::sensors::SensorType::PRESSURE); |
+ CHECK_ENUM(device::SensorType::LAST, device::sensors::SensorType::LAST); |
+ |
+ return static_cast<device::SensorType>(sensor_type); |
+} |
+ |
+// static |
+device::sensors::ReportingMode |
+TypeConverter<device::sensors::ReportingMode, device::ReportingMode>::Convert( |
+ device::ReportingMode reporting_mode) { |
+ CHECK_ENUM(device::ReportingMode::ON_CHANGE, |
+ device::sensors::ReportingMode::ON_CHANGE); |
+ CHECK_ENUM(device::ReportingMode::CONTINUOUS, |
+ device::sensors::ReportingMode::CONTINUOUS); |
+ return static_cast<device::sensors::ReportingMode>(reporting_mode); |
+} |
+ |
+} // namespace mojo |