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