Skip to main content

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