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

Side by Side Diff: device/sensors/public/interfaces/sensor_struct_traits.cc

Issue 2144623003: [sensors] Introduce Generic Sensor API interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheng 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 bool StructTraits<device::mojom::SensorConfiguration,
15 device::PlatformSensorConfiguration>::
16 Read(device::mojom::SensorConfigurationDataView data,
17 device::PlatformSensorConfiguration* out) {
18 // Maximum allowed frequency is capped to 60Hz.
19 if (data.frequency() > 60.0 || data.frequency() <= 0.0) {
20 return false;
21 }
22
23 out->set_frequency(data.frequency());
24 return true;
25 }
26
27 // static asserts to verify that enums are in sync
28 CHECK_ENUM(device::ReportingMode::ON_CHANGE,
29 device::mojom::ReportingMode::ON_CHANGE);
30 CHECK_ENUM(device::ReportingMode::CONTINUOUS,
31 device::mojom::ReportingMode::CONTINUOUS);
32
33 device::mojom::ReportingMode
34 EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::ToMojom(
35 device::ReportingMode reporting_mode) {
36 switch (reporting_mode) {
37 case device::ReportingMode::ON_CHANGE:
38 return device::mojom::ReportingMode::ON_CHANGE;
39 case device::ReportingMode::CONTINUOUS:
40 return device::mojom::ReportingMode::CONTINUOUS;
41 }
42
43 NOTREACHED();
44 return device::mojom::ReportingMode::ON_CHANGE;
45 }
46
47 // static
48 bool EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::FromMojom(
49 device::mojom::ReportingMode input,
50 device::ReportingMode* out) {
51 switch (input) {
52 case device::mojom::ReportingMode::ON_CHANGE:
53 *out = device::ReportingMode::ON_CHANGE;
54 return true;
55 case device::mojom::ReportingMode::CONTINUOUS:
56 *out = device::ReportingMode::CONTINUOUS;
57 return true;
58 }
59
60 NOTREACHED();
61 return false;
62 }
63
64 // static asserts to verify that enums are in sync
65 CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST);
66 CHECK_ENUM(device::SensorType::AMBIENT_LIGHT,
67 device::mojom::SensorType::AMBIENT_LIGHT);
68 CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY);
69 CHECK_ENUM(device::SensorType::ACCELEROMETER,
70 device::mojom::SensorType::ACCELEROMETER);
71 CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE);
72 CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE);
73 CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST);
74
75 // static
76 device::mojom::SensorType
77 EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom(
78 device::SensorType sensor_type) {
79 switch (sensor_type) {
80 case device::SensorType::AMBIENT_LIGHT:
81 return device::mojom::SensorType::AMBIENT_LIGHT;
82 case device::SensorType::PROXIMITY:
83 return device::mojom::SensorType::PROXIMITY;
84 case device::SensorType::ACCELEROMETER:
85 return device::mojom::SensorType::ACCELEROMETER;
86 case device::SensorType::GYROSCOPE:
87 return device::mojom::SensorType::GYROSCOPE;
88 case device::SensorType::PRESSURE:
89 return device::mojom::SensorType::PRESSURE;
90 }
91
92 NOTREACHED();
93 return device::mojom::SensorType::AMBIENT_LIGHT;
94 }
95
96 // static
97 bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom(
98 device::mojom::SensorType input,
99 device::SensorType* out) {
100 switch (input) {
101 case device::mojom::SensorType::AMBIENT_LIGHT:
102 *out = device::SensorType::AMBIENT_LIGHT;
103 return true;
104 case device::mojom::SensorType::PROXIMITY:
105 *out = device::SensorType::PROXIMITY;
106 return true;
107 case device::mojom::SensorType::ACCELEROMETER:
108 *out = device::SensorType::ACCELEROMETER;
109 return true;
110 case device::mojom::SensorType::GYROSCOPE:
111 *out = device::SensorType::GYROSCOPE;
112 return true;
113 case device::mojom::SensorType::PRESSURE:
114 *out = device::SensorType::PRESSURE;
115 return true;
116 }
117
118 NOTREACHED();
119 return false;
120 }
121
122 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698