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