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

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: Rebase + fixes for dcheng'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();
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());
dcheng 2016/07/06 02:07:29 Is there an upper limit on frequency that to enfor
shalamov 2016/07/06 07:15:10 Configuration is validated by concrete sensor impl
dcheng 2016/07/06 09:12:04 I think we can still provide an upper limit to cla
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 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 return false;
61 }
62
63 // static asserts to verify that enums are in sync
64 CHECK_ENUM(device::SensorType::FIRST, device::mojom::SensorType::FIRST);
65 CHECK_ENUM(device::SensorType::AMBIENT_LIGHT,
66 device::mojom::SensorType::AMBIENT_LIGHT);
67 CHECK_ENUM(device::SensorType::PROXIMITY, device::mojom::SensorType::PROXIMITY);
68 CHECK_ENUM(device::SensorType::ACCELEROMETER,
69 device::mojom::SensorType::ACCELEROMETER);
70 CHECK_ENUM(device::SensorType::GYROSCOPE, device::mojom::SensorType::GYROSCOPE);
71 CHECK_ENUM(device::SensorType::PRESSURE, device::mojom::SensorType::PRESSURE);
72 CHECK_ENUM(device::SensorType::LAST, device::mojom::SensorType::LAST);
73
74 // static
75 device::mojom::SensorType
76 EnumTraits<device::mojom::SensorType, device::SensorType>::ToMojom(
77 device::SensorType sensor_type) {
78 switch (sensor_type) {
79 case device::SensorType::AMBIENT_LIGHT:
80 return device::mojom::SensorType::AMBIENT_LIGHT;
81 case device::SensorType::PROXIMITY:
82 return device::mojom::SensorType::PROXIMITY;
83 case device::SensorType::ACCELEROMETER:
84 return device::mojom::SensorType::ACCELEROMETER;
85 case device::SensorType::GYROSCOPE:
86 return device::mojom::SensorType::GYROSCOPE;
87 case device::SensorType::PRESSURE:
88 return device::mojom::SensorType::PRESSURE;
89 }
90 NOTREACHED();
91 return device::mojom::SensorType::AMBIENT_LIGHT;
92 }
93
94 // static
95 bool EnumTraits<device::mojom::SensorType, device::SensorType>::FromMojom(
96 device::mojom::SensorType input,
97 device::SensorType* out) {
98 switch (input) {
99 case device::mojom::SensorType::AMBIENT_LIGHT:
100 *out = device::SensorType::AMBIENT_LIGHT;
101 return true;
102 case device::mojom::SensorType::PROXIMITY:
103 *out = device::SensorType::PROXIMITY;
104 return true;
105 case device::mojom::SensorType::ACCELEROMETER:
106 *out = device::SensorType::ACCELEROMETER;
107 return true;
108 case device::mojom::SensorType::GYROSCOPE:
109 *out = device::SensorType::GYROSCOPE;
110 return true;
111 case device::mojom::SensorType::PRESSURE:
112 *out = device::SensorType::PRESSURE;
113 return true;
114 }
timvolodine 2016/07/04 11:32:46 NOTREACHED?
shalamov 2016/07/04 12:11:46 Thanks, missed that.
115 return false;
116 }
117
118 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698