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