OLD | NEW |
(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/mojo/sensor_impl.h" |
| 6 |
| 7 #include "device/sensors/mojo/sensor_type_converters.h" |
| 8 #include "device/sensors/platform/platform_sensor_configuration.h" |
| 9 |
| 10 namespace device { |
| 11 namespace sensors { |
| 12 |
| 13 SensorImpl::SensorImpl(mojo::InterfaceRequest<Sensor> request, |
| 14 scoped_refptr<device::PlatformSensor> sensor) |
| 15 : sensor_(sensor), binding_(this, std::move(request)) { |
| 16 sensor_->AddClient(this); |
| 17 } |
| 18 |
| 19 SensorImpl::~SensorImpl() { |
| 20 sensor_->RemoveClient(this); |
| 21 } |
| 22 |
| 23 void SensorImpl::SetClient(SensorClientPtr client) { |
| 24 client_ = std::move(client); |
| 25 } |
| 26 |
| 27 void SensorImpl::Start(SensorConfigurationPtr configuration, |
| 28 const StartCallback& callback) { |
| 29 Result result = |
| 30 sensor_->StartListening( |
| 31 this, configuration.To<device::PlatformSensorConfiguration>()) |
| 32 ? Result::SUCCESS |
| 33 : Result::FAILURE; |
| 34 callback.Run(result); |
| 35 } |
| 36 |
| 37 void SensorImpl::Stop(SensorConfigurationPtr configuration, |
| 38 const StopCallback& callback) { |
| 39 Result result = |
| 40 sensor_->StopListening( |
| 41 this, configuration.To<device::PlatformSensorConfiguration>()) |
| 42 ? Result::SUCCESS |
| 43 : Result::FAILURE; |
| 44 callback.Run(result); |
| 45 } |
| 46 |
| 47 void SensorImpl::OnSensorReadingChanged() { |
| 48 if (client_) |
| 49 client_->OnSensorReadingChanged(); |
| 50 } |
| 51 |
| 52 void SensorImpl::OnSensorError() { |
| 53 if (client_) |
| 54 client_->OnSensorError(); |
| 55 } |
| 56 |
| 57 } // namespace sensors |
| 58 } // namespace device |
OLD | NEW |