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