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