Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_iio.h |
| diff --git a/device/generic_sensor/platform_sensor_iio.h b/device/generic_sensor/platform_sensor_iio.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..334e8350c91be7cdbe241b45bfaf75ce478415f2 |
| --- /dev/null |
| +++ b/device/generic_sensor/platform_sensor_iio.h |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |
| +#define DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |
| + |
| +#include "device/generic_sensor/platform_sensor.h" |
| + |
| +#include "base/threading/thread.h" |
| +#include "base/timer/timer.h" |
|
shalamov
2016/10/19 16:37:11
forward declare
maksims (do not use this acc)
2016/10/20 09:50:36
Done.
|
| +#include "device/generic_sensor/iio/platform_sensor_utils_iio.h" |
| +#include "device/generic_sensor/iio/sensor_data_iio.h" |
|
shalamov
2016/10/19 16:37:11
ditto
maksims (do not use this acc)
2016/10/20 09:50:36
Done.
|
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +} |
| + |
| +namespace device { |
| + |
| +class PlatformSensorIio : public PlatformSensor { |
| + public: |
| + PlatformSensorIio(mojom::SensorType type, |
| + mojo::ScopedSharedBufferMapping mapping, |
| + PlatformSensorProvider* provider, |
| + const SensorDataIio& data, |
| + std::unique_ptr<base::Thread> polling_thread, |
| + std::unique_ptr<SensorReader> sensor_reader); |
| + |
| + // Thread safe. |
| + mojom::ReportingMode GetReportingMode() override; |
| + |
| + protected: |
| + ~PlatformSensorIio() override; |
| + bool StartSensor(const PlatformSensorConfiguration& configuration) override; |
| + void StopSensor() override; |
| + bool CheckSensorConfiguration( |
| + const PlatformSensorConfiguration& configuration) override; |
| + PlatformSensorConfiguration GetDefaultConfiguration() override; |
| + |
| + private: |
| + void BeginPoll(const PlatformSensorConfiguration& configuration); |
| + void StopPoll(); |
| + |
| + // Triggers |sensor_reader_| to read new sensor data. |
| + // If new data is read, UpdateSensorReading() is called. |
| + void PollForReadingData(); |
| + |
| + // Owned timer to be deleted on a polling thread. |
| + base::RepeatingTimer* timer_; |
| + |
| + const PlatformSensorConfiguration default_configuration_; |
| + const mojom::ReportingMode reporting_mode_; |
| + |
| + // A sensor reader that reads values from sensor files |
| + // and stores them to a SensorReading structure. |
| + std::unique_ptr<SensorReader> sensor_reader_; |
| + |
| + // A thread that is used to poll sensor data. |
| + std::unique_ptr<base::Thread> polling_thread_; |
| + scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner_; |
| + |
| + // Stores previously read values that are used to |
| + // determine whether the recent values are changed |
| + // and IPC can be notified that updates are available. |
| + SensorReading old_values_; |
| + |
| + base::WeakPtrFactory<PlatformSensorIio> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PlatformSensorIio); |
| +}; |
| + |
| +} // namespace device |
| + |
| +#endif // DEVICE_GENERIC_SENSOR_PLATFORM_SENSOR_IIO_H_ |