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