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