| 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 #include "device/generic_sensor/platform_sensor.h" | 5 #include "device/generic_sensor/platform_sensor.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "device/generic_sensor/platform_sensor_provider.h" | 10 #include "device/generic_sensor/platform_sensor_provider.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 void PlatformSensor::RemoveClient(Client* client) { | 83 void PlatformSensor::RemoveClient(Client* client) { |
| 84 DCHECK(client); | 84 DCHECK(client); |
| 85 clients_.RemoveObserver(client); | 85 clients_.RemoveObserver(client); |
| 86 auto client_entry = config_map_.find(client); | 86 auto client_entry = config_map_.find(client); |
| 87 if (client_entry != config_map_.end()) { | 87 if (client_entry != config_map_.end()) { |
| 88 config_map_.erase(client_entry); | 88 config_map_.erase(client_entry); |
| 89 UpdateSensorInternal(config_map_); | 89 UpdateSensorInternal(config_map_); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool PlatformSensor::GetLatestReading(SensorReading* result) { |
| 94 const SensorReadingSharedBuffer* buffer = |
| 95 static_cast<const SensorReadingSharedBuffer*>( |
| 96 shared_buffer_mapping_.get()); |
| 97 return GetSensorReadingFromBuffer(buffer, result); |
| 98 } |
| 99 |
| 93 void PlatformSensor::UpdateSensorReading(const SensorReading& reading, | 100 void PlatformSensor::UpdateSensorReading(const SensorReading& reading, |
| 94 bool notify_clients) { | 101 bool notify_clients) { |
| 95 ReadingBuffer* buffer = | 102 ReadingBuffer* buffer = |
| 96 static_cast<ReadingBuffer*>(shared_buffer_mapping_.get()); | 103 static_cast<ReadingBuffer*>(shared_buffer_mapping_.get()); |
| 97 auto& seqlock = buffer->seqlock.value(); | 104 auto& seqlock = buffer->seqlock.value(); |
| 98 seqlock.WriteBegin(); | 105 seqlock.WriteBegin(); |
| 99 buffer->reading = reading; | 106 buffer->reading = reading; |
| 100 seqlock.WriteEnd(); | 107 seqlock.WriteEnd(); |
| 101 | 108 |
| 102 if (notify_clients) | 109 if (notify_clients) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 133 | 140 |
| 134 if (!optimal_configuration) { | 141 if (!optimal_configuration) { |
| 135 StopSensor(); | 142 StopSensor(); |
| 136 return true; | 143 return true; |
| 137 } | 144 } |
| 138 | 145 |
| 139 return StartSensor(*optimal_configuration); | 146 return StartSensor(*optimal_configuration); |
| 140 } | 147 } |
| 141 | 148 |
| 142 } // namespace device | 149 } // namespace device |
| OLD | NEW |