sl4f_lib/hwinfo/
facade.rs1use crate::common_utils::common::macros::{fx_err_and_bail, with_line};
6use crate::hwinfo::types::{
7 SerializableBoardInfo, SerializableDeviceInfo, SerializableProductInfo,
8};
9use anyhow::Error;
10use fidl_fuchsia_hwinfo::{BoardMarker, DeviceMarker, ProductMarker};
11use fuchsia_component as app;
12use log::info;
13
14#[derive(Debug)]
19pub struct HwinfoFacade {}
20
21impl HwinfoFacade {
22 pub fn new() -> HwinfoFacade {
23 HwinfoFacade {}
24 }
25
26 pub async fn get_device_info(&self) -> Result<SerializableDeviceInfo, Error> {
29 let tag = "HwinfoFacade::get_info";
30
31 let device_info_proxy = app::client::connect_to_protocol::<DeviceMarker>();
32
33 match device_info_proxy {
34 Ok(p) => {
35 let device_info = p.get_info().await?;
36 let device_info_string = format!("Device info found: {:?}", device_info);
37 info!(tag = &with_line!(tag); "{}", device_info_string);
38 Ok(SerializableDeviceInfo::new(&device_info))
39 }
40 Err(err) => fx_err_and_bail!(
41 &with_line!(tag),
42 format_err!("Failed to create hwinfo proxy: {}", err)
43 ),
44 }
45 }
46
47 pub async fn get_product_info(&self) -> Result<SerializableProductInfo, Error> {
49 let tag = "HwinfoFacade::get_product_info";
50
51 let product_info_proxy = app::client::connect_to_protocol::<ProductMarker>();
52
53 match product_info_proxy {
54 Ok(p) => {
55 let product_info = p.get_info().await?;
56 let product_info_string = format!("Product info found: {:?}", product_info);
57 info!(tag = &with_line!(tag); "{}", product_info_string);
58 Ok(SerializableProductInfo::new(&product_info))
59 }
60 Err(err) => fx_err_and_bail!(
61 &with_line!(tag),
62 format_err!("Failed to create hwinfo proxy: {}", err)
63 ),
64 }
65 }
66
67 pub async fn get_board_info(&self) -> Result<SerializableBoardInfo, Error> {
69 let tag = "HwinfoFacade::get_board_info";
70 let board_info_proxy = app::client::connect_to_protocol::<BoardMarker>();
71 match board_info_proxy {
72 Ok(p) => {
73 let board_info = p.get_info().await?;
74 let board_info_string = format!("Board info found: {:?}", board_info);
75 info!(tag = &with_line!(tag); "{}", board_info_string);
76 Ok(SerializableBoardInfo::new(&board_info))
77 }
78 Err(err) => fx_err_and_bail!(
79 &with_line!(tag),
80 format_err!("Failed to create hwinfo proxy: {}", err)
81 ),
82 }
83 }
84}