Skip to main content

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