fidl_fuchsia_interop_test/
fidl_fuchsia_interop_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_interop_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct WaiterMarker;
16
17impl fidl::endpoints::ProtocolMarker for WaiterMarker {
18    type Proxy = WaiterProxy;
19    type RequestStream = WaiterRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = WaiterSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.interop.test.Waiter";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for WaiterMarker {}
26
27pub trait WaiterProxyInterface: Send + Sync {
28    fn r#ack(&self) -> Result<(), fidl::Error>;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct WaiterSynchronousProxy {
33    client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for WaiterSynchronousProxy {
38    type Proxy = WaiterProxy;
39    type Protocol = WaiterMarker;
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 WaiterSynchronousProxy {
56    pub fn new(channel: fidl::Channel) -> Self {
57        let protocol_name = <WaiterMarker 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<WaiterEvent, fidl::Error> {
71        WaiterEvent::decode(self.client.wait_for_event(deadline)?)
72    }
73
74    pub fn r#ack(&self) -> Result<(), fidl::Error> {
75        self.client.send::<fidl::encoding::EmptyPayload>(
76            (),
77            0x757877942989532f,
78            fidl::encoding::DynamicFlags::empty(),
79        )
80    }
81}
82
83#[cfg(target_os = "fuchsia")]
84impl From<WaiterSynchronousProxy> for zx::Handle {
85    fn from(value: WaiterSynchronousProxy) -> Self {
86        value.into_channel().into()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl From<fidl::Channel> for WaiterSynchronousProxy {
92    fn from(value: fidl::Channel) -> Self {
93        Self::new(value)
94    }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl fidl::endpoints::FromClient for WaiterSynchronousProxy {
99    type Protocol = WaiterMarker;
100
101    fn from_client(value: fidl::endpoints::ClientEnd<WaiterMarker>) -> Self {
102        Self::new(value.into_channel())
103    }
104}
105
106#[derive(Debug, Clone)]
107pub struct WaiterProxy {
108    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
109}
110
111impl fidl::endpoints::Proxy for WaiterProxy {
112    type Protocol = WaiterMarker;
113
114    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
115        Self::new(inner)
116    }
117
118    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
119        self.client.into_channel().map_err(|client| Self { client })
120    }
121
122    fn as_channel(&self) -> &::fidl::AsyncChannel {
123        self.client.as_channel()
124    }
125}
126
127impl WaiterProxy {
128    /// Create a new Proxy for fuchsia.interop.test/Waiter.
129    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
130        let protocol_name = <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
131        Self { client: fidl::client::Client::new(channel, protocol_name) }
132    }
133
134    /// Get a Stream of events from the remote end of the protocol.
135    ///
136    /// # Panics
137    ///
138    /// Panics if the event stream was already taken.
139    pub fn take_event_stream(&self) -> WaiterEventStream {
140        WaiterEventStream { event_receiver: self.client.take_event_receiver() }
141    }
142
143    pub fn r#ack(&self) -> Result<(), fidl::Error> {
144        WaiterProxyInterface::r#ack(self)
145    }
146}
147
148impl WaiterProxyInterface for WaiterProxy {
149    fn r#ack(&self) -> Result<(), fidl::Error> {
150        self.client.send::<fidl::encoding::EmptyPayload>(
151            (),
152            0x757877942989532f,
153            fidl::encoding::DynamicFlags::empty(),
154        )
155    }
156}
157
158pub struct WaiterEventStream {
159    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
160}
161
162impl std::marker::Unpin for WaiterEventStream {}
163
164impl futures::stream::FusedStream for WaiterEventStream {
165    fn is_terminated(&self) -> bool {
166        self.event_receiver.is_terminated()
167    }
168}
169
170impl futures::Stream for WaiterEventStream {
171    type Item = Result<WaiterEvent, 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(WaiterEvent::decode(buf))),
182            None => std::task::Poll::Ready(None),
183        }
184    }
185}
186
187#[derive(Debug)]
188pub enum WaiterEvent {}
189
190impl WaiterEvent {
191    /// Decodes a message buffer as a [`WaiterEvent`].
192    fn decode(
193        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
194    ) -> Result<WaiterEvent, 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: <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
202            }),
203        }
204    }
205}
206
207/// A Stream of incoming requests for fuchsia.interop.test/Waiter.
208pub struct WaiterRequestStream {
209    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
210    is_terminated: bool,
211}
212
213impl std::marker::Unpin for WaiterRequestStream {}
214
215impl futures::stream::FusedStream for WaiterRequestStream {
216    fn is_terminated(&self) -> bool {
217        self.is_terminated
218    }
219}
220
221impl fidl::endpoints::RequestStream for WaiterRequestStream {
222    type Protocol = WaiterMarker;
223    type ControlHandle = WaiterControlHandle;
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        WaiterControlHandle { 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 WaiterRequestStream {
249    type Item = Result<WaiterRequest, 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 WaiterRequestStream 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                    0x757877942989532f => {
284                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
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 = WaiterControlHandle { inner: this.inner.clone() };
291                        Ok(WaiterRequest::Ack { control_handle })
292                    }
293                    _ => Err(fidl::Error::UnknownOrdinal {
294                        ordinal: header.ordinal,
295                        protocol_name:
296                            <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
297                    }),
298                }))
299            },
300        )
301    }
302}
303
304#[derive(Debug)]
305pub enum WaiterRequest {
306    Ack { control_handle: WaiterControlHandle },
307}
308
309impl WaiterRequest {
310    #[allow(irrefutable_let_patterns)]
311    pub fn into_ack(self) -> Option<(WaiterControlHandle)> {
312        if let WaiterRequest::Ack { control_handle } = self {
313            Some((control_handle))
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            WaiterRequest::Ack { .. } => "ack",
323        }
324    }
325}
326
327#[derive(Debug, Clone)]
328pub struct WaiterControlHandle {
329    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
330}
331
332impl fidl::endpoints::ControlHandle for WaiterControlHandle {
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 WaiterControlHandle {}
359
360mod internal {
361    use super::*;
362}