Skip to main content

fidl_fuchsia_ui_input_internal/
fidl_fuchsia_ui_input_internal.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_input_internal_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct InputOwnershipGetEventRequest {
16    pub target: InputOwnershipTarget,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for InputOwnershipGetEventRequest
21{
22}
23
24#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
25pub struct InputOwnershipGetEventResponse {
26    pub ownership_event: fidl::Event,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
30    for InputOwnershipGetEventResponse
31{
32}
33
34/// Target identity when requesting direct input ownership.
35#[derive(Debug)]
36pub enum InputOwnershipTarget {
37    ViewRef(fidl_fuchsia_ui_views::ViewRef),
38    Virtcon(Virtcon),
39    Platform(Platform),
40    #[doc(hidden)]
41    __SourceBreaking {
42        unknown_ordinal: u64,
43    },
44}
45
46/// Pattern that matches an unknown `InputOwnershipTarget` member.
47#[macro_export]
48macro_rules! InputOwnershipTargetUnknown {
49    () => {
50        _
51    };
52}
53
54// Custom PartialEq so that unknown variants are not equal to themselves.
55impl PartialEq for InputOwnershipTarget {
56    fn eq(&self, other: &Self) -> bool {
57        match (self, other) {
58            (Self::ViewRef(x), Self::ViewRef(y)) => *x == *y,
59            (Self::Virtcon(x), Self::Virtcon(y)) => *x == *y,
60            (Self::Platform(x), Self::Platform(y)) => *x == *y,
61            _ => false,
62        }
63    }
64}
65
66impl InputOwnershipTarget {
67    #[inline]
68    pub fn ordinal(&self) -> u64 {
69        match *self {
70            Self::ViewRef(_) => 1,
71            Self::Virtcon(_) => 2,
72            Self::Platform(_) => 3,
73            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
74        }
75    }
76
77    #[inline]
78    pub fn unknown_variant_for_testing() -> Self {
79        Self::__SourceBreaking { unknown_ordinal: 0 }
80    }
81
82    #[inline]
83    pub fn is_unknown(&self) -> bool {
84        match self {
85            Self::__SourceBreaking { .. } => true,
86            _ => false,
87        }
88    }
89}
90
91impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for InputOwnershipTarget {}
92
93#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
94pub struct InputOwnershipMarker;
95
96impl fidl::endpoints::ProtocolMarker for InputOwnershipMarker {
97    type Proxy = InputOwnershipProxy;
98    type RequestStream = InputOwnershipRequestStream;
99    #[cfg(target_os = "fuchsia")]
100    type SynchronousProxy = InputOwnershipSynchronousProxy;
101
102    const DEBUG_NAME: &'static str = "fuchsia.ui.input.internal.InputOwnership";
103}
104impl fidl::endpoints::DiscoverableProtocolMarker for InputOwnershipMarker {}
105pub type InputOwnershipGetEventResult = Result<fidl::Event, InputOwnershipError>;
106
107pub trait InputOwnershipProxyInterface: Send + Sync {
108    type GetEventResponseFut: std::future::Future<Output = Result<InputOwnershipGetEventResult, fidl::Error>>
109        + Send;
110    fn r#get_event(&self, target: InputOwnershipTarget) -> Self::GetEventResponseFut;
111}
112#[derive(Debug)]
113#[cfg(target_os = "fuchsia")]
114pub struct InputOwnershipSynchronousProxy {
115    client: fidl::client::sync::Client,
116}
117
118#[cfg(target_os = "fuchsia")]
119impl fidl::endpoints::SynchronousProxy for InputOwnershipSynchronousProxy {
120    type Proxy = InputOwnershipProxy;
121    type Protocol = InputOwnershipMarker;
122
123    fn from_channel(inner: fidl::Channel) -> Self {
124        Self::new(inner)
125    }
126
127    fn into_channel(self) -> fidl::Channel {
128        self.client.into_channel()
129    }
130
131    fn as_channel(&self) -> &fidl::Channel {
132        self.client.as_channel()
133    }
134}
135
136#[cfg(target_os = "fuchsia")]
137impl InputOwnershipSynchronousProxy {
138    pub fn new(channel: fidl::Channel) -> Self {
139        Self { client: fidl::client::sync::Client::new(channel) }
140    }
141
142    pub fn into_channel(self) -> fidl::Channel {
143        self.client.into_channel()
144    }
145
146    /// Waits until an event arrives and returns it. It is safe for other
147    /// threads to make concurrent requests while waiting for an event.
148    pub fn wait_for_event(
149        &self,
150        deadline: zx::MonotonicInstant,
151    ) -> Result<InputOwnershipEvent, fidl::Error> {
152        InputOwnershipEvent::decode(self.client.wait_for_event::<InputOwnershipMarker>(deadline)?)
153    }
154
155    /// Gets a duplicate handle to the shared kernel `ownership_event` whose
156    /// orthogonal signals inform clients and the system pipeline when direct
157    /// driver input access (`fuchsia.input.report.Service`) is granted or revoked:
158    ///
159    /// - `Virtcon` (`target` = `virtcon: {}`): owns input iff
160    ///   `InputOwnershipSignal.DISPLAY_UNOWNED` is asserted.
161    /// - `Starnix` (`target` = `view_ref`): owns direct input iff both
162    ///   `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
163    ///   `InputOwnershipSignal.INPUT_CLIENT_OWNED` are asserted.
164    /// - `SceneManager` (`target` = `platform: {}`): owns platform pipeline
165    ///   input iff both `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
166    ///   `InputOwnershipSignal.INPUT_PLATFORM_OWNED` are asserted (pauses whenever
167    ///   `DISPLAY_UNOWNED` or `INPUT_CLIENT_OWNED` is asserted).
168    ///
169    /// If `target` is set to an unsupported or unknown variant, the call
170    /// returns `InputOwnershipError.INVALID_TARGET`.
171    pub fn r#get_event(
172        &self,
173        mut target: InputOwnershipTarget,
174        ___deadline: zx::MonotonicInstant,
175    ) -> Result<InputOwnershipGetEventResult, fidl::Error> {
176        let _response =
177            self.client.send_query::<InputOwnershipGetEventRequest, fidl::encoding::ResultType<
178                InputOwnershipGetEventResponse,
179                InputOwnershipError,
180            >, InputOwnershipMarker>(
181                (&mut target,),
182                0x486e6eebf1f00657,
183                fidl::encoding::DynamicFlags::empty(),
184                ___deadline,
185            )?;
186        Ok(_response.map(|x| x.ownership_event))
187    }
188}
189
190#[cfg(target_os = "fuchsia")]
191impl From<InputOwnershipSynchronousProxy> for zx::NullableHandle {
192    fn from(value: InputOwnershipSynchronousProxy) -> Self {
193        value.into_channel().into()
194    }
195}
196
197#[cfg(target_os = "fuchsia")]
198impl From<fidl::Channel> for InputOwnershipSynchronousProxy {
199    fn from(value: fidl::Channel) -> Self {
200        Self::new(value)
201    }
202}
203
204#[cfg(target_os = "fuchsia")]
205impl fidl::endpoints::FromClient for InputOwnershipSynchronousProxy {
206    type Protocol = InputOwnershipMarker;
207
208    fn from_client(value: fidl::endpoints::ClientEnd<InputOwnershipMarker>) -> Self {
209        Self::new(value.into_channel())
210    }
211}
212
213#[derive(Debug, Clone)]
214pub struct InputOwnershipProxy {
215    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
216}
217
218impl fidl::endpoints::Proxy for InputOwnershipProxy {
219    type Protocol = InputOwnershipMarker;
220
221    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
222        Self::new(inner)
223    }
224
225    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
226        self.client.into_channel().map_err(|client| Self { client })
227    }
228
229    fn as_channel(&self) -> &::fidl::AsyncChannel {
230        self.client.as_channel()
231    }
232}
233
234impl InputOwnershipProxy {
235    /// Create a new Proxy for fuchsia.ui.input.internal/InputOwnership.
236    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
237        let protocol_name = <InputOwnershipMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
238        Self { client: fidl::client::Client::new(channel, protocol_name) }
239    }
240
241    /// Get a Stream of events from the remote end of the protocol.
242    ///
243    /// # Panics
244    ///
245    /// Panics if the event stream was already taken.
246    pub fn take_event_stream(&self) -> InputOwnershipEventStream {
247        InputOwnershipEventStream { event_receiver: self.client.take_event_receiver() }
248    }
249
250    /// Gets a duplicate handle to the shared kernel `ownership_event` whose
251    /// orthogonal signals inform clients and the system pipeline when direct
252    /// driver input access (`fuchsia.input.report.Service`) is granted or revoked:
253    ///
254    /// - `Virtcon` (`target` = `virtcon: {}`): owns input iff
255    ///   `InputOwnershipSignal.DISPLAY_UNOWNED` is asserted.
256    /// - `Starnix` (`target` = `view_ref`): owns direct input iff both
257    ///   `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
258    ///   `InputOwnershipSignal.INPUT_CLIENT_OWNED` are asserted.
259    /// - `SceneManager` (`target` = `platform: {}`): owns platform pipeline
260    ///   input iff both `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
261    ///   `InputOwnershipSignal.INPUT_PLATFORM_OWNED` are asserted (pauses whenever
262    ///   `DISPLAY_UNOWNED` or `INPUT_CLIENT_OWNED` is asserted).
263    ///
264    /// If `target` is set to an unsupported or unknown variant, the call
265    /// returns `InputOwnershipError.INVALID_TARGET`.
266    pub fn r#get_event(
267        &self,
268        mut target: InputOwnershipTarget,
269    ) -> fidl::client::QueryResponseFut<
270        InputOwnershipGetEventResult,
271        fidl::encoding::DefaultFuchsiaResourceDialect,
272    > {
273        InputOwnershipProxyInterface::r#get_event(self, target)
274    }
275}
276
277impl InputOwnershipProxyInterface for InputOwnershipProxy {
278    type GetEventResponseFut = fidl::client::QueryResponseFut<
279        InputOwnershipGetEventResult,
280        fidl::encoding::DefaultFuchsiaResourceDialect,
281    >;
282    fn r#get_event(&self, mut target: InputOwnershipTarget) -> Self::GetEventResponseFut {
283        fn _decode(
284            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
285        ) -> Result<InputOwnershipGetEventResult, fidl::Error> {
286            let _response = fidl::client::decode_transaction_body::<
287                fidl::encoding::ResultType<InputOwnershipGetEventResponse, InputOwnershipError>,
288                fidl::encoding::DefaultFuchsiaResourceDialect,
289                0x486e6eebf1f00657,
290            >(_buf?)?;
291            Ok(_response.map(|x| x.ownership_event))
292        }
293        self.client
294            .send_query_and_decode::<InputOwnershipGetEventRequest, InputOwnershipGetEventResult>(
295                (&mut target,),
296                0x486e6eebf1f00657,
297                fidl::encoding::DynamicFlags::empty(),
298                _decode,
299            )
300    }
301}
302
303pub struct InputOwnershipEventStream {
304    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
305}
306
307impl std::marker::Unpin for InputOwnershipEventStream {}
308
309impl futures::stream::FusedStream for InputOwnershipEventStream {
310    fn is_terminated(&self) -> bool {
311        self.event_receiver.is_terminated()
312    }
313}
314
315impl futures::Stream for InputOwnershipEventStream {
316    type Item = Result<InputOwnershipEvent, fidl::Error>;
317
318    fn poll_next(
319        mut self: std::pin::Pin<&mut Self>,
320        cx: &mut std::task::Context<'_>,
321    ) -> std::task::Poll<Option<Self::Item>> {
322        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
323            &mut self.event_receiver,
324            cx
325        )?) {
326            Some(buf) => std::task::Poll::Ready(Some(InputOwnershipEvent::decode(buf))),
327            None => std::task::Poll::Ready(None),
328        }
329    }
330}
331
332#[derive(Debug)]
333pub enum InputOwnershipEvent {}
334
335impl InputOwnershipEvent {
336    /// Decodes a message buffer as a [`InputOwnershipEvent`].
337    fn decode(
338        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
339    ) -> Result<InputOwnershipEvent, fidl::Error> {
340        let (bytes, _handles) = buf.split_mut();
341        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
342        debug_assert_eq!(tx_header.tx_id, 0);
343        match tx_header.ordinal {
344            _ => Err(fidl::Error::UnknownOrdinal {
345                ordinal: tx_header.ordinal,
346                protocol_name:
347                    <InputOwnershipMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
348            }),
349        }
350    }
351}
352
353/// A Stream of incoming requests for fuchsia.ui.input.internal/InputOwnership.
354pub struct InputOwnershipRequestStream {
355    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
356    is_terminated: bool,
357}
358
359impl std::marker::Unpin for InputOwnershipRequestStream {}
360
361impl futures::stream::FusedStream for InputOwnershipRequestStream {
362    fn is_terminated(&self) -> bool {
363        self.is_terminated
364    }
365}
366
367impl fidl::endpoints::RequestStream for InputOwnershipRequestStream {
368    type Protocol = InputOwnershipMarker;
369    type ControlHandle = InputOwnershipControlHandle;
370
371    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
372        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
373    }
374
375    fn control_handle(&self) -> Self::ControlHandle {
376        InputOwnershipControlHandle { inner: self.inner.clone() }
377    }
378
379    fn into_inner(
380        self,
381    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
382    {
383        (self.inner, self.is_terminated)
384    }
385
386    fn from_inner(
387        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
388        is_terminated: bool,
389    ) -> Self {
390        Self { inner, is_terminated }
391    }
392}
393
394impl futures::Stream for InputOwnershipRequestStream {
395    type Item = Result<InputOwnershipRequest, fidl::Error>;
396
397    fn poll_next(
398        mut self: std::pin::Pin<&mut Self>,
399        cx: &mut std::task::Context<'_>,
400    ) -> std::task::Poll<Option<Self::Item>> {
401        let this = &mut *self;
402        if this.inner.check_shutdown(cx) {
403            this.is_terminated = true;
404            return std::task::Poll::Ready(None);
405        }
406        if this.is_terminated {
407            panic!("polled InputOwnershipRequestStream after completion");
408        }
409        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
410            |bytes, handles| {
411                match this.inner.channel().read_etc(cx, bytes, handles) {
412                    std::task::Poll::Ready(Ok(())) => {}
413                    std::task::Poll::Pending => return std::task::Poll::Pending,
414                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
415                        this.is_terminated = true;
416                        return std::task::Poll::Ready(None);
417                    }
418                    std::task::Poll::Ready(Err(e)) => {
419                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
420                            e.into(),
421                        ))));
422                    }
423                }
424
425                // A message has been received from the channel
426                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
427
428                std::task::Poll::Ready(Some(match header.ordinal {
429                    0x486e6eebf1f00657 => {
430                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
431                        let mut req = fidl::new_empty!(
432                            InputOwnershipGetEventRequest,
433                            fidl::encoding::DefaultFuchsiaResourceDialect
434                        );
435                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<InputOwnershipGetEventRequest>(&header, _body_bytes, handles, &mut req)?;
436                        let control_handle =
437                            InputOwnershipControlHandle { inner: this.inner.clone() };
438                        Ok(InputOwnershipRequest::GetEvent {
439                            target: req.target,
440
441                            responder: InputOwnershipGetEventResponder {
442                                control_handle: std::mem::ManuallyDrop::new(control_handle),
443                                tx_id: header.tx_id,
444                            },
445                        })
446                    }
447                    _ => Err(fidl::Error::UnknownOrdinal {
448                        ordinal: header.ordinal,
449                        protocol_name:
450                            <InputOwnershipMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
451                    }),
452                }))
453            },
454        )
455    }
456}
457
458/// Get information about ownership of input (replaces `DisplayOwnership`).
459///
460/// By default, user input is handled by the platform input pipeline
461/// (`SceneManager`) and delivered to applications via standard UI protocols
462/// (e.g. `fuchsia.ui.pointer.TouchSource`).
463///
464/// Low-level components (such as Starnix or Virtcon) that require direct access
465/// to hardware input devices via `fuchsia.input.report.Service` must observe this
466/// event to pause or resume reading from direct driver streams, preventing
467/// duplicate processing or input leakage.
468///
469/// This protocol intentionally assumes a system-wide singleton direct-client
470/// model where only one direct client or the platform pipeline consumes input
471/// at any given time.
472///
473/// During ownership transitions (e.g. switching display ownership or view
474/// focus), an intermediate state may occur where neither the direct client nor
475/// the platform pipeline owns input. During any unowned or transition state, all
476/// consumers (both direct clients and the platform pipeline) must pause reading
477/// and processing hardware input reports until their respective ownership signal
478/// is asserted.
479#[derive(Debug)]
480pub enum InputOwnershipRequest {
481    /// Gets a duplicate handle to the shared kernel `ownership_event` whose
482    /// orthogonal signals inform clients and the system pipeline when direct
483    /// driver input access (`fuchsia.input.report.Service`) is granted or revoked:
484    ///
485    /// - `Virtcon` (`target` = `virtcon: {}`): owns input iff
486    ///   `InputOwnershipSignal.DISPLAY_UNOWNED` is asserted.
487    /// - `Starnix` (`target` = `view_ref`): owns direct input iff both
488    ///   `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
489    ///   `InputOwnershipSignal.INPUT_CLIENT_OWNED` are asserted.
490    /// - `SceneManager` (`target` = `platform: {}`): owns platform pipeline
491    ///   input iff both `InputOwnershipSignal.DISPLAY_PLATFORM_OWNED` and
492    ///   `InputOwnershipSignal.INPUT_PLATFORM_OWNED` are asserted (pauses whenever
493    ///   `DISPLAY_UNOWNED` or `INPUT_CLIENT_OWNED` is asserted).
494    ///
495    /// If `target` is set to an unsupported or unknown variant, the call
496    /// returns `InputOwnershipError.INVALID_TARGET`.
497    GetEvent { target: InputOwnershipTarget, responder: InputOwnershipGetEventResponder },
498}
499
500impl InputOwnershipRequest {
501    #[allow(irrefutable_let_patterns)]
502    pub fn into_get_event(self) -> Option<(InputOwnershipTarget, InputOwnershipGetEventResponder)> {
503        if let InputOwnershipRequest::GetEvent { target, responder } = self {
504            Some((target, responder))
505        } else {
506            None
507        }
508    }
509
510    /// Name of the method defined in FIDL
511    pub fn method_name(&self) -> &'static str {
512        match *self {
513            InputOwnershipRequest::GetEvent { .. } => "get_event",
514        }
515    }
516}
517
518#[derive(Debug, Clone)]
519pub struct InputOwnershipControlHandle {
520    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
521}
522
523impl InputOwnershipControlHandle {
524    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
525        self.inner.shutdown_with_epitaph(status.into())
526    }
527}
528
529impl fidl::endpoints::ControlHandle for InputOwnershipControlHandle {
530    fn shutdown(&self) {
531        self.inner.shutdown()
532    }
533
534    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
535        self.inner.shutdown_with_epitaph(status)
536    }
537
538    fn is_closed(&self) -> bool {
539        self.inner.channel().is_closed()
540    }
541    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
542        self.inner.channel().on_closed()
543    }
544
545    #[cfg(target_os = "fuchsia")]
546    fn signal_peer(
547        &self,
548        clear_mask: zx::Signals,
549        set_mask: zx::Signals,
550    ) -> Result<(), zx_status::Status> {
551        use fidl::Peered;
552        self.inner.channel().signal_peer(clear_mask, set_mask)
553    }
554}
555
556impl InputOwnershipControlHandle {}
557
558#[must_use = "FIDL methods require a response to be sent"]
559#[derive(Debug)]
560pub struct InputOwnershipGetEventResponder {
561    control_handle: std::mem::ManuallyDrop<InputOwnershipControlHandle>,
562    tx_id: u32,
563}
564
565/// Set the the channel to be shutdown (see [`InputOwnershipControlHandle::shutdown`])
566/// if the responder is dropped without sending a response, so that the client
567/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
568impl std::ops::Drop for InputOwnershipGetEventResponder {
569    fn drop(&mut self) {
570        self.control_handle.shutdown();
571        // Safety: drops once, never accessed again
572        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
573    }
574}
575
576impl fidl::endpoints::Responder for InputOwnershipGetEventResponder {
577    type ControlHandle = InputOwnershipControlHandle;
578
579    fn control_handle(&self) -> &InputOwnershipControlHandle {
580        &self.control_handle
581    }
582
583    fn drop_without_shutdown(mut self) {
584        // Safety: drops once, never accessed again due to mem::forget
585        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
586        // Prevent Drop from running (which would shut down the channel)
587        std::mem::forget(self);
588    }
589}
590
591impl InputOwnershipGetEventResponder {
592    /// Sends a response to the FIDL transaction.
593    ///
594    /// Sets the channel to shutdown if an error occurs.
595    pub fn send(
596        self,
597        mut result: Result<fidl::Event, InputOwnershipError>,
598    ) -> Result<(), fidl::Error> {
599        let _result = self.send_raw(result);
600        if _result.is_err() {
601            self.control_handle.shutdown();
602        }
603        self.drop_without_shutdown();
604        _result
605    }
606
607    /// Similar to "send" but does not shutdown the channel if an error occurs.
608    pub fn send_no_shutdown_on_err(
609        self,
610        mut result: Result<fidl::Event, InputOwnershipError>,
611    ) -> Result<(), fidl::Error> {
612        let _result = self.send_raw(result);
613        self.drop_without_shutdown();
614        _result
615    }
616
617    fn send_raw(
618        &self,
619        mut result: Result<fidl::Event, InputOwnershipError>,
620    ) -> Result<(), fidl::Error> {
621        self.control_handle.inner.send::<fidl::encoding::ResultType<
622            InputOwnershipGetEventResponse,
623            InputOwnershipError,
624        >>(
625            result.map(|ownership_event| (ownership_event,)),
626            self.tx_id,
627            0x486e6eebf1f00657,
628            fidl::encoding::DynamicFlags::empty(),
629        )
630    }
631}
632
633mod internal {
634    use super::*;
635
636    impl fidl::encoding::ResourceTypeMarker for InputOwnershipGetEventRequest {
637        type Borrowed<'a> = &'a mut Self;
638        fn take_or_borrow<'a>(
639            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
640        ) -> Self::Borrowed<'a> {
641            value
642        }
643    }
644
645    unsafe impl fidl::encoding::TypeMarker for InputOwnershipGetEventRequest {
646        type Owned = Self;
647
648        #[inline(always)]
649        fn inline_align(_context: fidl::encoding::Context) -> usize {
650            8
651        }
652
653        #[inline(always)]
654        fn inline_size(_context: fidl::encoding::Context) -> usize {
655            16
656        }
657    }
658
659    unsafe impl
660        fidl::encoding::Encode<
661            InputOwnershipGetEventRequest,
662            fidl::encoding::DefaultFuchsiaResourceDialect,
663        > for &mut InputOwnershipGetEventRequest
664    {
665        #[inline]
666        unsafe fn encode(
667            self,
668            encoder: &mut fidl::encoding::Encoder<
669                '_,
670                fidl::encoding::DefaultFuchsiaResourceDialect,
671            >,
672            offset: usize,
673            _depth: fidl::encoding::Depth,
674        ) -> fidl::Result<()> {
675            encoder.debug_check_bounds::<InputOwnershipGetEventRequest>(offset);
676            // Delegate to tuple encoding.
677            fidl::encoding::Encode::<
678                InputOwnershipGetEventRequest,
679                fidl::encoding::DefaultFuchsiaResourceDialect,
680            >::encode(
681                (<InputOwnershipTarget as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
682                    &mut self.target,
683                ),),
684                encoder,
685                offset,
686                _depth,
687            )
688        }
689    }
690    unsafe impl<
691        T0: fidl::encoding::Encode<InputOwnershipTarget, fidl::encoding::DefaultFuchsiaResourceDialect>,
692    >
693        fidl::encoding::Encode<
694            InputOwnershipGetEventRequest,
695            fidl::encoding::DefaultFuchsiaResourceDialect,
696        > for (T0,)
697    {
698        #[inline]
699        unsafe fn encode(
700            self,
701            encoder: &mut fidl::encoding::Encoder<
702                '_,
703                fidl::encoding::DefaultFuchsiaResourceDialect,
704            >,
705            offset: usize,
706            depth: fidl::encoding::Depth,
707        ) -> fidl::Result<()> {
708            encoder.debug_check_bounds::<InputOwnershipGetEventRequest>(offset);
709            // Zero out padding regions. There's no need to apply masks
710            // because the unmasked parts will be overwritten by fields.
711            // Write the fields.
712            self.0.encode(encoder, offset + 0, depth)?;
713            Ok(())
714        }
715    }
716
717    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
718        for InputOwnershipGetEventRequest
719    {
720        #[inline(always)]
721        fn new_empty() -> Self {
722            Self {
723                target: fidl::new_empty!(
724                    InputOwnershipTarget,
725                    fidl::encoding::DefaultFuchsiaResourceDialect
726                ),
727            }
728        }
729
730        #[inline]
731        unsafe fn decode(
732            &mut self,
733            decoder: &mut fidl::encoding::Decoder<
734                '_,
735                fidl::encoding::DefaultFuchsiaResourceDialect,
736            >,
737            offset: usize,
738            _depth: fidl::encoding::Depth,
739        ) -> fidl::Result<()> {
740            decoder.debug_check_bounds::<Self>(offset);
741            // Verify that padding bytes are zero.
742            fidl::decode!(
743                InputOwnershipTarget,
744                fidl::encoding::DefaultFuchsiaResourceDialect,
745                &mut self.target,
746                decoder,
747                offset + 0,
748                _depth
749            )?;
750            Ok(())
751        }
752    }
753
754    impl fidl::encoding::ResourceTypeMarker for InputOwnershipGetEventResponse {
755        type Borrowed<'a> = &'a mut Self;
756        fn take_or_borrow<'a>(
757            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
758        ) -> Self::Borrowed<'a> {
759            value
760        }
761    }
762
763    unsafe impl fidl::encoding::TypeMarker for InputOwnershipGetEventResponse {
764        type Owned = Self;
765
766        #[inline(always)]
767        fn inline_align(_context: fidl::encoding::Context) -> usize {
768            4
769        }
770
771        #[inline(always)]
772        fn inline_size(_context: fidl::encoding::Context) -> usize {
773            4
774        }
775    }
776
777    unsafe impl
778        fidl::encoding::Encode<
779            InputOwnershipGetEventResponse,
780            fidl::encoding::DefaultFuchsiaResourceDialect,
781        > for &mut InputOwnershipGetEventResponse
782    {
783        #[inline]
784        unsafe fn encode(
785            self,
786            encoder: &mut fidl::encoding::Encoder<
787                '_,
788                fidl::encoding::DefaultFuchsiaResourceDialect,
789            >,
790            offset: usize,
791            _depth: fidl::encoding::Depth,
792        ) -> fidl::Result<()> {
793            encoder.debug_check_bounds::<InputOwnershipGetEventResponse>(offset);
794            // Delegate to tuple encoding.
795            fidl::encoding::Encode::<
796                InputOwnershipGetEventResponse,
797                fidl::encoding::DefaultFuchsiaResourceDialect,
798            >::encode(
799                (<fidl::encoding::HandleType<
800                    fidl::Event,
801                    { fidl::ObjectType::EVENT.into_raw() },
802                    49155,
803                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
804                    &mut self.ownership_event,
805                ),),
806                encoder,
807                offset,
808                _depth,
809            )
810        }
811    }
812    unsafe impl<
813        T0: fidl::encoding::Encode<
814                fidl::encoding::HandleType<
815                    fidl::Event,
816                    { fidl::ObjectType::EVENT.into_raw() },
817                    49155,
818                >,
819                fidl::encoding::DefaultFuchsiaResourceDialect,
820            >,
821    >
822        fidl::encoding::Encode<
823            InputOwnershipGetEventResponse,
824            fidl::encoding::DefaultFuchsiaResourceDialect,
825        > for (T0,)
826    {
827        #[inline]
828        unsafe fn encode(
829            self,
830            encoder: &mut fidl::encoding::Encoder<
831                '_,
832                fidl::encoding::DefaultFuchsiaResourceDialect,
833            >,
834            offset: usize,
835            depth: fidl::encoding::Depth,
836        ) -> fidl::Result<()> {
837            encoder.debug_check_bounds::<InputOwnershipGetEventResponse>(offset);
838            // Zero out padding regions. There's no need to apply masks
839            // because the unmasked parts will be overwritten by fields.
840            // Write the fields.
841            self.0.encode(encoder, offset + 0, depth)?;
842            Ok(())
843        }
844    }
845
846    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
847        for InputOwnershipGetEventResponse
848    {
849        #[inline(always)]
850        fn new_empty() -> Self {
851            Self {
852                ownership_event: fidl::new_empty!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 49155>, fidl::encoding::DefaultFuchsiaResourceDialect),
853            }
854        }
855
856        #[inline]
857        unsafe fn decode(
858            &mut self,
859            decoder: &mut fidl::encoding::Decoder<
860                '_,
861                fidl::encoding::DefaultFuchsiaResourceDialect,
862            >,
863            offset: usize,
864            _depth: fidl::encoding::Depth,
865        ) -> fidl::Result<()> {
866            decoder.debug_check_bounds::<Self>(offset);
867            // Verify that padding bytes are zero.
868            fidl::decode!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 49155>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.ownership_event, decoder, offset + 0, _depth)?;
869            Ok(())
870        }
871    }
872
873    impl fidl::encoding::ResourceTypeMarker for InputOwnershipTarget {
874        type Borrowed<'a> = &'a mut Self;
875        fn take_or_borrow<'a>(
876            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
877        ) -> Self::Borrowed<'a> {
878            value
879        }
880    }
881
882    unsafe impl fidl::encoding::TypeMarker for InputOwnershipTarget {
883        type Owned = Self;
884
885        #[inline(always)]
886        fn inline_align(_context: fidl::encoding::Context) -> usize {
887            8
888        }
889
890        #[inline(always)]
891        fn inline_size(_context: fidl::encoding::Context) -> usize {
892            16
893        }
894    }
895
896    unsafe impl
897        fidl::encoding::Encode<InputOwnershipTarget, fidl::encoding::DefaultFuchsiaResourceDialect>
898        for &mut InputOwnershipTarget
899    {
900        #[inline]
901        unsafe fn encode(
902            self,
903            encoder: &mut fidl::encoding::Encoder<
904                '_,
905                fidl::encoding::DefaultFuchsiaResourceDialect,
906            >,
907            offset: usize,
908            _depth: fidl::encoding::Depth,
909        ) -> fidl::Result<()> {
910            encoder.debug_check_bounds::<InputOwnershipTarget>(offset);
911            encoder.write_num::<u64>(self.ordinal(), offset);
912            match self {
913            InputOwnershipTarget::ViewRef(ref mut val) => {
914                fidl::encoding::encode_in_envelope::<fidl_fuchsia_ui_views::ViewRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
915                    <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow(val),
916                    encoder, offset + 8, _depth
917                )
918            }
919            InputOwnershipTarget::Virtcon(ref val) => {
920                fidl::encoding::encode_in_envelope::<Virtcon, fidl::encoding::DefaultFuchsiaResourceDialect>(
921                    <Virtcon as fidl::encoding::ValueTypeMarker>::borrow(val),
922                    encoder, offset + 8, _depth
923                )
924            }
925            InputOwnershipTarget::Platform(ref val) => {
926                fidl::encoding::encode_in_envelope::<Platform, fidl::encoding::DefaultFuchsiaResourceDialect>(
927                    <Platform as fidl::encoding::ValueTypeMarker>::borrow(val),
928                    encoder, offset + 8, _depth
929                )
930            }
931            InputOwnershipTarget::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
932        }
933        }
934    }
935
936    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
937        for InputOwnershipTarget
938    {
939        #[inline(always)]
940        fn new_empty() -> Self {
941            Self::__SourceBreaking { unknown_ordinal: 0 }
942        }
943
944        #[inline]
945        unsafe fn decode(
946            &mut self,
947            decoder: &mut fidl::encoding::Decoder<
948                '_,
949                fidl::encoding::DefaultFuchsiaResourceDialect,
950            >,
951            offset: usize,
952            mut depth: fidl::encoding::Depth,
953        ) -> fidl::Result<()> {
954            decoder.debug_check_bounds::<Self>(offset);
955            #[allow(unused_variables)]
956            let next_out_of_line = decoder.next_out_of_line();
957            let handles_before = decoder.remaining_handles();
958            let (ordinal, inlined, num_bytes, num_handles) =
959                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
960
961            let member_inline_size = match ordinal {
962                1 => <fidl_fuchsia_ui_views::ViewRef as fidl::encoding::TypeMarker>::inline_size(
963                    decoder.context,
964                ),
965                2 => <Virtcon as fidl::encoding::TypeMarker>::inline_size(decoder.context),
966                3 => <Platform as fidl::encoding::TypeMarker>::inline_size(decoder.context),
967                0 => return Err(fidl::Error::UnknownUnionTag),
968                _ => num_bytes as usize,
969            };
970
971            if inlined != (member_inline_size <= 4) {
972                return Err(fidl::Error::InvalidInlineBitInEnvelope);
973            }
974            let _inner_offset;
975            if inlined {
976                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
977                _inner_offset = offset + 8;
978            } else {
979                depth.increment()?;
980                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
981            }
982            match ordinal {
983                1 => {
984                    #[allow(irrefutable_let_patterns)]
985                    if let InputOwnershipTarget::ViewRef(_) = self {
986                        // Do nothing, read the value into the object
987                    } else {
988                        // Initialize `self` to the right variant
989                        *self = InputOwnershipTarget::ViewRef(fidl::new_empty!(
990                            fidl_fuchsia_ui_views::ViewRef,
991                            fidl::encoding::DefaultFuchsiaResourceDialect
992                        ));
993                    }
994                    #[allow(irrefutable_let_patterns)]
995                    if let InputOwnershipTarget::ViewRef(ref mut val) = self {
996                        fidl::decode!(
997                            fidl_fuchsia_ui_views::ViewRef,
998                            fidl::encoding::DefaultFuchsiaResourceDialect,
999                            val,
1000                            decoder,
1001                            _inner_offset,
1002                            depth
1003                        )?;
1004                    } else {
1005                        unreachable!()
1006                    }
1007                }
1008                2 => {
1009                    #[allow(irrefutable_let_patterns)]
1010                    if let InputOwnershipTarget::Virtcon(_) = self {
1011                        // Do nothing, read the value into the object
1012                    } else {
1013                        // Initialize `self` to the right variant
1014                        *self = InputOwnershipTarget::Virtcon(fidl::new_empty!(
1015                            Virtcon,
1016                            fidl::encoding::DefaultFuchsiaResourceDialect
1017                        ));
1018                    }
1019                    #[allow(irrefutable_let_patterns)]
1020                    if let InputOwnershipTarget::Virtcon(ref mut val) = self {
1021                        fidl::decode!(
1022                            Virtcon,
1023                            fidl::encoding::DefaultFuchsiaResourceDialect,
1024                            val,
1025                            decoder,
1026                            _inner_offset,
1027                            depth
1028                        )?;
1029                    } else {
1030                        unreachable!()
1031                    }
1032                }
1033                3 => {
1034                    #[allow(irrefutable_let_patterns)]
1035                    if let InputOwnershipTarget::Platform(_) = self {
1036                        // Do nothing, read the value into the object
1037                    } else {
1038                        // Initialize `self` to the right variant
1039                        *self = InputOwnershipTarget::Platform(fidl::new_empty!(
1040                            Platform,
1041                            fidl::encoding::DefaultFuchsiaResourceDialect
1042                        ));
1043                    }
1044                    #[allow(irrefutable_let_patterns)]
1045                    if let InputOwnershipTarget::Platform(ref mut val) = self {
1046                        fidl::decode!(
1047                            Platform,
1048                            fidl::encoding::DefaultFuchsiaResourceDialect,
1049                            val,
1050                            decoder,
1051                            _inner_offset,
1052                            depth
1053                        )?;
1054                    } else {
1055                        unreachable!()
1056                    }
1057                }
1058                #[allow(deprecated)]
1059                ordinal => {
1060                    for _ in 0..num_handles {
1061                        decoder.drop_next_handle()?;
1062                    }
1063                    *self = InputOwnershipTarget::__SourceBreaking { unknown_ordinal: ordinal };
1064                }
1065            }
1066            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1067                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1068            }
1069            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1070                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1071            }
1072            Ok(())
1073        }
1074    }
1075}