Skip to main content

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