fidl_fuchsia_ui_input3/
fidl_fuchsia_ui_input3.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_ui_input3_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct KeyboardAddListenerRequest {
16    pub view_ref: fidl_fuchsia_ui_views::ViewRef,
17    pub listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
21    for KeyboardAddListenerRequest
22{
23}
24
25#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
26pub struct KeyEventInjectorMarker;
27
28impl fidl::endpoints::ProtocolMarker for KeyEventInjectorMarker {
29    type Proxy = KeyEventInjectorProxy;
30    type RequestStream = KeyEventInjectorRequestStream;
31    #[cfg(target_os = "fuchsia")]
32    type SynchronousProxy = KeyEventInjectorSynchronousProxy;
33
34    const DEBUG_NAME: &'static str = "fuchsia.ui.input3.KeyEventInjector";
35}
36impl fidl::endpoints::DiscoverableProtocolMarker for KeyEventInjectorMarker {}
37
38pub trait KeyEventInjectorProxyInterface: Send + Sync {
39    type InjectResponseFut: std::future::Future<Output = Result<KeyEventStatus, fidl::Error>> + Send;
40    fn r#inject(&self, key_event: &KeyEvent) -> Self::InjectResponseFut;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct KeyEventInjectorSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for KeyEventInjectorSynchronousProxy {
50    type Proxy = KeyEventInjectorProxy;
51    type Protocol = KeyEventInjectorMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl KeyEventInjectorSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <KeyEventInjectorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<KeyEventInjectorEvent, fidl::Error> {
83        KeyEventInjectorEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    /// Inject an event into the keyboard subsystem.
87    ///
88    /// # Returns
89    /// * `HANDLED` if the keyboard subsystem delivered the event to a consumer,
90    ///   and the consumer reported that it `HANDLED` the event
91    /// * `NOT_HANDLED` if the keyboard subsystem did not deliever the event to
92    ///   any consumers, or no consumer reported that it `HANDLED` the event.
93    pub fn r#inject(
94        &self,
95        mut key_event: &KeyEvent,
96        ___deadline: zx::MonotonicInstant,
97    ) -> Result<KeyEventStatus, fidl::Error> {
98        let _response = self
99            .client
100            .send_query::<KeyEventInjectorInjectRequest, KeyEventInjectorInjectResponse>(
101                (key_event,),
102                0x1eb2c0d795c68949,
103                fidl::encoding::DynamicFlags::empty(),
104                ___deadline,
105            )?;
106        Ok(_response.status)
107    }
108}
109
110#[derive(Debug, Clone)]
111pub struct KeyEventInjectorProxy {
112    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
113}
114
115impl fidl::endpoints::Proxy for KeyEventInjectorProxy {
116    type Protocol = KeyEventInjectorMarker;
117
118    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
119        Self::new(inner)
120    }
121
122    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
123        self.client.into_channel().map_err(|client| Self { client })
124    }
125
126    fn as_channel(&self) -> &::fidl::AsyncChannel {
127        self.client.as_channel()
128    }
129}
130
131impl KeyEventInjectorProxy {
132    /// Create a new Proxy for fuchsia.ui.input3/KeyEventInjector.
133    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
134        let protocol_name = <KeyEventInjectorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
135        Self { client: fidl::client::Client::new(channel, protocol_name) }
136    }
137
138    /// Get a Stream of events from the remote end of the protocol.
139    ///
140    /// # Panics
141    ///
142    /// Panics if the event stream was already taken.
143    pub fn take_event_stream(&self) -> KeyEventInjectorEventStream {
144        KeyEventInjectorEventStream { event_receiver: self.client.take_event_receiver() }
145    }
146
147    /// Inject an event into the keyboard subsystem.
148    ///
149    /// # Returns
150    /// * `HANDLED` if the keyboard subsystem delivered the event to a consumer,
151    ///   and the consumer reported that it `HANDLED` the event
152    /// * `NOT_HANDLED` if the keyboard subsystem did not deliever the event to
153    ///   any consumers, or no consumer reported that it `HANDLED` the event.
154    pub fn r#inject(
155        &self,
156        mut key_event: &KeyEvent,
157    ) -> fidl::client::QueryResponseFut<KeyEventStatus, fidl::encoding::DefaultFuchsiaResourceDialect>
158    {
159        KeyEventInjectorProxyInterface::r#inject(self, key_event)
160    }
161}
162
163impl KeyEventInjectorProxyInterface for KeyEventInjectorProxy {
164    type InjectResponseFut = fidl::client::QueryResponseFut<
165        KeyEventStatus,
166        fidl::encoding::DefaultFuchsiaResourceDialect,
167    >;
168    fn r#inject(&self, mut key_event: &KeyEvent) -> Self::InjectResponseFut {
169        fn _decode(
170            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
171        ) -> Result<KeyEventStatus, fidl::Error> {
172            let _response = fidl::client::decode_transaction_body::<
173                KeyEventInjectorInjectResponse,
174                fidl::encoding::DefaultFuchsiaResourceDialect,
175                0x1eb2c0d795c68949,
176            >(_buf?)?;
177            Ok(_response.status)
178        }
179        self.client.send_query_and_decode::<KeyEventInjectorInjectRequest, KeyEventStatus>(
180            (key_event,),
181            0x1eb2c0d795c68949,
182            fidl::encoding::DynamicFlags::empty(),
183            _decode,
184        )
185    }
186}
187
188pub struct KeyEventInjectorEventStream {
189    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
190}
191
192impl std::marker::Unpin for KeyEventInjectorEventStream {}
193
194impl futures::stream::FusedStream for KeyEventInjectorEventStream {
195    fn is_terminated(&self) -> bool {
196        self.event_receiver.is_terminated()
197    }
198}
199
200impl futures::Stream for KeyEventInjectorEventStream {
201    type Item = Result<KeyEventInjectorEvent, fidl::Error>;
202
203    fn poll_next(
204        mut self: std::pin::Pin<&mut Self>,
205        cx: &mut std::task::Context<'_>,
206    ) -> std::task::Poll<Option<Self::Item>> {
207        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
208            &mut self.event_receiver,
209            cx
210        )?) {
211            Some(buf) => std::task::Poll::Ready(Some(KeyEventInjectorEvent::decode(buf))),
212            None => std::task::Poll::Ready(None),
213        }
214    }
215}
216
217#[derive(Debug)]
218pub enum KeyEventInjectorEvent {}
219
220impl KeyEventInjectorEvent {
221    /// Decodes a message buffer as a [`KeyEventInjectorEvent`].
222    fn decode(
223        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
224    ) -> Result<KeyEventInjectorEvent, fidl::Error> {
225        let (bytes, _handles) = buf.split_mut();
226        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
227        debug_assert_eq!(tx_header.tx_id, 0);
228        match tx_header.ordinal {
229            _ => Err(fidl::Error::UnknownOrdinal {
230                ordinal: tx_header.ordinal,
231                protocol_name:
232                    <KeyEventInjectorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
233            }),
234        }
235    }
236}
237
238/// A Stream of incoming requests for fuchsia.ui.input3/KeyEventInjector.
239pub struct KeyEventInjectorRequestStream {
240    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
241    is_terminated: bool,
242}
243
244impl std::marker::Unpin for KeyEventInjectorRequestStream {}
245
246impl futures::stream::FusedStream for KeyEventInjectorRequestStream {
247    fn is_terminated(&self) -> bool {
248        self.is_terminated
249    }
250}
251
252impl fidl::endpoints::RequestStream for KeyEventInjectorRequestStream {
253    type Protocol = KeyEventInjectorMarker;
254    type ControlHandle = KeyEventInjectorControlHandle;
255
256    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
257        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
258    }
259
260    fn control_handle(&self) -> Self::ControlHandle {
261        KeyEventInjectorControlHandle { inner: self.inner.clone() }
262    }
263
264    fn into_inner(
265        self,
266    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
267    {
268        (self.inner, self.is_terminated)
269    }
270
271    fn from_inner(
272        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
273        is_terminated: bool,
274    ) -> Self {
275        Self { inner, is_terminated }
276    }
277}
278
279impl futures::Stream for KeyEventInjectorRequestStream {
280    type Item = Result<KeyEventInjectorRequest, fidl::Error>;
281
282    fn poll_next(
283        mut self: std::pin::Pin<&mut Self>,
284        cx: &mut std::task::Context<'_>,
285    ) -> std::task::Poll<Option<Self::Item>> {
286        let this = &mut *self;
287        if this.inner.check_shutdown(cx) {
288            this.is_terminated = true;
289            return std::task::Poll::Ready(None);
290        }
291        if this.is_terminated {
292            panic!("polled KeyEventInjectorRequestStream after completion");
293        }
294        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
295            |bytes, handles| {
296                match this.inner.channel().read_etc(cx, bytes, handles) {
297                    std::task::Poll::Ready(Ok(())) => {}
298                    std::task::Poll::Pending => return std::task::Poll::Pending,
299                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
300                        this.is_terminated = true;
301                        return std::task::Poll::Ready(None);
302                    }
303                    std::task::Poll::Ready(Err(e)) => {
304                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
305                            e.into(),
306                        ))))
307                    }
308                }
309
310                // A message has been received from the channel
311                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
312
313                std::task::Poll::Ready(Some(match header.ordinal {
314                    0x1eb2c0d795c68949 => {
315                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
316                        let mut req = fidl::new_empty!(
317                            KeyEventInjectorInjectRequest,
318                            fidl::encoding::DefaultFuchsiaResourceDialect
319                        );
320                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<KeyEventInjectorInjectRequest>(&header, _body_bytes, handles, &mut req)?;
321                        let control_handle =
322                            KeyEventInjectorControlHandle { inner: this.inner.clone() };
323                        Ok(KeyEventInjectorRequest::Inject {
324                            key_event: req.key_event,
325
326                            responder: KeyEventInjectorInjectResponder {
327                                control_handle: std::mem::ManuallyDrop::new(control_handle),
328                                tx_id: header.tx_id,
329                            },
330                        })
331                    }
332                    _ => Err(fidl::Error::UnknownOrdinal {
333                        ordinal: header.ordinal,
334                        protocol_name:
335                            <KeyEventInjectorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
336                    }),
337                }))
338            },
339        )
340    }
341}
342
343/// Provides the ability to inject `KeyEvent`s into the keyboard subsystem.
344///
345/// # Roles
346/// This protocol will typically be:
347/// * Implemented by platform components which process and deliver keyboard
348///   events.
349/// * Consumed by components which originiate keyboard events. E.g.
350///   an on-screen keyboard, or the Session Framework Input Pipeline.
351///
352/// # Related protocols
353/// This protocol should be using in preference to legacy protocols which provide
354/// similar functionality. Specifically, this means this protocol should be preferred
355/// over
356/// * `fuchsia.ui.input.ImeService` which provides `InjectInput()`, `DispatchKey()`,
357///   and `DispatchKey3()`
358/// * `fuchsia.ui.input.InputMethodEditor`, which provides `InjectInput()` and
359///   `DispatchKey3()`
360///
361/// # Notes
362/// Products should take care to limit access to this protocol, as events injected
363/// with this protocol are indistinguishable from those coming from physical devices.
364#[derive(Debug)]
365pub enum KeyEventInjectorRequest {
366    /// Inject an event into the keyboard subsystem.
367    ///
368    /// # Returns
369    /// * `HANDLED` if the keyboard subsystem delivered the event to a consumer,
370    ///   and the consumer reported that it `HANDLED` the event
371    /// * `NOT_HANDLED` if the keyboard subsystem did not deliever the event to
372    ///   any consumers, or no consumer reported that it `HANDLED` the event.
373    Inject { key_event: KeyEvent, responder: KeyEventInjectorInjectResponder },
374}
375
376impl KeyEventInjectorRequest {
377    #[allow(irrefutable_let_patterns)]
378    pub fn into_inject(self) -> Option<(KeyEvent, KeyEventInjectorInjectResponder)> {
379        if let KeyEventInjectorRequest::Inject { key_event, responder } = self {
380            Some((key_event, responder))
381        } else {
382            None
383        }
384    }
385
386    /// Name of the method defined in FIDL
387    pub fn method_name(&self) -> &'static str {
388        match *self {
389            KeyEventInjectorRequest::Inject { .. } => "inject",
390        }
391    }
392}
393
394#[derive(Debug, Clone)]
395pub struct KeyEventInjectorControlHandle {
396    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
397}
398
399impl fidl::endpoints::ControlHandle for KeyEventInjectorControlHandle {
400    fn shutdown(&self) {
401        self.inner.shutdown()
402    }
403    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
404        self.inner.shutdown_with_epitaph(status)
405    }
406
407    fn is_closed(&self) -> bool {
408        self.inner.channel().is_closed()
409    }
410    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
411        self.inner.channel().on_closed()
412    }
413
414    #[cfg(target_os = "fuchsia")]
415    fn signal_peer(
416        &self,
417        clear_mask: zx::Signals,
418        set_mask: zx::Signals,
419    ) -> Result<(), zx_status::Status> {
420        use fidl::Peered;
421        self.inner.channel().signal_peer(clear_mask, set_mask)
422    }
423}
424
425impl KeyEventInjectorControlHandle {}
426
427#[must_use = "FIDL methods require a response to be sent"]
428#[derive(Debug)]
429pub struct KeyEventInjectorInjectResponder {
430    control_handle: std::mem::ManuallyDrop<KeyEventInjectorControlHandle>,
431    tx_id: u32,
432}
433
434/// Set the the channel to be shutdown (see [`KeyEventInjectorControlHandle::shutdown`])
435/// if the responder is dropped without sending a response, so that the client
436/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
437impl std::ops::Drop for KeyEventInjectorInjectResponder {
438    fn drop(&mut self) {
439        self.control_handle.shutdown();
440        // Safety: drops once, never accessed again
441        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
442    }
443}
444
445impl fidl::endpoints::Responder for KeyEventInjectorInjectResponder {
446    type ControlHandle = KeyEventInjectorControlHandle;
447
448    fn control_handle(&self) -> &KeyEventInjectorControlHandle {
449        &self.control_handle
450    }
451
452    fn drop_without_shutdown(mut self) {
453        // Safety: drops once, never accessed again due to mem::forget
454        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
455        // Prevent Drop from running (which would shut down the channel)
456        std::mem::forget(self);
457    }
458}
459
460impl KeyEventInjectorInjectResponder {
461    /// Sends a response to the FIDL transaction.
462    ///
463    /// Sets the channel to shutdown if an error occurs.
464    pub fn send(self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
465        let _result = self.send_raw(status);
466        if _result.is_err() {
467            self.control_handle.shutdown();
468        }
469        self.drop_without_shutdown();
470        _result
471    }
472
473    /// Similar to "send" but does not shutdown the channel if an error occurs.
474    pub fn send_no_shutdown_on_err(self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
475        let _result = self.send_raw(status);
476        self.drop_without_shutdown();
477        _result
478    }
479
480    fn send_raw(&self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
481        self.control_handle.inner.send::<KeyEventInjectorInjectResponse>(
482            (status,),
483            self.tx_id,
484            0x1eb2c0d795c68949,
485            fidl::encoding::DynamicFlags::empty(),
486        )
487    }
488}
489
490#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
491pub struct KeyboardMarker;
492
493impl fidl::endpoints::ProtocolMarker for KeyboardMarker {
494    type Proxy = KeyboardProxy;
495    type RequestStream = KeyboardRequestStream;
496    #[cfg(target_os = "fuchsia")]
497    type SynchronousProxy = KeyboardSynchronousProxy;
498
499    const DEBUG_NAME: &'static str = "fuchsia.ui.input3.Keyboard";
500}
501impl fidl::endpoints::DiscoverableProtocolMarker for KeyboardMarker {}
502
503pub trait KeyboardProxyInterface: Send + Sync {
504    type AddListenerResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
505    fn r#add_listener(
506        &self,
507        view_ref: fidl_fuchsia_ui_views::ViewRef,
508        listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
509    ) -> Self::AddListenerResponseFut;
510}
511#[derive(Debug)]
512#[cfg(target_os = "fuchsia")]
513pub struct KeyboardSynchronousProxy {
514    client: fidl::client::sync::Client,
515}
516
517#[cfg(target_os = "fuchsia")]
518impl fidl::endpoints::SynchronousProxy for KeyboardSynchronousProxy {
519    type Proxy = KeyboardProxy;
520    type Protocol = KeyboardMarker;
521
522    fn from_channel(inner: fidl::Channel) -> Self {
523        Self::new(inner)
524    }
525
526    fn into_channel(self) -> fidl::Channel {
527        self.client.into_channel()
528    }
529
530    fn as_channel(&self) -> &fidl::Channel {
531        self.client.as_channel()
532    }
533}
534
535#[cfg(target_os = "fuchsia")]
536impl KeyboardSynchronousProxy {
537    pub fn new(channel: fidl::Channel) -> Self {
538        let protocol_name = <KeyboardMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
539        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
540    }
541
542    pub fn into_channel(self) -> fidl::Channel {
543        self.client.into_channel()
544    }
545
546    /// Waits until an event arrives and returns it. It is safe for other
547    /// threads to make concurrent requests while waiting for an event.
548    pub fn wait_for_event(
549        &self,
550        deadline: zx::MonotonicInstant,
551    ) -> Result<KeyboardEvent, fidl::Error> {
552        KeyboardEvent::decode(self.client.wait_for_event(deadline)?)
553    }
554
555    /// Add a key event listener for the specified View.
556    /// If multiple listeners are added, each will receive key events independently and
557    /// should respond with a `Status`.
558    ///
559    /// The client calling `AddListener` should keep the connection to `Keyboard` alive
560    /// for as long as the events from `KeyboardListener` need to be received.  Dropping the
561    /// connection to the `Keyboard` protocol will terminate `KeyboardListener` as well.
562    pub fn r#add_listener(
563        &self,
564        mut view_ref: fidl_fuchsia_ui_views::ViewRef,
565        mut listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
566        ___deadline: zx::MonotonicInstant,
567    ) -> Result<(), fidl::Error> {
568        let _response =
569            self.client.send_query::<KeyboardAddListenerRequest, fidl::encoding::EmptyPayload>(
570                (&mut view_ref, listener),
571                0x3bc57587fc9b3d22,
572                fidl::encoding::DynamicFlags::empty(),
573                ___deadline,
574            )?;
575        Ok(_response)
576    }
577}
578
579#[derive(Debug, Clone)]
580pub struct KeyboardProxy {
581    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
582}
583
584impl fidl::endpoints::Proxy for KeyboardProxy {
585    type Protocol = KeyboardMarker;
586
587    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
588        Self::new(inner)
589    }
590
591    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
592        self.client.into_channel().map_err(|client| Self { client })
593    }
594
595    fn as_channel(&self) -> &::fidl::AsyncChannel {
596        self.client.as_channel()
597    }
598}
599
600impl KeyboardProxy {
601    /// Create a new Proxy for fuchsia.ui.input3/Keyboard.
602    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
603        let protocol_name = <KeyboardMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
604        Self { client: fidl::client::Client::new(channel, protocol_name) }
605    }
606
607    /// Get a Stream of events from the remote end of the protocol.
608    ///
609    /// # Panics
610    ///
611    /// Panics if the event stream was already taken.
612    pub fn take_event_stream(&self) -> KeyboardEventStream {
613        KeyboardEventStream { event_receiver: self.client.take_event_receiver() }
614    }
615
616    /// Add a key event listener for the specified View.
617    /// If multiple listeners are added, each will receive key events independently and
618    /// should respond with a `Status`.
619    ///
620    /// The client calling `AddListener` should keep the connection to `Keyboard` alive
621    /// for as long as the events from `KeyboardListener` need to be received.  Dropping the
622    /// connection to the `Keyboard` protocol will terminate `KeyboardListener` as well.
623    pub fn r#add_listener(
624        &self,
625        mut view_ref: fidl_fuchsia_ui_views::ViewRef,
626        mut listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
627    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
628        KeyboardProxyInterface::r#add_listener(self, view_ref, listener)
629    }
630}
631
632impl KeyboardProxyInterface for KeyboardProxy {
633    type AddListenerResponseFut =
634        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
635    fn r#add_listener(
636        &self,
637        mut view_ref: fidl_fuchsia_ui_views::ViewRef,
638        mut listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
639    ) -> Self::AddListenerResponseFut {
640        fn _decode(
641            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
642        ) -> Result<(), fidl::Error> {
643            let _response = fidl::client::decode_transaction_body::<
644                fidl::encoding::EmptyPayload,
645                fidl::encoding::DefaultFuchsiaResourceDialect,
646                0x3bc57587fc9b3d22,
647            >(_buf?)?;
648            Ok(_response)
649        }
650        self.client.send_query_and_decode::<KeyboardAddListenerRequest, ()>(
651            (&mut view_ref, listener),
652            0x3bc57587fc9b3d22,
653            fidl::encoding::DynamicFlags::empty(),
654            _decode,
655        )
656    }
657}
658
659pub struct KeyboardEventStream {
660    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
661}
662
663impl std::marker::Unpin for KeyboardEventStream {}
664
665impl futures::stream::FusedStream for KeyboardEventStream {
666    fn is_terminated(&self) -> bool {
667        self.event_receiver.is_terminated()
668    }
669}
670
671impl futures::Stream for KeyboardEventStream {
672    type Item = Result<KeyboardEvent, fidl::Error>;
673
674    fn poll_next(
675        mut self: std::pin::Pin<&mut Self>,
676        cx: &mut std::task::Context<'_>,
677    ) -> std::task::Poll<Option<Self::Item>> {
678        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
679            &mut self.event_receiver,
680            cx
681        )?) {
682            Some(buf) => std::task::Poll::Ready(Some(KeyboardEvent::decode(buf))),
683            None => std::task::Poll::Ready(None),
684        }
685    }
686}
687
688#[derive(Debug)]
689pub enum KeyboardEvent {}
690
691impl KeyboardEvent {
692    /// Decodes a message buffer as a [`KeyboardEvent`].
693    fn decode(
694        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
695    ) -> Result<KeyboardEvent, fidl::Error> {
696        let (bytes, _handles) = buf.split_mut();
697        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
698        debug_assert_eq!(tx_header.tx_id, 0);
699        match tx_header.ordinal {
700            _ => Err(fidl::Error::UnknownOrdinal {
701                ordinal: tx_header.ordinal,
702                protocol_name: <KeyboardMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
703            }),
704        }
705    }
706}
707
708/// A Stream of incoming requests for fuchsia.ui.input3/Keyboard.
709pub struct KeyboardRequestStream {
710    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
711    is_terminated: bool,
712}
713
714impl std::marker::Unpin for KeyboardRequestStream {}
715
716impl futures::stream::FusedStream for KeyboardRequestStream {
717    fn is_terminated(&self) -> bool {
718        self.is_terminated
719    }
720}
721
722impl fidl::endpoints::RequestStream for KeyboardRequestStream {
723    type Protocol = KeyboardMarker;
724    type ControlHandle = KeyboardControlHandle;
725
726    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
727        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
728    }
729
730    fn control_handle(&self) -> Self::ControlHandle {
731        KeyboardControlHandle { inner: self.inner.clone() }
732    }
733
734    fn into_inner(
735        self,
736    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
737    {
738        (self.inner, self.is_terminated)
739    }
740
741    fn from_inner(
742        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
743        is_terminated: bool,
744    ) -> Self {
745        Self { inner, is_terminated }
746    }
747}
748
749impl futures::Stream for KeyboardRequestStream {
750    type Item = Result<KeyboardRequest, fidl::Error>;
751
752    fn poll_next(
753        mut self: std::pin::Pin<&mut Self>,
754        cx: &mut std::task::Context<'_>,
755    ) -> std::task::Poll<Option<Self::Item>> {
756        let this = &mut *self;
757        if this.inner.check_shutdown(cx) {
758            this.is_terminated = true;
759            return std::task::Poll::Ready(None);
760        }
761        if this.is_terminated {
762            panic!("polled KeyboardRequestStream after completion");
763        }
764        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
765            |bytes, handles| {
766                match this.inner.channel().read_etc(cx, bytes, handles) {
767                    std::task::Poll::Ready(Ok(())) => {}
768                    std::task::Poll::Pending => return std::task::Poll::Pending,
769                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
770                        this.is_terminated = true;
771                        return std::task::Poll::Ready(None);
772                    }
773                    std::task::Poll::Ready(Err(e)) => {
774                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
775                            e.into(),
776                        ))))
777                    }
778                }
779
780                // A message has been received from the channel
781                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
782
783                std::task::Poll::Ready(Some(match header.ordinal {
784                    0x3bc57587fc9b3d22 => {
785                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
786                        let mut req = fidl::new_empty!(
787                            KeyboardAddListenerRequest,
788                            fidl::encoding::DefaultFuchsiaResourceDialect
789                        );
790                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<KeyboardAddListenerRequest>(&header, _body_bytes, handles, &mut req)?;
791                        let control_handle = KeyboardControlHandle { inner: this.inner.clone() };
792                        Ok(KeyboardRequest::AddListener {
793                            view_ref: req.view_ref,
794                            listener: req.listener,
795
796                            responder: KeyboardAddListenerResponder {
797                                control_handle: std::mem::ManuallyDrop::new(control_handle),
798                                tx_id: header.tx_id,
799                            },
800                        })
801                    }
802                    _ => Err(fidl::Error::UnknownOrdinal {
803                        ordinal: header.ordinal,
804                        protocol_name:
805                            <KeyboardMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
806                    }),
807                }))
808            },
809        )
810    }
811}
812
813/// Components may request this service from their namespace to be notified of
814/// physical key events.
815#[derive(Debug)]
816pub enum KeyboardRequest {
817    /// Add a key event listener for the specified View.
818    /// If multiple listeners are added, each will receive key events independently and
819    /// should respond with a `Status`.
820    ///
821    /// The client calling `AddListener` should keep the connection to `Keyboard` alive
822    /// for as long as the events from `KeyboardListener` need to be received.  Dropping the
823    /// connection to the `Keyboard` protocol will terminate `KeyboardListener` as well.
824    AddListener {
825        view_ref: fidl_fuchsia_ui_views::ViewRef,
826        listener: fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
827        responder: KeyboardAddListenerResponder,
828    },
829}
830
831impl KeyboardRequest {
832    #[allow(irrefutable_let_patterns)]
833    pub fn into_add_listener(
834        self,
835    ) -> Option<(
836        fidl_fuchsia_ui_views::ViewRef,
837        fidl::endpoints::ClientEnd<KeyboardListenerMarker>,
838        KeyboardAddListenerResponder,
839    )> {
840        if let KeyboardRequest::AddListener { view_ref, listener, responder } = self {
841            Some((view_ref, listener, responder))
842        } else {
843            None
844        }
845    }
846
847    /// Name of the method defined in FIDL
848    pub fn method_name(&self) -> &'static str {
849        match *self {
850            KeyboardRequest::AddListener { .. } => "add_listener",
851        }
852    }
853}
854
855#[derive(Debug, Clone)]
856pub struct KeyboardControlHandle {
857    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
858}
859
860impl fidl::endpoints::ControlHandle for KeyboardControlHandle {
861    fn shutdown(&self) {
862        self.inner.shutdown()
863    }
864    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
865        self.inner.shutdown_with_epitaph(status)
866    }
867
868    fn is_closed(&self) -> bool {
869        self.inner.channel().is_closed()
870    }
871    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
872        self.inner.channel().on_closed()
873    }
874
875    #[cfg(target_os = "fuchsia")]
876    fn signal_peer(
877        &self,
878        clear_mask: zx::Signals,
879        set_mask: zx::Signals,
880    ) -> Result<(), zx_status::Status> {
881        use fidl::Peered;
882        self.inner.channel().signal_peer(clear_mask, set_mask)
883    }
884}
885
886impl KeyboardControlHandle {}
887
888#[must_use = "FIDL methods require a response to be sent"]
889#[derive(Debug)]
890pub struct KeyboardAddListenerResponder {
891    control_handle: std::mem::ManuallyDrop<KeyboardControlHandle>,
892    tx_id: u32,
893}
894
895/// Set the the channel to be shutdown (see [`KeyboardControlHandle::shutdown`])
896/// if the responder is dropped without sending a response, so that the client
897/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
898impl std::ops::Drop for KeyboardAddListenerResponder {
899    fn drop(&mut self) {
900        self.control_handle.shutdown();
901        // Safety: drops once, never accessed again
902        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
903    }
904}
905
906impl fidl::endpoints::Responder for KeyboardAddListenerResponder {
907    type ControlHandle = KeyboardControlHandle;
908
909    fn control_handle(&self) -> &KeyboardControlHandle {
910        &self.control_handle
911    }
912
913    fn drop_without_shutdown(mut self) {
914        // Safety: drops once, never accessed again due to mem::forget
915        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
916        // Prevent Drop from running (which would shut down the channel)
917        std::mem::forget(self);
918    }
919}
920
921impl KeyboardAddListenerResponder {
922    /// Sends a response to the FIDL transaction.
923    ///
924    /// Sets the channel to shutdown if an error occurs.
925    pub fn send(self) -> Result<(), fidl::Error> {
926        let _result = self.send_raw();
927        if _result.is_err() {
928            self.control_handle.shutdown();
929        }
930        self.drop_without_shutdown();
931        _result
932    }
933
934    /// Similar to "send" but does not shutdown the channel if an error occurs.
935    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
936        let _result = self.send_raw();
937        self.drop_without_shutdown();
938        _result
939    }
940
941    fn send_raw(&self) -> Result<(), fidl::Error> {
942        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
943            (),
944            self.tx_id,
945            0x3bc57587fc9b3d22,
946            fidl::encoding::DynamicFlags::empty(),
947        )
948    }
949}
950
951#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
952pub struct KeyboardListenerMarker;
953
954impl fidl::endpoints::ProtocolMarker for KeyboardListenerMarker {
955    type Proxy = KeyboardListenerProxy;
956    type RequestStream = KeyboardListenerRequestStream;
957    #[cfg(target_os = "fuchsia")]
958    type SynchronousProxy = KeyboardListenerSynchronousProxy;
959
960    const DEBUG_NAME: &'static str = "(anonymous) KeyboardListener";
961}
962
963pub trait KeyboardListenerProxyInterface: Send + Sync {
964    type OnKeyEventResponseFut: std::future::Future<Output = Result<KeyEventStatus, fidl::Error>>
965        + Send;
966    fn r#on_key_event(&self, event: &KeyEvent) -> Self::OnKeyEventResponseFut;
967}
968#[derive(Debug)]
969#[cfg(target_os = "fuchsia")]
970pub struct KeyboardListenerSynchronousProxy {
971    client: fidl::client::sync::Client,
972}
973
974#[cfg(target_os = "fuchsia")]
975impl fidl::endpoints::SynchronousProxy for KeyboardListenerSynchronousProxy {
976    type Proxy = KeyboardListenerProxy;
977    type Protocol = KeyboardListenerMarker;
978
979    fn from_channel(inner: fidl::Channel) -> Self {
980        Self::new(inner)
981    }
982
983    fn into_channel(self) -> fidl::Channel {
984        self.client.into_channel()
985    }
986
987    fn as_channel(&self) -> &fidl::Channel {
988        self.client.as_channel()
989    }
990}
991
992#[cfg(target_os = "fuchsia")]
993impl KeyboardListenerSynchronousProxy {
994    pub fn new(channel: fidl::Channel) -> Self {
995        let protocol_name = <KeyboardListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
996        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
997    }
998
999    pub fn into_channel(self) -> fidl::Channel {
1000        self.client.into_channel()
1001    }
1002
1003    /// Waits until an event arrives and returns it. It is safe for other
1004    /// threads to make concurrent requests while waiting for an event.
1005    pub fn wait_for_event(
1006        &self,
1007        deadline: zx::MonotonicInstant,
1008    ) -> Result<KeyboardListenerEvent, fidl::Error> {
1009        KeyboardListenerEvent::decode(self.client.wait_for_event(deadline)?)
1010    }
1011
1012    /// Called when a key event takes place, such as key press or release.
1013    ///
1014    /// Protocol implementers must respond to acknowledge the event by returning Status
1015    /// in a timely manner, i.e. not introducing significant delays to the
1016    /// input pipeline (typically 10s of milliseconds).
1017    ///
1018    /// Returning `NOT_HANDLED` means the event may be offered to other
1019    /// clients of other related APIs.
1020    ///
1021    /// Clients that do not acknowledge their events will eventually be disconnected.
1022    ///
1023    /// Notification is only dispatched to a view that has focus. No other views,
1024    /// including parents or children, will get notified specifically via `OnKeyEvent`.
1025    pub fn r#on_key_event(
1026        &self,
1027        mut event: &KeyEvent,
1028        ___deadline: zx::MonotonicInstant,
1029    ) -> Result<KeyEventStatus, fidl::Error> {
1030        let _response = self
1031            .client
1032            .send_query::<KeyboardListenerOnKeyEventRequest, KeyboardListenerOnKeyEventResponse>(
1033                (event,),
1034                0x2ef2ee16ac509093,
1035                fidl::encoding::DynamicFlags::empty(),
1036                ___deadline,
1037            )?;
1038        Ok(_response.status)
1039    }
1040}
1041
1042#[derive(Debug, Clone)]
1043pub struct KeyboardListenerProxy {
1044    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1045}
1046
1047impl fidl::endpoints::Proxy for KeyboardListenerProxy {
1048    type Protocol = KeyboardListenerMarker;
1049
1050    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1051        Self::new(inner)
1052    }
1053
1054    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1055        self.client.into_channel().map_err(|client| Self { client })
1056    }
1057
1058    fn as_channel(&self) -> &::fidl::AsyncChannel {
1059        self.client.as_channel()
1060    }
1061}
1062
1063impl KeyboardListenerProxy {
1064    /// Create a new Proxy for fuchsia.ui.input3/KeyboardListener.
1065    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1066        let protocol_name = <KeyboardListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1067        Self { client: fidl::client::Client::new(channel, protocol_name) }
1068    }
1069
1070    /// Get a Stream of events from the remote end of the protocol.
1071    ///
1072    /// # Panics
1073    ///
1074    /// Panics if the event stream was already taken.
1075    pub fn take_event_stream(&self) -> KeyboardListenerEventStream {
1076        KeyboardListenerEventStream { event_receiver: self.client.take_event_receiver() }
1077    }
1078
1079    /// Called when a key event takes place, such as key press or release.
1080    ///
1081    /// Protocol implementers must respond to acknowledge the event by returning Status
1082    /// in a timely manner, i.e. not introducing significant delays to the
1083    /// input pipeline (typically 10s of milliseconds).
1084    ///
1085    /// Returning `NOT_HANDLED` means the event may be offered to other
1086    /// clients of other related APIs.
1087    ///
1088    /// Clients that do not acknowledge their events will eventually be disconnected.
1089    ///
1090    /// Notification is only dispatched to a view that has focus. No other views,
1091    /// including parents or children, will get notified specifically via `OnKeyEvent`.
1092    pub fn r#on_key_event(
1093        &self,
1094        mut event: &KeyEvent,
1095    ) -> fidl::client::QueryResponseFut<KeyEventStatus, fidl::encoding::DefaultFuchsiaResourceDialect>
1096    {
1097        KeyboardListenerProxyInterface::r#on_key_event(self, event)
1098    }
1099}
1100
1101impl KeyboardListenerProxyInterface for KeyboardListenerProxy {
1102    type OnKeyEventResponseFut = fidl::client::QueryResponseFut<
1103        KeyEventStatus,
1104        fidl::encoding::DefaultFuchsiaResourceDialect,
1105    >;
1106    fn r#on_key_event(&self, mut event: &KeyEvent) -> Self::OnKeyEventResponseFut {
1107        fn _decode(
1108            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1109        ) -> Result<KeyEventStatus, fidl::Error> {
1110            let _response = fidl::client::decode_transaction_body::<
1111                KeyboardListenerOnKeyEventResponse,
1112                fidl::encoding::DefaultFuchsiaResourceDialect,
1113                0x2ef2ee16ac509093,
1114            >(_buf?)?;
1115            Ok(_response.status)
1116        }
1117        self.client.send_query_and_decode::<KeyboardListenerOnKeyEventRequest, KeyEventStatus>(
1118            (event,),
1119            0x2ef2ee16ac509093,
1120            fidl::encoding::DynamicFlags::empty(),
1121            _decode,
1122        )
1123    }
1124}
1125
1126pub struct KeyboardListenerEventStream {
1127    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1128}
1129
1130impl std::marker::Unpin for KeyboardListenerEventStream {}
1131
1132impl futures::stream::FusedStream for KeyboardListenerEventStream {
1133    fn is_terminated(&self) -> bool {
1134        self.event_receiver.is_terminated()
1135    }
1136}
1137
1138impl futures::Stream for KeyboardListenerEventStream {
1139    type Item = Result<KeyboardListenerEvent, fidl::Error>;
1140
1141    fn poll_next(
1142        mut self: std::pin::Pin<&mut Self>,
1143        cx: &mut std::task::Context<'_>,
1144    ) -> std::task::Poll<Option<Self::Item>> {
1145        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1146            &mut self.event_receiver,
1147            cx
1148        )?) {
1149            Some(buf) => std::task::Poll::Ready(Some(KeyboardListenerEvent::decode(buf))),
1150            None => std::task::Poll::Ready(None),
1151        }
1152    }
1153}
1154
1155#[derive(Debug)]
1156pub enum KeyboardListenerEvent {}
1157
1158impl KeyboardListenerEvent {
1159    /// Decodes a message buffer as a [`KeyboardListenerEvent`].
1160    fn decode(
1161        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1162    ) -> Result<KeyboardListenerEvent, fidl::Error> {
1163        let (bytes, _handles) = buf.split_mut();
1164        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1165        debug_assert_eq!(tx_header.tx_id, 0);
1166        match tx_header.ordinal {
1167            _ => Err(fidl::Error::UnknownOrdinal {
1168                ordinal: tx_header.ordinal,
1169                protocol_name:
1170                    <KeyboardListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1171            }),
1172        }
1173    }
1174}
1175
1176/// A Stream of incoming requests for fuchsia.ui.input3/KeyboardListener.
1177pub struct KeyboardListenerRequestStream {
1178    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1179    is_terminated: bool,
1180}
1181
1182impl std::marker::Unpin for KeyboardListenerRequestStream {}
1183
1184impl futures::stream::FusedStream for KeyboardListenerRequestStream {
1185    fn is_terminated(&self) -> bool {
1186        self.is_terminated
1187    }
1188}
1189
1190impl fidl::endpoints::RequestStream for KeyboardListenerRequestStream {
1191    type Protocol = KeyboardListenerMarker;
1192    type ControlHandle = KeyboardListenerControlHandle;
1193
1194    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1195        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1196    }
1197
1198    fn control_handle(&self) -> Self::ControlHandle {
1199        KeyboardListenerControlHandle { inner: self.inner.clone() }
1200    }
1201
1202    fn into_inner(
1203        self,
1204    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1205    {
1206        (self.inner, self.is_terminated)
1207    }
1208
1209    fn from_inner(
1210        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1211        is_terminated: bool,
1212    ) -> Self {
1213        Self { inner, is_terminated }
1214    }
1215}
1216
1217impl futures::Stream for KeyboardListenerRequestStream {
1218    type Item = Result<KeyboardListenerRequest, fidl::Error>;
1219
1220    fn poll_next(
1221        mut self: std::pin::Pin<&mut Self>,
1222        cx: &mut std::task::Context<'_>,
1223    ) -> std::task::Poll<Option<Self::Item>> {
1224        let this = &mut *self;
1225        if this.inner.check_shutdown(cx) {
1226            this.is_terminated = true;
1227            return std::task::Poll::Ready(None);
1228        }
1229        if this.is_terminated {
1230            panic!("polled KeyboardListenerRequestStream after completion");
1231        }
1232        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1233            |bytes, handles| {
1234                match this.inner.channel().read_etc(cx, bytes, handles) {
1235                    std::task::Poll::Ready(Ok(())) => {}
1236                    std::task::Poll::Pending => return std::task::Poll::Pending,
1237                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1238                        this.is_terminated = true;
1239                        return std::task::Poll::Ready(None);
1240                    }
1241                    std::task::Poll::Ready(Err(e)) => {
1242                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1243                            e.into(),
1244                        ))))
1245                    }
1246                }
1247
1248                // A message has been received from the channel
1249                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1250
1251                std::task::Poll::Ready(Some(match header.ordinal {
1252                    0x2ef2ee16ac509093 => {
1253                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1254                        let mut req = fidl::new_empty!(
1255                            KeyboardListenerOnKeyEventRequest,
1256                            fidl::encoding::DefaultFuchsiaResourceDialect
1257                        );
1258                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<KeyboardListenerOnKeyEventRequest>(&header, _body_bytes, handles, &mut req)?;
1259                        let control_handle =
1260                            KeyboardListenerControlHandle { inner: this.inner.clone() };
1261                        Ok(KeyboardListenerRequest::OnKeyEvent {
1262                            event: req.event,
1263
1264                            responder: KeyboardListenerOnKeyEventResponder {
1265                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1266                                tx_id: header.tx_id,
1267                            },
1268                        })
1269                    }
1270                    _ => Err(fidl::Error::UnknownOrdinal {
1271                        ordinal: header.ordinal,
1272                        protocol_name:
1273                            <KeyboardListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1274                    }),
1275                }))
1276            },
1277        )
1278    }
1279}
1280
1281/// Client should implement this protocol to get notified of key events.
1282#[derive(Debug)]
1283pub enum KeyboardListenerRequest {
1284    /// Called when a key event takes place, such as key press or release.
1285    ///
1286    /// Protocol implementers must respond to acknowledge the event by returning Status
1287    /// in a timely manner, i.e. not introducing significant delays to the
1288    /// input pipeline (typically 10s of milliseconds).
1289    ///
1290    /// Returning `NOT_HANDLED` means the event may be offered to other
1291    /// clients of other related APIs.
1292    ///
1293    /// Clients that do not acknowledge their events will eventually be disconnected.
1294    ///
1295    /// Notification is only dispatched to a view that has focus. No other views,
1296    /// including parents or children, will get notified specifically via `OnKeyEvent`.
1297    OnKeyEvent { event: KeyEvent, responder: KeyboardListenerOnKeyEventResponder },
1298}
1299
1300impl KeyboardListenerRequest {
1301    #[allow(irrefutable_let_patterns)]
1302    pub fn into_on_key_event(self) -> Option<(KeyEvent, KeyboardListenerOnKeyEventResponder)> {
1303        if let KeyboardListenerRequest::OnKeyEvent { event, responder } = self {
1304            Some((event, responder))
1305        } else {
1306            None
1307        }
1308    }
1309
1310    /// Name of the method defined in FIDL
1311    pub fn method_name(&self) -> &'static str {
1312        match *self {
1313            KeyboardListenerRequest::OnKeyEvent { .. } => "on_key_event",
1314        }
1315    }
1316}
1317
1318#[derive(Debug, Clone)]
1319pub struct KeyboardListenerControlHandle {
1320    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1321}
1322
1323impl fidl::endpoints::ControlHandle for KeyboardListenerControlHandle {
1324    fn shutdown(&self) {
1325        self.inner.shutdown()
1326    }
1327    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1328        self.inner.shutdown_with_epitaph(status)
1329    }
1330
1331    fn is_closed(&self) -> bool {
1332        self.inner.channel().is_closed()
1333    }
1334    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1335        self.inner.channel().on_closed()
1336    }
1337
1338    #[cfg(target_os = "fuchsia")]
1339    fn signal_peer(
1340        &self,
1341        clear_mask: zx::Signals,
1342        set_mask: zx::Signals,
1343    ) -> Result<(), zx_status::Status> {
1344        use fidl::Peered;
1345        self.inner.channel().signal_peer(clear_mask, set_mask)
1346    }
1347}
1348
1349impl KeyboardListenerControlHandle {}
1350
1351#[must_use = "FIDL methods require a response to be sent"]
1352#[derive(Debug)]
1353pub struct KeyboardListenerOnKeyEventResponder {
1354    control_handle: std::mem::ManuallyDrop<KeyboardListenerControlHandle>,
1355    tx_id: u32,
1356}
1357
1358/// Set the the channel to be shutdown (see [`KeyboardListenerControlHandle::shutdown`])
1359/// if the responder is dropped without sending a response, so that the client
1360/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1361impl std::ops::Drop for KeyboardListenerOnKeyEventResponder {
1362    fn drop(&mut self) {
1363        self.control_handle.shutdown();
1364        // Safety: drops once, never accessed again
1365        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1366    }
1367}
1368
1369impl fidl::endpoints::Responder for KeyboardListenerOnKeyEventResponder {
1370    type ControlHandle = KeyboardListenerControlHandle;
1371
1372    fn control_handle(&self) -> &KeyboardListenerControlHandle {
1373        &self.control_handle
1374    }
1375
1376    fn drop_without_shutdown(mut self) {
1377        // Safety: drops once, never accessed again due to mem::forget
1378        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1379        // Prevent Drop from running (which would shut down the channel)
1380        std::mem::forget(self);
1381    }
1382}
1383
1384impl KeyboardListenerOnKeyEventResponder {
1385    /// Sends a response to the FIDL transaction.
1386    ///
1387    /// Sets the channel to shutdown if an error occurs.
1388    pub fn send(self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
1389        let _result = self.send_raw(status);
1390        if _result.is_err() {
1391            self.control_handle.shutdown();
1392        }
1393        self.drop_without_shutdown();
1394        _result
1395    }
1396
1397    /// Similar to "send" but does not shutdown the channel if an error occurs.
1398    pub fn send_no_shutdown_on_err(self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
1399        let _result = self.send_raw(status);
1400        self.drop_without_shutdown();
1401        _result
1402    }
1403
1404    fn send_raw(&self, mut status: KeyEventStatus) -> Result<(), fidl::Error> {
1405        self.control_handle.inner.send::<KeyboardListenerOnKeyEventResponse>(
1406            (status,),
1407            self.tx_id,
1408            0x2ef2ee16ac509093,
1409            fidl::encoding::DynamicFlags::empty(),
1410        )
1411    }
1412}
1413
1414mod internal {
1415    use super::*;
1416
1417    impl fidl::encoding::ResourceTypeMarker for KeyboardAddListenerRequest {
1418        type Borrowed<'a> = &'a mut Self;
1419        fn take_or_borrow<'a>(
1420            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1421        ) -> Self::Borrowed<'a> {
1422            value
1423        }
1424    }
1425
1426    unsafe impl fidl::encoding::TypeMarker for KeyboardAddListenerRequest {
1427        type Owned = Self;
1428
1429        #[inline(always)]
1430        fn inline_align(_context: fidl::encoding::Context) -> usize {
1431            4
1432        }
1433
1434        #[inline(always)]
1435        fn inline_size(_context: fidl::encoding::Context) -> usize {
1436            8
1437        }
1438    }
1439
1440    unsafe impl
1441        fidl::encoding::Encode<
1442            KeyboardAddListenerRequest,
1443            fidl::encoding::DefaultFuchsiaResourceDialect,
1444        > for &mut KeyboardAddListenerRequest
1445    {
1446        #[inline]
1447        unsafe fn encode(
1448            self,
1449            encoder: &mut fidl::encoding::Encoder<
1450                '_,
1451                fidl::encoding::DefaultFuchsiaResourceDialect,
1452            >,
1453            offset: usize,
1454            _depth: fidl::encoding::Depth,
1455        ) -> fidl::Result<()> {
1456            encoder.debug_check_bounds::<KeyboardAddListenerRequest>(offset);
1457            // Delegate to tuple encoding.
1458            fidl::encoding::Encode::<KeyboardAddListenerRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1459                (
1460                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.view_ref),
1461                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<KeyboardListenerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.listener),
1462                ),
1463                encoder, offset, _depth
1464            )
1465        }
1466    }
1467    unsafe impl<
1468            T0: fidl::encoding::Encode<
1469                fidl_fuchsia_ui_views::ViewRef,
1470                fidl::encoding::DefaultFuchsiaResourceDialect,
1471            >,
1472            T1: fidl::encoding::Encode<
1473                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<KeyboardListenerMarker>>,
1474                fidl::encoding::DefaultFuchsiaResourceDialect,
1475            >,
1476        >
1477        fidl::encoding::Encode<
1478            KeyboardAddListenerRequest,
1479            fidl::encoding::DefaultFuchsiaResourceDialect,
1480        > for (T0, T1)
1481    {
1482        #[inline]
1483        unsafe fn encode(
1484            self,
1485            encoder: &mut fidl::encoding::Encoder<
1486                '_,
1487                fidl::encoding::DefaultFuchsiaResourceDialect,
1488            >,
1489            offset: usize,
1490            depth: fidl::encoding::Depth,
1491        ) -> fidl::Result<()> {
1492            encoder.debug_check_bounds::<KeyboardAddListenerRequest>(offset);
1493            // Zero out padding regions. There's no need to apply masks
1494            // because the unmasked parts will be overwritten by fields.
1495            // Write the fields.
1496            self.0.encode(encoder, offset + 0, depth)?;
1497            self.1.encode(encoder, offset + 4, depth)?;
1498            Ok(())
1499        }
1500    }
1501
1502    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1503        for KeyboardAddListenerRequest
1504    {
1505        #[inline(always)]
1506        fn new_empty() -> Self {
1507            Self {
1508                view_ref: fidl::new_empty!(
1509                    fidl_fuchsia_ui_views::ViewRef,
1510                    fidl::encoding::DefaultFuchsiaResourceDialect
1511                ),
1512                listener: fidl::new_empty!(
1513                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<KeyboardListenerMarker>>,
1514                    fidl::encoding::DefaultFuchsiaResourceDialect
1515                ),
1516            }
1517        }
1518
1519        #[inline]
1520        unsafe fn decode(
1521            &mut self,
1522            decoder: &mut fidl::encoding::Decoder<
1523                '_,
1524                fidl::encoding::DefaultFuchsiaResourceDialect,
1525            >,
1526            offset: usize,
1527            _depth: fidl::encoding::Depth,
1528        ) -> fidl::Result<()> {
1529            decoder.debug_check_bounds::<Self>(offset);
1530            // Verify that padding bytes are zero.
1531            fidl::decode!(
1532                fidl_fuchsia_ui_views::ViewRef,
1533                fidl::encoding::DefaultFuchsiaResourceDialect,
1534                &mut self.view_ref,
1535                decoder,
1536                offset + 0,
1537                _depth
1538            )?;
1539            fidl::decode!(
1540                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<KeyboardListenerMarker>>,
1541                fidl::encoding::DefaultFuchsiaResourceDialect,
1542                &mut self.listener,
1543                decoder,
1544                offset + 4,
1545                _depth
1546            )?;
1547            Ok(())
1548        }
1549    }
1550}