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

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: Moved frequency check to StructTraits 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 NOTREACHED();
dcheng 2016/07/14 09:24:10 Nit: this shouldn't be NOTREACHED(), as it's somet
21 return false;
22 }
23
24 out->set_frequency(data.frequency());
25 return true;
26 }
27
28 // static asserts to verify that enums are in sync
29 CHECK_ENUM(device::ReportingMode::ON_CHANGE,
30 device::mojom::ReportingMode::ON_CHANGE);
31 CHECK_ENUM(device::ReportingMode::CONTINUOUS,
32 device::mojom::ReportingMode::CONTINUOUS);
33
34 device::mojom::ReportingMode
35 EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::ToMojom(
36 device::ReportingMode reporting_mode) {
37 switch (reporting_mode) {
38 case device::ReportingMode::ON_CHANGE:
39 return device::mojom::ReportingMode::ON_CHANGE;
40 case device::ReportingMode::CONTINUOUS:
41 return device::mojom::ReportingMode::CONTINUOUS;
42 }
43
44 NOTREACHED();
45 return device::mojom::ReportingMode::ON_CHANGE;
46 }
47
48 // static
49 bool EnumTraits<device::mojom::ReportingMode, device::ReportingMode>::FromMojom(
50 device::mojom::ReportingMode input,
51 device::ReportingMode* out) {
52 switch (input) {
53 case device::mojom::ReportingMode::ON_CHANGE:
54 *out = device::ReportingMode::ON_CHANGE;
55 return true;
56 case device::mojom::ReportingMode::CONTINUOUS:
57 *out = device::ReportingMode::CONTINUOUS;
58 return true;
59 }
60
61 NOTREACHED();
62 return false;
63 }
64
65 // static asserts to verify that enums are in sync
66 CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST);
67 CHECK_ENUM(device::SensorType::AMBIENT_LIGHT,
68 device::mojom::SensorType::AMBIENT_LIGHT);
69 CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY);
70 CHECK_ENUM(device::SensorType::ACCELEROMETER,
71 device::mojom::SensorType::ACCELEROMETER);
72 CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE);
73 CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE);
74 CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST);
75
76 // static
77 device::mojom::SensorType
78 EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom(
79 device::SensorType sensor_type) {
80 switch (sensor_type) {
81 case device::SensorType::AMBIENT_LIGHT:
82 return device::mojom::SensorType::AMBIENT_LIGHT;
83 case device::SensorType::PROXIMITY:
84 return device::mojom::SensorType::PROXIMITY;
85 case device::SensorType::ACCELEROMETER:
86 return device::mojom::SensorType::ACCELEROMETER;
87 case device::SensorType::GYROSCOPE:
88 return device::mojom::SensorType::GYROSCOPE;
89 case device::SensorType::PRESSURE:
90 return device::mojom::SensorType::PRESSURE;
91 }
92
93 NOTREACHED();
94 return device::mojom::SensorType::AMBIENT_LIGHT;
95 }
96
97 // static
98 bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom(
99 device::mojom::SensorType input,
100 device::SensorType* out) {
101 switch (input) {
102 case device::mojom::SensorType::AMBIENT_LIGHT:
103 *out = device::SensorType::AMBIENT_LIGHT;
104 return true;
105 case device::mojom::SensorType::PROXIMITY:
106 *out = device::SensorType::PROXIMITY;
107 return true;
108 case device::mojom::SensorType::ACCELEROMETER:
109 *out = device::SensorType::ACCELEROMETER;
110 return true;
111 case device::mojom::SensorType::GYROSCOPE:
112 *out = device::SensorType::GYROSCOPE;
113 return true;
114 case device::mojom::SensorType::PRESSURE:
115 *out = device::SensorType::PRESSURE;
116 return true;
117 }
118
119 NOTREACHED();
120 return false;
121 }
122
123 } // 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