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