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