Skip to main content

fidl_fuchsia_recovery_policy/
fidl_fuchsia_recovery_policy.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_recovery_policy__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18    type Proxy = DeviceProxy;
19    type RequestStream = DeviceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.recovery.policy.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26
27pub trait DeviceProxyInterface: Send + Sync {
28    fn r#set_is_local_reset_allowed(&self, allowed: bool) -> Result<(), fidl::Error>;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct DeviceSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
38    type Proxy = DeviceProxy;
39    type Protocol = DeviceMarker;
40
41    fn from_channel(inner: fidl::Channel) -> Self {
42        Self::new(inner)
43    }
44
45    fn into_channel(self) -> fidl::Channel {
46        self.client.into_channel()
47    }
48
49    fn as_channel(&self) -> &fidl::Channel {
50        self.client.as_channel()
51    }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl DeviceSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        Self { client: fidl::client::sync::Client::new(channel) }
58    }
59
60    pub fn into_channel(self) -> fidl::Channel {
61        self.client.into_channel()
62    }
63
64    /// Waits until an event arrives and returns it. It is safe for other
65    /// threads to make concurrent requests while waiting for an event.
66    pub fn wait_for_event(
67        &self,
68        deadline: zx::MonotonicInstant,
69    ) -> Result<DeviceEvent, fidl::Error> {
70        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
71    }
72
73    /// Sets whether local factory reset is enabled, and persists the setting
74    /// after reboot.
75    /// If this function has never been called on this device, then local
76    /// factory reset is allowed by default.
77    pub fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
78        self.client.send::<DeviceSetIsLocalResetAllowedRequest>(
79            (allowed,),
80            0x7a0343d0fccb7ac7,
81            fidl::encoding::DynamicFlags::empty(),
82        )
83    }
84}
85
86#[cfg(target_os = "fuchsia")]
87impl From<DeviceSynchronousProxy> for zx::NullableHandle {
88    fn from(value: DeviceSynchronousProxy) -> Self {
89        value.into_channel().into()
90    }
91}
92
93#[cfg(target_os = "fuchsia")]
94impl From<fidl::Channel> for DeviceSynchronousProxy {
95    fn from(value: fidl::Channel) -> Self {
96        Self::new(value)
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
102    type Protocol = DeviceMarker;
103
104    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
105        Self::new(value.into_channel())
106    }
107}
108
109#[derive(Debug, Clone)]
110pub struct DeviceProxy {
111    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
112}
113
114impl fidl::endpoints::Proxy for DeviceProxy {
115    type Protocol = DeviceMarker;
116
117    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
118        Self::new(inner)
119    }
120
121    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
122        self.client.into_channel().map_err(|client| Self { client })
123    }
124
125    fn as_channel(&self) -> &::fidl::AsyncChannel {
126        self.client.as_channel()
127    }
128}
129
130impl DeviceProxy {
131    /// Create a new Proxy for fuchsia.recovery.policy/Device.
132    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
133        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
134        Self { client: fidl::client::Client::new(channel, protocol_name) }
135    }
136
137    /// Get a Stream of events from the remote end of the protocol.
138    ///
139    /// # Panics
140    ///
141    /// Panics if the event stream was already taken.
142    pub fn take_event_stream(&self) -> DeviceEventStream {
143        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
144    }
145
146    /// Sets whether local factory reset is enabled, and persists the setting
147    /// after reboot.
148    /// If this function has never been called on this device, then local
149    /// factory reset is allowed by default.
150    pub fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
151        DeviceProxyInterface::r#set_is_local_reset_allowed(self, allowed)
152    }
153}
154
155impl DeviceProxyInterface for DeviceProxy {
156    fn r#set_is_local_reset_allowed(&self, mut allowed: bool) -> Result<(), fidl::Error> {
157        self.client.send::<DeviceSetIsLocalResetAllowedRequest>(
158            (allowed,),
159            0x7a0343d0fccb7ac7,
160            fidl::encoding::DynamicFlags::empty(),
161        )
162    }
163}
164
165pub struct DeviceEventStream {
166    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
167}
168
169impl std::marker::Unpin for DeviceEventStream {}
170
171impl futures::stream::FusedStream for DeviceEventStream {
172    fn is_terminated(&self) -> bool {
173        self.event_receiver.is_terminated()
174    }
175}
176
177impl futures::Stream for DeviceEventStream {
178    type Item = Result<DeviceEvent, fidl::Error>;
179
180    fn poll_next(
181        mut self: std::pin::Pin<&mut Self>,
182        cx: &mut std::task::Context<'_>,
183    ) -> std::task::Poll<Option<Self::Item>> {
184        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
185            &mut self.event_receiver,
186            cx
187        )?) {
188            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
189            None => std::task::Poll::Ready(None),
190        }
191    }
192}
193
194#[derive(Debug)]
195pub enum DeviceEvent {}
196
197impl DeviceEvent {
198    /// Decodes a message buffer as a [`DeviceEvent`].
199    fn decode(
200        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
201    ) -> Result<DeviceEvent, fidl::Error> {
202        let (bytes, _handles) = buf.split_mut();
203        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
204        debug_assert_eq!(tx_header.tx_id, 0);
205        match tx_header.ordinal {
206            _ => Err(fidl::Error::UnknownOrdinal {
207                ordinal: tx_header.ordinal,
208                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
209            }),
210        }
211    }
212}
213
214/// A Stream of incoming requests for fuchsia.recovery.policy/Device.
215pub struct DeviceRequestStream {
216    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
217    is_terminated: bool,
218}
219
220impl std::marker::Unpin for DeviceRequestStream {}
221
222impl futures::stream::FusedStream for DeviceRequestStream {
223    fn is_terminated(&self) -> bool {
224        self.is_terminated
225    }
226}
227
228impl fidl::endpoints::RequestStream for DeviceRequestStream {
229    type Protocol = DeviceMarker;
230    type ControlHandle = DeviceControlHandle;
231
232    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
233        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
234    }
235
236    fn control_handle(&self) -> Self::ControlHandle {
237        DeviceControlHandle { inner: self.inner.clone() }
238    }
239
240    fn into_inner(
241        self,
242    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
243    {
244        (self.inner, self.is_terminated)
245    }
246
247    fn from_inner(
248        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
249        is_terminated: bool,
250    ) -> Self {
251        Self { inner, is_terminated }
252    }
253}
254
255impl futures::Stream for DeviceRequestStream {
256    type Item = Result<DeviceRequest, fidl::Error>;
257
258    fn poll_next(
259        mut self: std::pin::Pin<&mut Self>,
260        cx: &mut std::task::Context<'_>,
261    ) -> std::task::Poll<Option<Self::Item>> {
262        let this = &mut *self;
263        if this.inner.check_shutdown(cx) {
264            this.is_terminated = true;
265            return std::task::Poll::Ready(None);
266        }
267        if this.is_terminated {
268            panic!("polled DeviceRequestStream after completion");
269        }
270        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
271            |bytes, handles| {
272                match this.inner.channel().read_etc(cx, bytes, handles) {
273                    std::task::Poll::Ready(Ok(())) => {}
274                    std::task::Poll::Pending => return std::task::Poll::Pending,
275                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
276                        this.is_terminated = true;
277                        return std::task::Poll::Ready(None);
278                    }
279                    std::task::Poll::Ready(Err(e)) => {
280                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
281                            e.into(),
282                        ))));
283                    }
284                }
285
286                // A message has been received from the channel
287                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
288
289                std::task::Poll::Ready(Some(match header.ordinal {
290                    0x7a0343d0fccb7ac7 => {
291                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
292                        let mut req = fidl::new_empty!(
293                            DeviceSetIsLocalResetAllowedRequest,
294                            fidl::encoding::DefaultFuchsiaResourceDialect
295                        );
296                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetIsLocalResetAllowedRequest>(&header, _body_bytes, handles, &mut req)?;
297                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
298                        Ok(DeviceRequest::SetIsLocalResetAllowed {
299                            allowed: req.allowed,
300
301                            control_handle,
302                        })
303                    }
304                    _ => Err(fidl::Error::UnknownOrdinal {
305                        ordinal: header.ordinal,
306                        protocol_name:
307                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
308                    }),
309                }))
310            },
311        )
312    }
313}
314
315/// A protocol for controlling whether factory reset can be triggered by holding
316/// the physical button.
317/// This protocol will be used by Settings service to make root_presenter aware
318/// of a new FactoryReset policy.
319#[derive(Debug)]
320pub enum DeviceRequest {
321    /// Sets whether local factory reset is enabled, and persists the setting
322    /// after reboot.
323    /// If this function has never been called on this device, then local
324    /// factory reset is allowed by default.
325    SetIsLocalResetAllowed { allowed: bool, control_handle: DeviceControlHandle },
326}
327
328impl DeviceRequest {
329    #[allow(irrefutable_let_patterns)]
330    pub fn into_set_is_local_reset_allowed(self) -> Option<(bool, DeviceControlHandle)> {
331        if let DeviceRequest::SetIsLocalResetAllowed { allowed, control_handle } = self {
332            Some((allowed, control_handle))
333        } else {
334            None
335        }
336    }
337
338    /// Name of the method defined in FIDL
339    pub fn method_name(&self) -> &'static str {
340        match *self {
341            DeviceRequest::SetIsLocalResetAllowed { .. } => "set_is_local_reset_allowed",
342        }
343    }
344}
345
346#[derive(Debug, Clone)]
347pub struct DeviceControlHandle {
348    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
349}
350
351impl fidl::endpoints::ControlHandle for DeviceControlHandle {
352    fn shutdown(&self) {
353        self.inner.shutdown()
354    }
355
356    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
357        self.inner.shutdown_with_epitaph(status)
358    }
359
360    fn is_closed(&self) -> bool {
361        self.inner.channel().is_closed()
362    }
363    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
364        self.inner.channel().on_closed()
365    }
366
367    #[cfg(target_os = "fuchsia")]
368    fn signal_peer(
369        &self,
370        clear_mask: zx::Signals,
371        set_mask: zx::Signals,
372    ) -> Result<(), zx_status::Status> {
373        use fidl::Peered;
374        self.inner.channel().signal_peer(clear_mask, set_mask)
375    }
376}
377
378impl DeviceControlHandle {}
379
380#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
381pub struct FactoryResetMarker;
382
383impl fidl::endpoints::ProtocolMarker for FactoryResetMarker {
384    type Proxy = FactoryResetProxy;
385    type RequestStream = FactoryResetRequestStream;
386    #[cfg(target_os = "fuchsia")]
387    type SynchronousProxy = FactoryResetSynchronousProxy;
388
389    const DEBUG_NAME: &'static str = "fuchsia.recovery.policy.FactoryReset";
390}
391impl fidl::endpoints::DiscoverableProtocolMarker for FactoryResetMarker {}
392
393pub trait FactoryResetProxyInterface: Send + Sync {
394    type GetEnabledResponseFut: std::future::Future<Output = Result<bool, fidl::Error>> + Send;
395    fn r#get_enabled(&self) -> Self::GetEnabledResponseFut;
396}
397#[derive(Debug)]
398#[cfg(target_os = "fuchsia")]
399pub struct FactoryResetSynchronousProxy {
400    client: fidl::client::sync::Client,
401}
402
403#[cfg(target_os = "fuchsia")]
404impl fidl::endpoints::SynchronousProxy for FactoryResetSynchronousProxy {
405    type Proxy = FactoryResetProxy;
406    type Protocol = FactoryResetMarker;
407
408    fn from_channel(inner: fidl::Channel) -> Self {
409        Self::new(inner)
410    }
411
412    fn into_channel(self) -> fidl::Channel {
413        self.client.into_channel()
414    }
415
416    fn as_channel(&self) -> &fidl::Channel {
417        self.client.as_channel()
418    }
419}
420
421#[cfg(target_os = "fuchsia")]
422impl FactoryResetSynchronousProxy {
423    pub fn new(channel: fidl::Channel) -> Self {
424        Self { client: fidl::client::sync::Client::new(channel) }
425    }
426
427    pub fn into_channel(self) -> fidl::Channel {
428        self.client.into_channel()
429    }
430
431    /// Waits until an event arrives and returns it. It is safe for other
432    /// threads to make concurrent requests while waiting for an event.
433    pub fn wait_for_event(
434        &self,
435        deadline: zx::MonotonicInstant,
436    ) -> Result<FactoryResetEvent, fidl::Error> {
437        FactoryResetEvent::decode(self.client.wait_for_event::<FactoryResetMarker>(deadline)?)
438    }
439
440    /// A hanging-get style api that returns whether local factory reset is
441    /// enabled.
442    pub fn r#get_enabled(&self, ___deadline: zx::MonotonicInstant) -> Result<bool, fidl::Error> {
443        let _response = self.client.send_query::<
444            fidl::encoding::EmptyPayload,
445            FactoryResetGetEnabledResponse,
446            FactoryResetMarker,
447        >(
448            (),
449            0x46b4c73b3d6be123,
450            fidl::encoding::DynamicFlags::empty(),
451            ___deadline,
452        )?;
453        Ok(_response.fdr_enabled)
454    }
455}
456
457#[cfg(target_os = "fuchsia")]
458impl From<FactoryResetSynchronousProxy> for zx::NullableHandle {
459    fn from(value: FactoryResetSynchronousProxy) -> Self {
460        value.into_channel().into()
461    }
462}
463
464#[cfg(target_os = "fuchsia")]
465impl From<fidl::Channel> for FactoryResetSynchronousProxy {
466    fn from(value: fidl::Channel) -> Self {
467        Self::new(value)
468    }
469}
470
471#[cfg(target_os = "fuchsia")]
472impl fidl::endpoints::FromClient for FactoryResetSynchronousProxy {
473    type Protocol = FactoryResetMarker;
474
475    fn from_client(value: fidl::endpoints::ClientEnd<FactoryResetMarker>) -> Self {
476        Self::new(value.into_channel())
477    }
478}
479
480#[derive(Debug, Clone)]
481pub struct FactoryResetProxy {
482    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
483}
484
485impl fidl::endpoints::Proxy for FactoryResetProxy {
486    type Protocol = FactoryResetMarker;
487
488    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
489        Self::new(inner)
490    }
491
492    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
493        self.client.into_channel().map_err(|client| Self { client })
494    }
495
496    fn as_channel(&self) -> &::fidl::AsyncChannel {
497        self.client.as_channel()
498    }
499}
500
501impl FactoryResetProxy {
502    /// Create a new Proxy for fuchsia.recovery.policy/FactoryReset.
503    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
504        let protocol_name = <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
505        Self { client: fidl::client::Client::new(channel, protocol_name) }
506    }
507
508    /// Get a Stream of events from the remote end of the protocol.
509    ///
510    /// # Panics
511    ///
512    /// Panics if the event stream was already taken.
513    pub fn take_event_stream(&self) -> FactoryResetEventStream {
514        FactoryResetEventStream { event_receiver: self.client.take_event_receiver() }
515    }
516
517    /// A hanging-get style api that returns whether local factory reset is
518    /// enabled.
519    pub fn r#get_enabled(
520        &self,
521    ) -> fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect> {
522        FactoryResetProxyInterface::r#get_enabled(self)
523    }
524}
525
526impl FactoryResetProxyInterface for FactoryResetProxy {
527    type GetEnabledResponseFut =
528        fidl::client::QueryResponseFut<bool, fidl::encoding::DefaultFuchsiaResourceDialect>;
529    fn r#get_enabled(&self) -> Self::GetEnabledResponseFut {
530        fn _decode(
531            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
532        ) -> Result<bool, fidl::Error> {
533            let _response = fidl::client::decode_transaction_body::<
534                FactoryResetGetEnabledResponse,
535                fidl::encoding::DefaultFuchsiaResourceDialect,
536                0x46b4c73b3d6be123,
537            >(_buf?)?;
538            Ok(_response.fdr_enabled)
539        }
540        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, bool>(
541            (),
542            0x46b4c73b3d6be123,
543            fidl::encoding::DynamicFlags::empty(),
544            _decode,
545        )
546    }
547}
548
549pub struct FactoryResetEventStream {
550    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
551}
552
553impl std::marker::Unpin for FactoryResetEventStream {}
554
555impl futures::stream::FusedStream for FactoryResetEventStream {
556    fn is_terminated(&self) -> bool {
557        self.event_receiver.is_terminated()
558    }
559}
560
561impl futures::Stream for FactoryResetEventStream {
562    type Item = Result<FactoryResetEvent, fidl::Error>;
563
564    fn poll_next(
565        mut self: std::pin::Pin<&mut Self>,
566        cx: &mut std::task::Context<'_>,
567    ) -> std::task::Poll<Option<Self::Item>> {
568        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
569            &mut self.event_receiver,
570            cx
571        )?) {
572            Some(buf) => std::task::Poll::Ready(Some(FactoryResetEvent::decode(buf))),
573            None => std::task::Poll::Ready(None),
574        }
575    }
576}
577
578#[derive(Debug)]
579pub enum FactoryResetEvent {}
580
581impl FactoryResetEvent {
582    /// Decodes a message buffer as a [`FactoryResetEvent`].
583    fn decode(
584        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
585    ) -> Result<FactoryResetEvent, fidl::Error> {
586        let (bytes, _handles) = buf.split_mut();
587        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
588        debug_assert_eq!(tx_header.tx_id, 0);
589        match tx_header.ordinal {
590            _ => Err(fidl::Error::UnknownOrdinal {
591                ordinal: tx_header.ordinal,
592                protocol_name: <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
593            }),
594        }
595    }
596}
597
598/// A Stream of incoming requests for fuchsia.recovery.policy/FactoryReset.
599pub struct FactoryResetRequestStream {
600    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
601    is_terminated: bool,
602}
603
604impl std::marker::Unpin for FactoryResetRequestStream {}
605
606impl futures::stream::FusedStream for FactoryResetRequestStream {
607    fn is_terminated(&self) -> bool {
608        self.is_terminated
609    }
610}
611
612impl fidl::endpoints::RequestStream for FactoryResetRequestStream {
613    type Protocol = FactoryResetMarker;
614    type ControlHandle = FactoryResetControlHandle;
615
616    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
617        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
618    }
619
620    fn control_handle(&self) -> Self::ControlHandle {
621        FactoryResetControlHandle { inner: self.inner.clone() }
622    }
623
624    fn into_inner(
625        self,
626    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
627    {
628        (self.inner, self.is_terminated)
629    }
630
631    fn from_inner(
632        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
633        is_terminated: bool,
634    ) -> Self {
635        Self { inner, is_terminated }
636    }
637}
638
639impl futures::Stream for FactoryResetRequestStream {
640    type Item = Result<FactoryResetRequest, fidl::Error>;
641
642    fn poll_next(
643        mut self: std::pin::Pin<&mut Self>,
644        cx: &mut std::task::Context<'_>,
645    ) -> std::task::Poll<Option<Self::Item>> {
646        let this = &mut *self;
647        if this.inner.check_shutdown(cx) {
648            this.is_terminated = true;
649            return std::task::Poll::Ready(None);
650        }
651        if this.is_terminated {
652            panic!("polled FactoryResetRequestStream after completion");
653        }
654        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
655            |bytes, handles| {
656                match this.inner.channel().read_etc(cx, bytes, handles) {
657                    std::task::Poll::Ready(Ok(())) => {}
658                    std::task::Poll::Pending => return std::task::Poll::Pending,
659                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
660                        this.is_terminated = true;
661                        return std::task::Poll::Ready(None);
662                    }
663                    std::task::Poll::Ready(Err(e)) => {
664                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
665                            e.into(),
666                        ))));
667                    }
668                }
669
670                // A message has been received from the channel
671                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
672
673                std::task::Poll::Ready(Some(match header.ordinal {
674                    0x46b4c73b3d6be123 => {
675                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
676                        let mut req = fidl::new_empty!(
677                            fidl::encoding::EmptyPayload,
678                            fidl::encoding::DefaultFuchsiaResourceDialect
679                        );
680                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
681                        let control_handle =
682                            FactoryResetControlHandle { inner: this.inner.clone() };
683                        Ok(FactoryResetRequest::GetEnabled {
684                            responder: FactoryResetGetEnabledResponder {
685                                control_handle: std::mem::ManuallyDrop::new(control_handle),
686                                tx_id: header.tx_id,
687                            },
688                        })
689                    }
690                    _ => Err(fidl::Error::UnknownOrdinal {
691                        ordinal: header.ordinal,
692                        protocol_name:
693                            <FactoryResetMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
694                    }),
695                }))
696            },
697        )
698    }
699}
700
701/// A protocol for determining whether factory reset can be triggered.
702#[derive(Debug)]
703pub enum FactoryResetRequest {
704    /// A hanging-get style api that returns whether local factory reset is
705    /// enabled.
706    GetEnabled { responder: FactoryResetGetEnabledResponder },
707}
708
709impl FactoryResetRequest {
710    #[allow(irrefutable_let_patterns)]
711    pub fn into_get_enabled(self) -> Option<(FactoryResetGetEnabledResponder)> {
712        if let FactoryResetRequest::GetEnabled { responder } = self {
713            Some((responder))
714        } else {
715            None
716        }
717    }
718
719    /// Name of the method defined in FIDL
720    pub fn method_name(&self) -> &'static str {
721        match *self {
722            FactoryResetRequest::GetEnabled { .. } => "get_enabled",
723        }
724    }
725}
726
727#[derive(Debug, Clone)]
728pub struct FactoryResetControlHandle {
729    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
730}
731
732impl fidl::endpoints::ControlHandle for FactoryResetControlHandle {
733    fn shutdown(&self) {
734        self.inner.shutdown()
735    }
736
737    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
738        self.inner.shutdown_with_epitaph(status)
739    }
740
741    fn is_closed(&self) -> bool {
742        self.inner.channel().is_closed()
743    }
744    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
745        self.inner.channel().on_closed()
746    }
747
748    #[cfg(target_os = "fuchsia")]
749    fn signal_peer(
750        &self,
751        clear_mask: zx::Signals,
752        set_mask: zx::Signals,
753    ) -> Result<(), zx_status::Status> {
754        use fidl::Peered;
755        self.inner.channel().signal_peer(clear_mask, set_mask)
756    }
757}
758
759impl FactoryResetControlHandle {}
760
761#[must_use = "FIDL methods require a response to be sent"]
762#[derive(Debug)]
763pub struct FactoryResetGetEnabledResponder {
764    control_handle: std::mem::ManuallyDrop<FactoryResetControlHandle>,
765    tx_id: u32,
766}
767
768/// Set the the channel to be shutdown (see [`FactoryResetControlHandle::shutdown`])
769/// if the responder is dropped without sending a response, so that the client
770/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
771impl std::ops::Drop for FactoryResetGetEnabledResponder {
772    fn drop(&mut self) {
773        self.control_handle.shutdown();
774        // Safety: drops once, never accessed again
775        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
776    }
777}
778
779impl fidl::endpoints::Responder for FactoryResetGetEnabledResponder {
780    type ControlHandle = FactoryResetControlHandle;
781
782    fn control_handle(&self) -> &FactoryResetControlHandle {
783        &self.control_handle
784    }
785
786    fn drop_without_shutdown(mut self) {
787        // Safety: drops once, never accessed again due to mem::forget
788        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
789        // Prevent Drop from running (which would shut down the channel)
790        std::mem::forget(self);
791    }
792}
793
794impl FactoryResetGetEnabledResponder {
795    /// Sends a response to the FIDL transaction.
796    ///
797    /// Sets the channel to shutdown if an error occurs.
798    pub fn send(self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
799        let _result = self.send_raw(fdr_enabled);
800        if _result.is_err() {
801            self.control_handle.shutdown();
802        }
803        self.drop_without_shutdown();
804        _result
805    }
806
807    /// Similar to "send" but does not shutdown the channel if an error occurs.
808    pub fn send_no_shutdown_on_err(self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
809        let _result = self.send_raw(fdr_enabled);
810        self.drop_without_shutdown();
811        _result
812    }
813
814    fn send_raw(&self, mut fdr_enabled: bool) -> Result<(), fidl::Error> {
815        self.control_handle.inner.send::<FactoryResetGetEnabledResponse>(
816            (fdr_enabled,),
817            self.tx_id,
818            0x46b4c73b3d6be123,
819            fidl::encoding::DynamicFlags::empty(),
820        )
821    }
822}
823
824mod internal {
825    use super::*;
826}