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

Side by Side 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: Fixes for Tim's comments. 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 unified diff | Download patch
OLDNEW
(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 double StructTraits<device::mojom::SensorConfiguration,
15 device::PlatformSensorConfiguration>::
16 frequency(const device::PlatformSensorConfiguration& input) {
17 return input.GetFrequency();
dcheng 2016/07/06 02:07:29 It's OK to inline this one, since it's short and s
shalamov 2016/07/06 07:15:10 Done.
18 }
19
20 // static
21 bool StructTraits<device::mojom::SensorConfiguration,
22 device::PlatformSensorConfiguration>::
23 Read(device::mojom::SensorConfigurationDataView data,
24 device::PlatformSensorConfiguration* out) {
25 out->SetFrequency(data.frequency());
26 return true;
27 }
28
29 // static asserts to verify that enums are in sync
30 CHECK_ENUM(device::ReportingMode::ON_CHANGE,
31 device::mojom::ReportingMode::ON_CHANGE);
32 CHECK_ENUM(device::ReportingMode::CONTINUOUS,
33 device::mojom::ReportingMode::CONTINUOUS);
34
35 device::mojom::ReportingMode
36 EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::ToMojom(
37 device::ReportingMode reporting_mode) {
38 switch (reporting_mode) {
39 case device::ReportingMode::ON_CHANGE:
40 return device::mojom::ReportingMode::ON_CHANGE;
41 case device::ReportingMode::CONTINUOUS:
42 return device::mojom::ReportingMode::CONTINUOUS;
43 }
44
45 NOTREACHED();
46 return device::mojom::ReportingMode::ON_CHANGE;
47 }
48
49 // static
50 bool EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::FromMojom(
51 device::mojom::ReportingMode input,
52 device::ReportingMode* out) {
53 switch (input) {
54 case device::mojom::ReportingMode::ON_CHANGE:
55 *out = device::ReportingMode::ON_CHANGE;
56 return true;
57 case device::mojom::ReportingMode::CONTINUOUS:
58 *out = device::ReportingMode::CONTINUOUS;
59 return true;
60 }
61
62 NOTREACHED();
63 return false;
64 }
65
66 // static asserts to verify that enums are in sync
67 CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST);
68 CHECK_ENUM(device::SensorType::AMBIENT_LIGHT,
69 device::mojom::SensorType::AMBIENT_LIGHT);
70 CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY);
71 CHECK_ENUM(device::SensorType::ACCELEROMETER,
72 device::mojom::SensorType::ACCELEROMETER);
73 CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE);
74 CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE);
75 CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST);
76
77 // static
78 device::mojom::SensorType
79 EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom(
80 device::SensorType sensor_type) {
81 switch (sensor_type) {
82 case device::SensorType::AMBIENT_LIGHT:
83 return device::mojom::SensorType::AMBIENT_LIGHT;
84 case device::SensorType::PROXIMITY:
85 return device::mojom::SensorType::PROXIMITY;
86 case device::SensorType::ACCELEROMETER:
87 return device::mojom::SensorType::ACCELEROMETER;
88 case device::SensorType::GYROSCOPE:
89 return device::mojom::SensorType::GYROSCOPE;
90 case device::SensorType::PRESSURE:
91 return device::mojom::SensorType::PRESSURE;
92 }
93
94 NOTREACHED();
95 return device::mojom::SensorType::AMBIENT_LIGHT;
96 }
97
98 // static
99 bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom(
100 device::mojom::SensorType input,
101 device::SensorType* out) {
102 switch (input) {
103 case device::mojom::SensorType::AMBIENT_LIGHT:
104 *out = device::SensorType::AMBIENT_LIGHT;
105 return true;
106 case device::mojom::SensorType::PROXIMITY:
107 *out = device::SensorType::PROXIMITY;
108 return true;
109 case device::mojom::SensorType::ACCELEROMETER:
110 *out = device::SensorType::ACCELEROMETER;
111 return true;
112 case device::mojom::SensorType::GYROSCOPE:
113 *out = device::SensorType::GYROSCOPE;
114 return true;
115 case device::mojom::SensorType::PRESSURE:
116 *out = device::SensorType::PRESSURE;
117 return true;
118 }
119
120 NOTREACHED();
121 return false;
122 }
123
124 } // namespace mojo
OLDNEW
« no previous file with comments | « device/sensors/public/interfaces/sensor_struct_traits.h ('k') | device/sensors/public/interfaces/typemaps.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698