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