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