Skip to main content

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