Skip to main content

guest_emulation_transport/
resolver.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resource definitions for the GET client.
5
6use crate::GuestEmulationTransportClient;
7use chipset_resources::ipmi_kcs::IpmiSelEventSinkHandleKind;
8use chipset_resources::ipmi_kcs::ResolvedIpmiSelEventSink;
9use chipset_resources::ipmi_kcs::SelEventSink;
10use get_protocol::IPMI_SEL_RECORD_SIZE;
11use std::convert::Infallible;
12use vm_resource::CanResolveTo;
13use vm_resource::PlatformResource;
14use vm_resource::ResolveResource;
15use vm_resource::ResourceKind;
16
17/// A resource kind for getting a [`GuestEmulationTransportClient`].
18///
19/// This is primarily used with [`PlatformResource`].
20pub enum GetClientKind {}
21
22impl ResourceKind for GetClientKind {
23    const NAME: &'static str = "get";
24}
25
26impl CanResolveTo<GuestEmulationTransportClient> for GetClientKind {
27    type Input<'a> = ();
28}
29
30impl ResolveResource<GetClientKind, PlatformResource> for GuestEmulationTransportClient {
31    type Output = GuestEmulationTransportClient;
32    type Error = Infallible;
33
34    fn resolve(
35        &self,
36        PlatformResource: PlatformResource,
37        (): (),
38    ) -> Result<Self::Output, Self::Error> {
39        Ok(self.clone())
40    }
41}
42
43struct GetIpmiSelEventSink(GuestEmulationTransportClient);
44
45impl SelEventSink for GetIpmiSelEventSink {
46    fn try_send(&mut self, record_id: u16, record: [u8; IPMI_SEL_RECORD_SIZE]) -> bool {
47        self.0.ipmi_sel(record_id, record);
48        true
49    }
50}
51
52/// Resolves the platform IPMI SEL event sink to GET.
53pub struct IpmiSelEventSinkResolver(pub GuestEmulationTransportClient);
54
55impl ResolveResource<IpmiSelEventSinkHandleKind, PlatformResource> for IpmiSelEventSinkResolver {
56    type Output = ResolvedIpmiSelEventSink;
57    type Error = Infallible;
58
59    fn resolve(
60        &self,
61        PlatformResource: PlatformResource,
62        (): (),
63    ) -> Result<Self::Output, Self::Error> {
64        Ok(ResolvedIpmiSelEventSink(Box::new(GetIpmiSelEventSink(
65            self.0.clone(),
66        ))))
67    }
68}