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