| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ | 5 #ifndef SERVICES_DEVICE_PUBLIC_CPP_GENERIC_SENSOR_SENSOR_READING_H_ |
| 6 #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ | 6 #define SERVICES_DEVICE_PUBLIC_CPP_GENERIC_SENSOR_SENSOR_READING_H_ |
| 7 | 7 |
| 8 #include "device/base/synchronization/one_writer_seqlock.h" | 8 #include "device/base/synchronization/one_writer_seqlock.h" |
| 9 #include "device/generic_sensor/public/cpp/generic_sensor_public_export.h" | 9 #include "services/device/public/interfaces/sensor.mojom.h" |
| 10 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" | |
| 11 | 10 |
| 12 namespace device { | 11 namespace device { |
| 13 | 12 |
| 14 // This class is guarantied to have a fixed size of 64 bits on every platform. | 13 // This class is guarantied to have a fixed size of 64 bits on every platform. |
| 15 // It is introduce to simplify sensors shared buffer memory calculation. | 14 // It is introduce to simplify sensors shared buffer memory calculation. |
| 16 template <typename Data> | 15 template <typename Data> |
| 17 class SensorReadingField { | 16 class SensorReadingField { |
| 18 public: | 17 public: |
| 19 static_assert(sizeof(Data) <= sizeof(int64_t), | 18 static_assert(sizeof(Data) <= sizeof(int64_t), |
| 20 "The field size must be <= 64 bits."); | 19 "The field size must be <= 64 bits."); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 33 union Storage { | 32 union Storage { |
| 34 int64_t unused; | 33 int64_t unused; |
| 35 Data value; | 34 Data value; |
| 36 Storage() { new (&value) Data(); } | 35 Storage() { new (&value) Data(); } |
| 37 ~Storage() { value.~Data(); } | 36 ~Storage() { value.~Data(); } |
| 38 }; | 37 }; |
| 39 Storage storage_; | 38 Storage storage_; |
| 40 }; | 39 }; |
| 41 | 40 |
| 42 // This structure represents sensor reading data: timestamp and 4 values. | 41 // This structure represents sensor reading data: timestamp and 4 values. |
| 43 struct DEVICE_GENERIC_SENSOR_PUBLIC_EXPORT SensorReading { | 42 struct SensorReading { |
| 44 SensorReading(); | 43 SensorReading(); |
| 45 ~SensorReading(); | 44 ~SensorReading(); |
| 46 SensorReading(const SensorReading& other); | 45 SensorReading(const SensorReading& other); |
| 47 SensorReadingField<double> timestamp; | 46 SensorReadingField<double> timestamp; |
| 48 constexpr static int kValuesCount = 4; | 47 constexpr static int kValuesCount = 4; |
| 49 // AMBIENT_LIGHT: | 48 // AMBIENT_LIGHT: |
| 50 // values[0]: ambient light level in SI lux units. | 49 // values[0]: ambient light level in SI lux units. |
| 51 // | 50 // |
| 52 // PROXIMITY: | 51 // PROXIMITY: |
| 53 // values[0]: proximity sensor distance measured in centimeters. | 52 // values[0]: proximity sensor distance measured in centimeters. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // device in 3D space. | 93 // device in 3D space. |
| 95 // values[2]: z value of a quaternion representing the orientation of the | 94 // values[2]: z value of a quaternion representing the orientation of the |
| 96 // device in 3D space. | 95 // device in 3D space. |
| 97 // values[3]: w value of a quaternion representing the orientation of the | 96 // values[3]: w value of a quaternion representing the orientation of the |
| 98 // device in 3D space. | 97 // device in 3D space. |
| 99 SensorReadingField<double> values[kValuesCount]; | 98 SensorReadingField<double> values[kValuesCount]; |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 // This structure represents sensor reading buffer: sensor reading and seqlock | 101 // This structure represents sensor reading buffer: sensor reading and seqlock |
| 103 // for synchronization. | 102 // for synchronization. |
| 104 struct DEVICE_GENERIC_SENSOR_PUBLIC_EXPORT SensorReadingSharedBuffer { | 103 struct SensorReadingSharedBuffer { |
| 105 SensorReadingSharedBuffer(); | 104 SensorReadingSharedBuffer(); |
| 106 ~SensorReadingSharedBuffer(); | 105 ~SensorReadingSharedBuffer(); |
| 107 SensorReadingField<OneWriterSeqLock> seqlock; | 106 SensorReadingField<OneWriterSeqLock> seqlock; |
| 108 SensorReading reading; | 107 SensorReading reading; |
| 109 | 108 |
| 110 // Gets the shared reading buffer offset for the given sensor type. | 109 // Gets the shared reading buffer offset for the given sensor type. |
| 111 static uint64_t GetOffset(mojom::SensorType type); | 110 static uint64_t GetOffset(mojom::SensorType type); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 } // namespace device | 113 } // namespace device |
| 115 | 114 |
| 116 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ | 115 #endif // SERVICES_DEVICE_PUBLIC_CPP_GENERIC_SENSOR_SENSOR_READING_H_ |
| OLD | NEW |