OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "device/sensors/public/interfaces/sensor_struct_traits.h" |
| 6 |
| 7 #define CHECK_ENUM(VALUE1, VALUE2) \ |
| 8 static_assert(static_cast<int32_t>(VALUE1) == static_cast<int32_t>(VALUE2), \ |
| 9 "Enum value mismatch.") |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 // static |
| 14 bool StructTraits<device::mojom::SensorConfiguration, |
| 15 device::PlatformSensorConfiguration>:: |
| 16 Read(device::mojom::SensorConfigurationDataView data, |
| 17 device::PlatformSensorConfiguration* out) { |
| 18 out->set_frequency(data.frequency()); |
| 19 return true; |
| 20 } |
| 21 |
| 22 // static asserts to verify that enums are in sync |
| 23 CHECK_ENUM(device::ReportingMode::ON_CHANGE, |
| 24 device::mojom::ReportingMode::ON_CHANGE); |
| 25 CHECK_ENUM(device::ReportingMode::CONTINUOUS, |
| 26 device::mojom::ReportingMode::CONTINUOUS); |
| 27 |
| 28 device::mojom::ReportingMode |
| 29 EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::ToMojom( |
| 30 device::ReportingMode reporting_mode) { |
| 31 switch (reporting_mode) { |
| 32 case device::ReportingMode::ON_CHANGE: |
| 33 return device::mojom::ReportingMode::ON_CHANGE; |
| 34 case device::ReportingMode::CONTINUOUS: |
| 35 return device::mojom::ReportingMode::CONTINUOUS; |
| 36 } |
| 37 |
| 38 NOTREACHED(); |
| 39 return device::mojom::ReportingMode::ON_CHANGE; |
| 40 } |
| 41 |
| 42 // static |
| 43 bool EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::FromMojom( |
| 44 device::mojom::ReportingMode input, |
| 45 device::ReportingMode* out) { |
| 46 switch (input) { |
| 47 case device::mojom::ReportingMode::ON_CHANGE: |
| 48 *out = device::ReportingMode::ON_CHANGE; |
| 49 return true; |
| 50 case device::mojom::ReportingMode::CONTINUOUS: |
| 51 *out = device::ReportingMode::CONTINUOUS; |
| 52 return true; |
| 53 } |
| 54 |
| 55 NOTREACHED(); |
| 56 return false; |
| 57 } |
| 58 |
| 59 // static asserts to verify that enums are in sync |
| 60 CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST); |
| 61 CHECK_ENUM(device::SensorType::AMBIENT_LIGHT, |
| 62 device::mojom::SensorType::AMBIENT_LIGHT); |
| 63 CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY); |
| 64 CHECK_ENUM(device::SensorType::ACCELEROMETER, |
| 65 device::mojom::SensorType::ACCELEROMETER); |
| 66 CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE); |
| 67 CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE); |
| 68 CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST); |
| 69 |
| 70 // static |
| 71 device::mojom::SensorType |
| 72 EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom( |
| 73 device::SensorType sensor_type) { |
| 74 switch (sensor_type) { |
| 75 case device::SensorType::AMBIENT_LIGHT: |
| 76 return device::mojom::SensorType::AMBIENT_LIGHT; |
| 77 case device::SensorType::PROXIMITY: |
| 78 return device::mojom::SensorType::PROXIMITY; |
| 79 case device::SensorType::ACCELEROMETER: |
| 80 return device::mojom::SensorType::ACCELEROMETER; |
| 81 case device::SensorType::GYROSCOPE: |
| 82 return device::mojom::SensorType::GYROSCOPE; |
| 83 case device::SensorType::PRESSURE: |
| 84 return device::mojom::SensorType::PRESSURE; |
| 85 } |
| 86 |
| 87 NOTREACHED(); |
| 88 return device::mojom::SensorType::AMBIENT_LIGHT; |
| 89 } |
| 90 |
| 91 // static |
| 92 bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom( |
| 93 device::mojom::SensorType input, |
| 94 device::SensorType* out) { |
| 95 switch (input) { |
| 96 case device::mojom::SensorType::AMBIENT_LIGHT: |
| 97 *out = device::SensorType::AMBIENT_LIGHT; |
| 98 return true; |
| 99 case device::mojom::SensorType::PROXIMITY: |
| 100 *out = device::SensorType::PROXIMITY; |
| 101 return true; |
| 102 case device::mojom::SensorType::ACCELEROMETER: |
| 103 *out = device::SensorType::ACCELEROMETER; |
| 104 return true; |
| 105 case device::mojom::SensorType::GYROSCOPE: |
| 106 *out = device::SensorType::GYROSCOPE; |
| 107 return true; |
| 108 case device::mojom::SensorType::PRESSURE: |
| 109 *out = device::SensorType::PRESSURE; |
| 110 return true; |
| 111 } |
| 112 |
| 113 NOTREACHED(); |
| 114 return false; |
| 115 } |
| 116 |
| 117 } // namespace mojo |
OLD | NEW |