Skip to main content

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        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<WaiterEvent, fidl::Error> {
70        WaiterEvent::decode(self.client.wait_for_event::<WaiterMarker>(deadline)?)
71    }
72
73    pub fn r#ack(&self) -> Result<(), fidl::Error> {
74        self.client.send::<fidl::encoding::EmptyPayload>(
75            (),
76            0x757877942989532f,
77            fidl::encoding::DynamicFlags::empty(),
78        )
79    }
80}
81
82#[cfg(target_os = "fuchsia")]
83impl From<WaiterSynchronousProxy> for zx::NullableHandle {
84    fn from(value: WaiterSynchronousProxy) -> Self {
85        value.into_channel().into()
86    }
87}
88
89#[cfg(target_os = "fuchsia")]
90impl From<fidl::Channel> for WaiterSynchronousProxy {
91    fn from(value: fidl::Channel) -> Self {
92        Self::new(value)
93    }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl fidl::endpoints::FromClient for WaiterSynchronousProxy {
98    type Protocol = WaiterMarker;
99
100    fn from_client(value: fidl::endpoints::ClientEnd<WaiterMarker>) -> Self {
101        Self::new(value.into_channel())
102    }
103}
104
105#[derive(Debug, Clone)]
106pub struct WaiterProxy {
107    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
108}
109
110impl fidl::endpoints::Proxy for WaiterProxy {
111    type Protocol = WaiterMarker;
112
113    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
114        Self::new(inner)
115    }
116
117    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
118        self.client.into_channel().map_err(|client| Self { client })
119    }
120
121    fn as_channel(&self) -> &::fidl::AsyncChannel {
122        self.client.as_channel()
123    }
124}
125
126impl WaiterProxy {
127    /// Create a new Proxy for fuchsia.interop.test/Waiter.
128    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
129        let protocol_name = <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
130        Self { client: fidl::client::Client::new(channel, protocol_name) }
131    }
132
133    /// Get a Stream of events from the remote end of the protocol.
134    ///
135    /// # Panics
136    ///
137    /// Panics if the event stream was already taken.
138    pub fn take_event_stream(&self) -> WaiterEventStream {
139        WaiterEventStream { event_receiver: self.client.take_event_receiver() }
140    }
141
142    pub fn r#ack(&self) -> Result<(), fidl::Error> {
143        WaiterProxyInterface::r#ack(self)
144    }
145}
146
147impl WaiterProxyInterface for WaiterProxy {
148    fn r#ack(&self) -> Result<(), fidl::Error> {
149        self.client.send::<fidl::encoding::EmptyPayload>(
150            (),
151            0x757877942989532f,
152            fidl::encoding::DynamicFlags::empty(),
153        )
154    }
155}
156
157pub struct WaiterEventStream {
158    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
159}
160
161impl std::marker::Unpin for WaiterEventStream {}
162
163impl futures::stream::FusedStream for WaiterEventStream {
164    fn is_terminated(&self) -> bool {
165        self.event_receiver.is_terminated()
166    }
167}
168
169impl futures::Stream for WaiterEventStream {
170    type Item = Result<WaiterEvent, fidl::Error>;
171
172    fn poll_next(
173        mut self: std::pin::Pin<&mut Self>,
174        cx: &mut std::task::Context<'_>,
175    ) -> std::task::Poll<Option<Self::Item>> {
176        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
177            &mut self.event_receiver,
178            cx
179        )?) {
180            Some(buf) => std::task::Poll::Ready(Some(WaiterEvent::decode(buf))),
181            None => std::task::Poll::Ready(None),
182        }
183    }
184}
185
186#[derive(Debug)]
187pub enum WaiterEvent {}
188
189impl WaiterEvent {
190    /// Decodes a message buffer as a [`WaiterEvent`].
191    fn decode(
192        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
193    ) -> Result<WaiterEvent, fidl::Error> {
194        let (bytes, _handles) = buf.split_mut();
195        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
196        debug_assert_eq!(tx_header.tx_id, 0);
197        match tx_header.ordinal {
198            _ => Err(fidl::Error::UnknownOrdinal {
199                ordinal: tx_header.ordinal,
200                protocol_name: <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
201            }),
202        }
203    }
204}
205
206/// A Stream of incoming requests for fuchsia.interop.test/Waiter.
207pub struct WaiterRequestStream {
208    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
209    is_terminated: bool,
210}
211
212impl std::marker::Unpin for WaiterRequestStream {}
213
214impl futures::stream::FusedStream for WaiterRequestStream {
215    fn is_terminated(&self) -> bool {
216        self.is_terminated
217    }
218}
219
220impl fidl::endpoints::RequestStream for WaiterRequestStream {
221    type Protocol = WaiterMarker;
222    type ControlHandle = WaiterControlHandle;
223
224    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
225        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
226    }
227
228    fn control_handle(&self) -> Self::ControlHandle {
229        WaiterControlHandle { inner: self.inner.clone() }
230    }
231
232    fn into_inner(
233        self,
234    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
235    {
236        (self.inner, self.is_terminated)
237    }
238
239    fn from_inner(
240        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241        is_terminated: bool,
242    ) -> Self {
243        Self { inner, is_terminated }
244    }
245}
246
247impl futures::Stream for WaiterRequestStream {
248    type Item = Result<WaiterRequest, fidl::Error>;
249
250    fn poll_next(
251        mut self: std::pin::Pin<&mut Self>,
252        cx: &mut std::task::Context<'_>,
253    ) -> std::task::Poll<Option<Self::Item>> {
254        let this = &mut *self;
255        if this.inner.check_shutdown(cx) {
256            this.is_terminated = true;
257            return std::task::Poll::Ready(None);
258        }
259        if this.is_terminated {
260            panic!("polled WaiterRequestStream after completion");
261        }
262        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
263            |bytes, handles| {
264                match this.inner.channel().read_etc(cx, bytes, handles) {
265                    std::task::Poll::Ready(Ok(())) => {}
266                    std::task::Poll::Pending => return std::task::Poll::Pending,
267                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
268                        this.is_terminated = true;
269                        return std::task::Poll::Ready(None);
270                    }
271                    std::task::Poll::Ready(Err(e)) => {
272                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
273                            e.into(),
274                        ))));
275                    }
276                }
277
278                // A message has been received from the channel
279                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
280
281                std::task::Poll::Ready(Some(match header.ordinal {
282                    0x757877942989532f => {
283                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
284                        let mut req = fidl::new_empty!(
285                            fidl::encoding::EmptyPayload,
286                            fidl::encoding::DefaultFuchsiaResourceDialect
287                        );
288                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
289                        let control_handle = WaiterControlHandle { inner: this.inner.clone() };
290                        Ok(WaiterRequest::Ack { control_handle })
291                    }
292                    _ => Err(fidl::Error::UnknownOrdinal {
293                        ordinal: header.ordinal,
294                        protocol_name:
295                            <WaiterMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
296                    }),
297                }))
298            },
299        )
300    }
301}
302
303#[derive(Debug)]
304pub enum WaiterRequest {
305    Ack { control_handle: WaiterControlHandle },
306}
307
308impl WaiterRequest {
309    #[allow(irrefutable_let_patterns)]
310    pub fn into_ack(self) -> Option<(WaiterControlHandle)> {
311        if let WaiterRequest::Ack { control_handle } = self { Some((control_handle)) } else { None }
312    }
313
314    /// Name of the method defined in FIDL
315    pub fn method_name(&self) -> &'static str {
316        match *self {
317            WaiterRequest::Ack { .. } => "ack",
318        }
319    }
320}
321
322#[derive(Debug, Clone)]
323pub struct WaiterControlHandle {
324    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
325}
326
327impl fidl::endpoints::ControlHandle for WaiterControlHandle {
328    fn shutdown(&self) {
329        self.inner.shutdown()
330    }
331
332    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
333        self.inner.shutdown_with_epitaph(status)
334    }
335
336    fn is_closed(&self) -> bool {
337        self.inner.channel().is_closed()
338    }
339    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
340        self.inner.channel().on_closed()
341    }
342
343    #[cfg(target_os = "fuchsia")]
344    fn signal_peer(
345        &self,
346        clear_mask: zx::Signals,
347        set_mask: zx::Signals,
348    ) -> Result<(), zx_status::Status> {
349        use fidl::Peered;
350        self.inner.channel().signal_peer(clear_mask, set_mask)
351    }
352}
353
354impl WaiterControlHandle {}
355
356mod internal {
357    use super::*;
358}