fdomain_fuchsia_buildinfo/
fdomain_fuchsia_buildinfo.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fdomain_client::fidl::{ControlHandle as _, FDomainFlexibleIntoResult as _, Responder as _};
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9pub use fidl_fuchsia_buildinfo__common::*;
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
14pub struct ProviderMarker;
15
16impl fdomain_client::fidl::ProtocolMarker for ProviderMarker {
17    type Proxy = ProviderProxy;
18    type RequestStream = ProviderRequestStream;
19
20    const DEBUG_NAME: &'static str = "fuchsia.buildinfo.Provider";
21}
22impl fdomain_client::fidl::DiscoverableProtocolMarker for ProviderMarker {}
23
24pub trait ProviderProxyInterface: Send + Sync {
25    type GetBuildInfoResponseFut: std::future::Future<Output = Result<BuildInfo, fidl::Error>>
26        + Send;
27    fn r#get_build_info(&self) -> Self::GetBuildInfoResponseFut;
28}
29
30#[derive(Debug, Clone)]
31pub struct ProviderProxy {
32    client: fidl::client::Client<fdomain_client::fidl::FDomainResourceDialect>,
33}
34
35impl fdomain_client::fidl::Proxy for ProviderProxy {
36    type Protocol = ProviderMarker;
37
38    fn from_channel(inner: fdomain_client::Channel) -> Self {
39        Self::new(inner)
40    }
41
42    fn into_channel(self) -> Result<fdomain_client::Channel, Self> {
43        self.client.into_channel().map_err(|client| Self { client })
44    }
45
46    fn as_channel(&self) -> &fdomain_client::Channel {
47        self.client.as_channel()
48    }
49}
50
51impl ProviderProxy {
52    /// Create a new Proxy for fuchsia.buildinfo/Provider.
53    pub fn new(channel: fdomain_client::Channel) -> Self {
54        let protocol_name = <ProviderMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME;
55        Self { client: fidl::client::Client::new(channel, protocol_name) }
56    }
57
58    /// Get a Stream of events from the remote end of the protocol.
59    ///
60    /// # Panics
61    ///
62    /// Panics if the event stream was already taken.
63    pub fn take_event_stream(&self) -> ProviderEventStream {
64        ProviderEventStream { event_receiver: self.client.take_event_receiver() }
65    }
66
67    /// Returns a table of build information.
68    pub fn r#get_build_info(
69        &self,
70    ) -> fidl::client::QueryResponseFut<BuildInfo, fdomain_client::fidl::FDomainResourceDialect>
71    {
72        ProviderProxyInterface::r#get_build_info(self)
73    }
74}
75
76impl ProviderProxyInterface for ProviderProxy {
77    type GetBuildInfoResponseFut =
78        fidl::client::QueryResponseFut<BuildInfo, fdomain_client::fidl::FDomainResourceDialect>;
79    fn r#get_build_info(&self) -> Self::GetBuildInfoResponseFut {
80        fn _decode(
81            mut _buf: Result<<fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
82        ) -> Result<BuildInfo, fidl::Error> {
83            let _response = fidl::client::decode_transaction_body::<
84                ProviderGetBuildInfoResponse,
85                fdomain_client::fidl::FDomainResourceDialect,
86                0x2cf46f6b8e681b93,
87            >(_buf?)?;
88            Ok(_response.build_info)
89        }
90        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, BuildInfo>(
91            (),
92            0x2cf46f6b8e681b93,
93            fidl::encoding::DynamicFlags::empty(),
94            _decode,
95        )
96    }
97}
98
99pub struct ProviderEventStream {
100    event_receiver: fidl::client::EventReceiver<fdomain_client::fidl::FDomainResourceDialect>,
101}
102
103impl std::marker::Unpin for ProviderEventStream {}
104
105impl futures::stream::FusedStream for ProviderEventStream {
106    fn is_terminated(&self) -> bool {
107        self.event_receiver.is_terminated()
108    }
109}
110
111impl futures::Stream for ProviderEventStream {
112    type Item = Result<ProviderEvent, fidl::Error>;
113
114    fn poll_next(
115        mut self: std::pin::Pin<&mut Self>,
116        cx: &mut std::task::Context<'_>,
117    ) -> std::task::Poll<Option<Self::Item>> {
118        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
119            &mut self.event_receiver,
120            cx
121        )?) {
122            Some(buf) => std::task::Poll::Ready(Some(ProviderEvent::decode(buf))),
123            None => std::task::Poll::Ready(None),
124        }
125    }
126}
127
128#[derive(Debug)]
129pub enum ProviderEvent {}
130
131impl ProviderEvent {
132    /// Decodes a message buffer as a [`ProviderEvent`].
133    fn decode(
134        mut buf: <fdomain_client::fidl::FDomainResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
135    ) -> Result<ProviderEvent, fidl::Error> {
136        let (bytes, _handles) = buf.split_mut();
137        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
138        debug_assert_eq!(tx_header.tx_id, 0);
139        match tx_header.ordinal {
140            _ => Err(fidl::Error::UnknownOrdinal {
141                ordinal: tx_header.ordinal,
142                protocol_name: <ProviderMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
143            }),
144        }
145    }
146}
147
148/// A Stream of incoming requests for fuchsia.buildinfo/Provider.
149pub struct ProviderRequestStream {
150    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
151    is_terminated: bool,
152}
153
154impl std::marker::Unpin for ProviderRequestStream {}
155
156impl futures::stream::FusedStream for ProviderRequestStream {
157    fn is_terminated(&self) -> bool {
158        self.is_terminated
159    }
160}
161
162impl fdomain_client::fidl::RequestStream for ProviderRequestStream {
163    type Protocol = ProviderMarker;
164    type ControlHandle = ProviderControlHandle;
165
166    fn from_channel(channel: fdomain_client::Channel) -> Self {
167        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
168    }
169
170    fn control_handle(&self) -> Self::ControlHandle {
171        ProviderControlHandle { inner: self.inner.clone() }
172    }
173
174    fn into_inner(
175        self,
176    ) -> (::std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>, bool)
177    {
178        (self.inner, self.is_terminated)
179    }
180
181    fn from_inner(
182        inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
183        is_terminated: bool,
184    ) -> Self {
185        Self { inner, is_terminated }
186    }
187}
188
189impl futures::Stream for ProviderRequestStream {
190    type Item = Result<ProviderRequest, fidl::Error>;
191
192    fn poll_next(
193        mut self: std::pin::Pin<&mut Self>,
194        cx: &mut std::task::Context<'_>,
195    ) -> std::task::Poll<Option<Self::Item>> {
196        let this = &mut *self;
197        if this.inner.check_shutdown(cx) {
198            this.is_terminated = true;
199            return std::task::Poll::Ready(None);
200        }
201        if this.is_terminated {
202            panic!("polled ProviderRequestStream after completion");
203        }
204        fidl::encoding::with_tls_decode_buf::<_, fdomain_client::fidl::FDomainResourceDialect>(
205            |bytes, handles| {
206                match this.inner.channel().read_etc(cx, bytes, handles) {
207                    std::task::Poll::Ready(Ok(())) => {}
208                    std::task::Poll::Pending => return std::task::Poll::Pending,
209                    std::task::Poll::Ready(Err(None)) => {
210                        this.is_terminated = true;
211                        return std::task::Poll::Ready(None);
212                    }
213                    std::task::Poll::Ready(Err(Some(e))) => {
214                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
215                            e.into(),
216                        ))))
217                    }
218                }
219
220                // A message has been received from the channel
221                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
222
223                std::task::Poll::Ready(Some(match header.ordinal {
224                    0x2cf46f6b8e681b93 => {
225                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
226                        let mut req = fidl::new_empty!(
227                            fidl::encoding::EmptyPayload,
228                            fdomain_client::fidl::FDomainResourceDialect
229                        );
230                        fidl::encoding::Decoder::<fdomain_client::fidl::FDomainResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
231                        let control_handle = ProviderControlHandle { inner: this.inner.clone() };
232                        Ok(ProviderRequest::GetBuildInfo {
233                            responder: ProviderGetBuildInfoResponder {
234                                control_handle: std::mem::ManuallyDrop::new(control_handle),
235                                tx_id: header.tx_id,
236                            },
237                        })
238                    }
239                    _ => Err(fidl::Error::UnknownOrdinal {
240                        ordinal: header.ordinal,
241                        protocol_name:
242                            <ProviderMarker as fdomain_client::fidl::ProtocolMarker>::DEBUG_NAME,
243                    }),
244                }))
245            },
246        )
247    }
248}
249
250/// Returns build information about a Fuchsia system.
251#[derive(Debug)]
252pub enum ProviderRequest {
253    /// Returns a table of build information.
254    GetBuildInfo { responder: ProviderGetBuildInfoResponder },
255}
256
257impl ProviderRequest {
258    #[allow(irrefutable_let_patterns)]
259    pub fn into_get_build_info(self) -> Option<(ProviderGetBuildInfoResponder)> {
260        if let ProviderRequest::GetBuildInfo { responder } = self {
261            Some((responder))
262        } else {
263            None
264        }
265    }
266
267    /// Name of the method defined in FIDL
268    pub fn method_name(&self) -> &'static str {
269        match *self {
270            ProviderRequest::GetBuildInfo { .. } => "get_build_info",
271        }
272    }
273}
274
275#[derive(Debug, Clone)]
276pub struct ProviderControlHandle {
277    inner: std::sync::Arc<fidl::ServeInner<fdomain_client::fidl::FDomainResourceDialect>>,
278}
279
280impl fdomain_client::fidl::ControlHandle for ProviderControlHandle {
281    fn shutdown(&self) {
282        self.inner.shutdown()
283    }
284
285    fn is_closed(&self) -> bool {
286        self.inner.channel().is_closed()
287    }
288    fn on_closed(&self) -> fdomain_client::OnFDomainSignals {
289        self.inner.channel().on_closed()
290    }
291}
292
293impl ProviderControlHandle {}
294
295#[must_use = "FIDL methods require a response to be sent"]
296#[derive(Debug)]
297pub struct ProviderGetBuildInfoResponder {
298    control_handle: std::mem::ManuallyDrop<ProviderControlHandle>,
299    tx_id: u32,
300}
301
302/// Set the the channel to be shutdown (see [`ProviderControlHandle::shutdown`])
303/// if the responder is dropped without sending a response, so that the client
304/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
305impl std::ops::Drop for ProviderGetBuildInfoResponder {
306    fn drop(&mut self) {
307        self.control_handle.shutdown();
308        // Safety: drops once, never accessed again
309        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
310    }
311}
312
313impl fdomain_client::fidl::Responder for ProviderGetBuildInfoResponder {
314    type ControlHandle = ProviderControlHandle;
315
316    fn control_handle(&self) -> &ProviderControlHandle {
317        &self.control_handle
318    }
319
320    fn drop_without_shutdown(mut self) {
321        // Safety: drops once, never accessed again due to mem::forget
322        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
323        // Prevent Drop from running (which would shut down the channel)
324        std::mem::forget(self);
325    }
326}
327
328impl ProviderGetBuildInfoResponder {
329    /// Sends a response to the FIDL transaction.
330    ///
331    /// Sets the channel to shutdown if an error occurs.
332    pub fn send(self, mut build_info: &BuildInfo) -> Result<(), fidl::Error> {
333        let _result = self.send_raw(build_info);
334        if _result.is_err() {
335            self.control_handle.shutdown();
336        }
337        self.drop_without_shutdown();
338        _result
339    }
340
341    /// Similar to "send" but does not shutdown the channel if an error occurs.
342    pub fn send_no_shutdown_on_err(self, mut build_info: &BuildInfo) -> Result<(), fidl::Error> {
343        let _result = self.send_raw(build_info);
344        self.drop_without_shutdown();
345        _result
346    }
347
348    fn send_raw(&self, mut build_info: &BuildInfo) -> Result<(), fidl::Error> {
349        self.control_handle.inner.send::<ProviderGetBuildInfoResponse>(
350            (build_info,),
351            self.tx_id,
352            0x2cf46f6b8e681b93,
353            fidl::encoding::DynamicFlags::empty(),
354        )
355    }
356}
357
358mod internal {
359    use super::*;
360}