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