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