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 DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ |
6 #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ | 6 #define DEVICE_GENERIC_SENSOR_PUBLIC_CPP_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/generic_sensor_export.h" |
9 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" | 10 #include "device/generic_sensor/public/interfaces/sensor.mojom.h" |
10 | 11 |
11 namespace device { | 12 namespace device { |
12 | 13 |
13 // This class is guarantied to have a fixed size of 64 bits on every platform. | 14 // This class is guarantied to have a fixed size of 64 bits on every platform. |
14 // It is introduce to simplify sensors shared buffer memory calculation. | 15 // It is introduce to simplify sensors shared buffer memory calculation. |
15 template <typename Data> | 16 template <typename Data> |
16 class SensorReadingField { | 17 class SensorReadingField { |
17 public: | 18 public: |
18 static_assert(sizeof(Data) <= sizeof(int64_t), | 19 static_assert(sizeof(Data) <= sizeof(int64_t), |
(...skipping 13 matching lines...) Expand all Loading... |
32 union Storage { | 33 union Storage { |
33 int64_t unused; | 34 int64_t unused; |
34 Data value; | 35 Data value; |
35 Storage() { new (&value) Data(); } | 36 Storage() { new (&value) Data(); } |
36 ~Storage() { value.~Data(); } | 37 ~Storage() { value.~Data(); } |
37 }; | 38 }; |
38 Storage storage_; | 39 Storage storage_; |
39 }; | 40 }; |
40 | 41 |
41 // This structure represents sensor reading data: timestamp and 3 values. | 42 // This structure represents sensor reading data: timestamp and 3 values. |
42 struct SensorReading { | 43 struct DEVICE_GENERIC_SENSOR_EXPORT SensorReading { |
43 SensorReading(); | 44 SensorReading(); |
44 ~SensorReading(); | 45 ~SensorReading(); |
45 SensorReading(const SensorReading& other); | 46 SensorReading(const SensorReading& other); |
46 SensorReadingField<double> timestamp; | 47 SensorReadingField<double> timestamp; |
47 SensorReadingField<double> values[3]; | 48 SensorReadingField<double> values[3]; |
48 }; | 49 }; |
49 | 50 |
50 // This structure represents sensor reading buffer: sensor reading and seqlock | 51 // This structure represents sensor reading buffer: sensor reading and seqlock |
51 // for synchronization. | 52 // for synchronization. |
52 struct SensorReadingSharedBuffer { | 53 struct SensorReadingSharedBuffer { |
53 SensorReadingSharedBuffer(); | 54 SensorReadingSharedBuffer(); |
54 ~SensorReadingSharedBuffer(); | 55 ~SensorReadingSharedBuffer(); |
55 SensorReadingField<OneWriterSeqLock> seqlock; | 56 SensorReadingField<OneWriterSeqLock> seqlock; |
56 SensorReading reading; | 57 SensorReading reading; |
57 | 58 |
58 // Gets the shared reading buffer offset for the given sensor type. | 59 // Gets the shared reading buffer offset for the given sensor type. |
59 static uint64_t GetOffset(mojom::SensorType type); | 60 static uint64_t GetOffset(mojom::SensorType type); |
60 }; | 61 }; |
61 | 62 |
62 } // namespace device | 63 } // namespace device |
63 | 64 |
64 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ | 65 #endif // DEVICE_GENERIC_SENSOR_PUBLIC_CPP_SENSOR_READING_H_ |
OLD | NEW |