Skip to main content

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