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