Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_iio.cc |
| diff --git a/device/generic_sensor/platform_sensor_iio.cc b/device/generic_sensor/platform_sensor_iio.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c64e2b2c7c47908533593e05f917e811a94b7740 |
| --- /dev/null |
| +++ b/device/generic_sensor/platform_sensor_iio.cc |
| @@ -0,0 +1,64 @@ |
| +// 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. |
| + |
| +#include <device/generic_sensor/platform_sensor_iio.h> |
| +#include "base/message_loop/message_loop.h" |
| + |
| +namespace device { |
| + |
| +PlatformSensorIio::PlatformSensorIio( |
|
Mikhail
2016/10/11 14:46:47
pls add thread checks to methods
Mikhail
2016/10/11 14:46:47
pls add thread check to methods
maksims (do not use this acc)
2016/10/14 12:31:45
Done.
|
| + mojom::SensorType type, |
| + mojo::ScopedSharedBufferMapping mapping, |
| + PlatformSensorProvider* provider, |
| + scoped_refptr<base::SingleThreadTaskRunner> polling_task_runner) |
| + : PlatformSensor(type, std::move(mapping), provider), |
| + polling_thread_task_runner_(polling_task_runner), |
| + timer_(new base::RepeatingTimer()), |
| + weak_factory_(this) {} |
| + |
| +PlatformSensorIio::~PlatformSensorIio() { |
| + polling_thread_task_runner_->DeleteSoon(FROM_HERE, timer_); |
| +} |
| + |
| +bool PlatformSensorIio::StartSensor( |
| + const PlatformSensorConfiguration& configuration) { |
| + return polling_thread_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&PlatformSensorIio::BeginPoll, |
| + weak_factory_.GetWeakPtr(), configuration)); |
| +} |
| + |
| +void PlatformSensorIio::BeginPoll( |
| + const PlatformSensorConfiguration& configuration) { |
| + DCHECK(polling_thread_task_runner_->BelongsToCurrentThread()); |
| + timer_->Start(FROM_HERE, base::TimeDelta::FromMicroseconds( |
| + base::Time::kMicrosecondsPerSecond / |
| + configuration.frequency()), |
| + this, &PlatformSensorIio::UpdateReading); |
| +} |
| + |
| +void PlatformSensorIio::StopSensor() { |
| + polling_thread_task_runner_->PostTask( |
| + FROM_HERE, base::Bind(&PlatformSensorIio::StopPoll, this)); |
| +} |
| + |
| +void PlatformSensorIio::StopPoll() { |
| + timer_->Stop(); |
| +} |
| + |
| +void PlatformSensorIio::OnSensorReadFailed() { |
| + StopSensor(); |
|
Mikhail
2016/10/11 14:46:47
is it called on polling thread? if so, than just c
|
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&PlatformSensorIio::NotifySensorError, |
| + weak_factory_.GetWeakPtr())); |
| +} |
| + |
| +bool PlatformSensorIio::CheckSensorConfiguration( |
| + const PlatformSensorConfiguration& configuration) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| + return configuration.frequency() > 0 && |
| + configuration.frequency() <= |
| + mojom::SensorConfiguration::kMaxAllowedFrequency; |
| +} |
| + |
| +} // namespace device |