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