Commit 90ecd947 authored by Harvey Yang's avatar Harvey Yang Committed by Commit Bot

Chromium: Use GetAttributes in SensorDevice

Updating with CL:2494163, this commit replaces GetAttribute with
GetAttributes so that sensor clients can get multiple attributes within
one Mojo request.

BUG=chromium:1006141, b:162154663
TEST=builds and run ash on octopus

Change-Id: I33fb315050b5aaefa8e387a8afcdc2aa1c9ca2da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490320Reviewed-by: default avatarJorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: default avatarRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Cheng-Hao Yang <chenghaoyang@chromium.org>
Auto-Submit: Cheng-Hao Yang <chenghaoyang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820263}
parent da6bff87
...@@ -66,17 +66,22 @@ void FakeSensorDevice::SetChannels(const std::vector<ChannelData>& channels) { ...@@ -66,17 +66,22 @@ void FakeSensorDevice::SetChannels(const std::vector<ChannelData>& channels) {
channels_enabled_.assign(channels_.size(), false); channels_enabled_.assign(channels_.size(), false);
} }
void FakeSensorDevice::GetAttribute(const std::string& attr_name, void FakeSensorDevice::GetAttributes(const std::vector<std::string>& attr_names,
GetAttributeCallback callback) { GetAttributesCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::Optional<std::string> value = base::nullopt; std::vector<base::Optional<std::string>> values;
values.reserve(attr_names.size());
for (const auto& attr_name : attr_names) {
auto it = attributes_.find(attr_name); auto it = attributes_.find(attr_name);
if (it != attributes_.end()) if (it != attributes_.end())
value = it->second; values.push_back(it->second);
else
values.push_back(base::nullopt);
}
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), std::move(value))); FROM_HERE, base::BindOnce(std::move(callback), std::move(values)));
} }
void FakeSensorDevice::SetFrequency(double frequency, void FakeSensorDevice::SetFrequency(double frequency,
......
...@@ -48,8 +48,8 @@ class FakeSensorDevice final : public mojom::SensorDevice { ...@@ -48,8 +48,8 @@ class FakeSensorDevice final : public mojom::SensorDevice {
// Implementation of mojom::SensorDevice. // Implementation of mojom::SensorDevice.
void SetTimeout(uint32_t timeout) override {} void SetTimeout(uint32_t timeout) override {}
void GetAttribute(const std::string& attr_name, void GetAttributes(const std::vector<std::string>& attr_names,
GetAttributeCallback callback) override; GetAttributesCallback callback) override;
void SetFrequency(double frequency, SetFrequencyCallback callback) override; void SetFrequency(double frequency, SetFrequencyCallback callback) override;
void StartReadingSamples( void StartReadingSamples(
mojo::PendingRemote<mojom::SensorDeviceSamplesObserver> observer) mojo::PendingRemote<mojom::SensorDeviceSamplesObserver> observer)
......
...@@ -71,9 +71,10 @@ interface SensorDevice { ...@@ -71,9 +71,10 @@ interface SensorDevice {
// Default: 5000 milliseconds. // Default: 5000 milliseconds.
SetTimeout@0(uint32 timeout); SetTimeout@0(uint32 timeout);
// Gets the |attr_name| attribute of this device into |value| in string. // Gets the |attr_names| attributes of this device into |values| as strings.
// Returns base::nullopt if the attribute cannot be read. // When an attribute cannot be read, its value in |values| is set to null.
GetAttribute@1(string attr_name) => (string? value); // |values| and |attr_names| always have the same size.
GetAttributes@1(array<string> attr_names) => (array<string?> values);
// Sets the frequency in Hz of the device before starting to read samples. // Sets the frequency in Hz of the device before starting to read samples.
// If no frequency or an invalid frequency is set, an // If no frequency or an invalid frequency is set, an
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment