Index: device/sensors/sensor_type_converters.cc |
diff --git a/device/sensors/sensor_type_converters.cc b/device/sensors/sensor_type_converters.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c51b2a2b4ccd9c212d4f4e346ebfd79ba9446756 |
--- /dev/null |
+++ b/device/sensors/sensor_type_converters.cc |
@@ -0,0 +1,54 @@ |
+// 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/sensor_type_converters.h" |
+ |
+#include "device/sensors/platform_sensor.h" |
+#include "device/sensors/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::mojom::SensorConfigurationPtr>:: |
+ Convert(const device::mojom::SensorConfigurationPtr& sensor_configuration) { |
+ return device::PlatformSensorConfiguration(sensor_configuration->frequency); |
dcheng
2016/07/01 09:17:24
Instead of adding new type converters, please use
shalamov
2016/07/01 14:22:47
Done.
|
+} |
+ |
+// static |
+device::SensorType |
+TypeConverter<device::SensorType, device::mojom::SensorType>::Convert( |
+ device::mojom::SensorType sensor_type) { |
+ 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::LINEAR_ACCELERATION, |
+ device::mojom::SensorType::LINEAR_ACCELERATION); |
+ 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); |
+ |
+ return static_cast<device::SensorType>(sensor_type); |
+} |
+ |
+// static |
+device::mojom::ReportingMode |
+TypeConverter<device::mojom::ReportingMode, device::ReportingMode>::Convert( |
+ device::ReportingMode reporting_mode) { |
+ CHECK_ENUM(device::ReportingMode::ON_CHANGE, |
+ device::mojom::ReportingMode::ON_CHANGE); |
+ CHECK_ENUM(device::ReportingMode::CONTINUOUS, |
+ device::mojom::ReportingMode::CONTINUOUS); |
+ return static_cast<device::mojom::ReportingMode>(reporting_mode); |
+} |
+ |
+} // namespace mojo |