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