Commit ad53e202 authored by Oleh Lamzin's avatar Oleh Lamzin Committed by Commit Bot

[Telemetry SWX] Use which() and switch for unions

Use which() method and switch to convert Mojo unions. Ther benefit is
that if union will be extended on cros_healthd side, there will be
compilation error.

Bug: b:158658869
Change-Id: If86b6c9a1e8eebe7b28ba8597234d6f742638e03
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2273064
Commit-Queue: Oleh Lamzin <lamzin@google.com>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarRoland Bock <rbock@google.com>
Reviewed-by: default avatarMahmoud Gawad <mgawad@google.com>
Cr-Commit-Position: refs/heads/master@{#786200}
parent 61b95af0
......@@ -97,15 +97,15 @@ health::mojom::BatteryResultPtr Convert(
return nullptr;
}
auto output = health::mojom::BatteryResult::New();
if (input->is_error()) {
output->set_error(Convert(std::move(input->get_error())));
} else if (input->is_battery_info()) {
output->set_battery_info(Convert(std::move(input->get_battery_info())));
switch (input->which()) {
case cros_healthd::mojom::BatteryResult::Tag::BATTERY_INFO:
return health::mojom::BatteryResult::NewBatteryInfo(
Convert(std::move(input->get_battery_info())));
case cros_healthd::mojom::BatteryResult::Tag::ERROR:
return health::mojom::BatteryResult::NewError(
Convert(std::move(input->get_error())));
}
return output;
NOTREACHED();
}
health::mojom::NonRemovableBlockDeviceInfoPtr Convert(
......@@ -128,17 +128,17 @@ health::mojom::NonRemovableBlockDeviceResultPtr Convert(
return nullptr;
}
auto output = health::mojom::NonRemovableBlockDeviceResult::New();
if (input->is_error()) {
output->set_error(Convert(std::move(input->get_error())));
} else if (input->is_block_device_info()) {
output->set_block_device_info(
ConvertPtrVector<health::mojom::NonRemovableBlockDeviceInfoPtr>(
std::move(input->get_block_device_info())));
switch (input->which()) {
case cros_healthd::mojom::NonRemovableBlockDeviceResult::Tag::
BLOCK_DEVICE_INFO:
return health::mojom::NonRemovableBlockDeviceResult::NewBlockDeviceInfo(
ConvertPtrVector<health::mojom::NonRemovableBlockDeviceInfoPtr>(
std::move(input->get_block_device_info())));
case cros_healthd::mojom::NonRemovableBlockDeviceResult::Tag::ERROR:
return health::mojom::NonRemovableBlockDeviceResult::NewError(
Convert(std::move(input->get_error())));
}
return output;
NOTREACHED();
}
health::mojom::CachedVpdInfoPtr Convert(
......@@ -156,15 +156,15 @@ health::mojom::CachedVpdResultPtr Convert(
return nullptr;
}
auto output = health::mojom::CachedVpdResult::New();
if (input->is_error()) {
output->set_error(Convert(std::move(input->get_error())));
} else if (input->is_vpd_info()) {
output->set_vpd_info(Convert(std::move(input->get_vpd_info())));
switch (input->which()) {
case cros_healthd::mojom::CachedVpdResult::Tag::VPD_INFO:
return health::mojom::CachedVpdResult::NewVpdInfo(
Convert(std::move(input->get_vpd_info())));
case cros_healthd::mojom::CachedVpdResult::Tag::ERROR:
return health::mojom::CachedVpdResult::NewError(
Convert(std::move(input->get_error())));
}
return output;
NOTREACHED();
}
health::mojom::TelemetryInfoPtr Convert(
......
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