sl4f_lib/hwinfo/
facade.rsuse crate::common_utils::common::macros::{fx_err_and_bail, with_line};
use crate::hwinfo::types::{
SerializableBoardInfo, SerializableDeviceInfo, SerializableProductInfo,
};
use anyhow::Error;
use fidl_fuchsia_hwinfo::{BoardMarker, DeviceMarker, ProductMarker};
use fuchsia_component as app;
use tracing::info;
#[derive(Debug)]
pub struct HwinfoFacade {}
impl HwinfoFacade {
pub fn new() -> HwinfoFacade {
HwinfoFacade {}
}
pub async fn get_device_info(&self) -> Result<SerializableDeviceInfo, Error> {
let tag = "HwinfoFacade::get_info";
let device_info_proxy = app::client::connect_to_protocol::<DeviceMarker>();
match device_info_proxy {
Ok(p) => {
let device_info = p.get_info().await?;
let device_info_string = format!("Device info found: {:?}", device_info);
info!(tag = &with_line!(tag), "{}", device_info_string);
Ok(SerializableDeviceInfo::new(&device_info))
}
Err(err) => fx_err_and_bail!(
&with_line!(tag),
format_err!("Failed to create hwinfo proxy: {}", err)
),
}
}
pub async fn get_product_info(&self) -> Result<SerializableProductInfo, Error> {
let tag = "HwinfoFacade::get_product_info";
let product_info_proxy = app::client::connect_to_protocol::<ProductMarker>();
match product_info_proxy {
Ok(p) => {
let product_info = p.get_info().await?;
let product_info_string = format!("Product info found: {:?}", product_info);
info!(tag = &with_line!(tag), "{}", product_info_string);
Ok(SerializableProductInfo::new(&product_info))
}
Err(err) => fx_err_and_bail!(
&with_line!(tag),
format_err!("Failed to create hwinfo proxy: {}", err)
),
}
}
pub async fn get_board_info(&self) -> Result<SerializableBoardInfo, Error> {
let tag = "HwinfoFacade::get_board_info";
let board_info_proxy = app::client::connect_to_protocol::<BoardMarker>();
match board_info_proxy {
Ok(p) => {
let board_info = p.get_info().await?;
let board_info_string = format!("Board info found: {:?}", board_info);
info!(tag = &with_line!(tag), "{}", board_info_string);
Ok(SerializableBoardInfo::new(&board_info))
}
Err(err) => fx_err_and_bail!(
&with_line!(tag),
format_err!("Failed to create hwinfo proxy: {}", err)
),
}
}
}