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