Skip to main content

fidl_fuchsia_hardware_spmi/
fidl_fuchsia_hardware_spmi.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_hardware_spmi_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DebugConnectTargetRequest {
16    pub target_id: u8,
17    pub server: fidl::endpoints::ServerEnd<DeviceMarker>,
18}
19
20impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for DebugConnectTargetRequest {}
21
22#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
23pub struct DeviceWatchControllerWriteCommandsRequest {
24    pub address: u8,
25    pub size: u16,
26    pub setup_wake_lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
30    for DeviceWatchControllerWriteCommandsRequest
31{
32}
33
34#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
35pub struct DeviceWatchControllerWriteCommandsResponse {
36    pub writes: Vec<Register8>,
37    pub wake_lease: Option<fidl::EventPair>,
38}
39
40impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
41    for DeviceWatchControllerWriteCommandsResponse
42{
43}
44
45#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
46pub struct DebugMarker;
47
48impl fidl::endpoints::ProtocolMarker for DebugMarker {
49    type Proxy = DebugProxy;
50    type RequestStream = DebugRequestStream;
51    #[cfg(target_os = "fuchsia")]
52    type SynchronousProxy = DebugSynchronousProxy;
53
54    const DEBUG_NAME: &'static str = "(anonymous) Debug";
55}
56pub type DebugConnectTargetResult = Result<(), DriverError>;
57
58pub trait DebugProxyInterface: Send + Sync {
59    type ConnectTargetResponseFut: std::future::Future<Output = Result<DebugConnectTargetResult, fidl::Error>>
60        + Send;
61    fn r#connect_target(
62        &self,
63        target_id: u8,
64        server: fidl::endpoints::ServerEnd<DeviceMarker>,
65    ) -> Self::ConnectTargetResponseFut;
66    type GetControllerPropertiesResponseFut: std::future::Future<Output = Result<DebugGetControllerPropertiesResponse, fidl::Error>>
67        + Send;
68    fn r#get_controller_properties(&self) -> Self::GetControllerPropertiesResponseFut;
69}
70#[derive(Debug)]
71#[cfg(target_os = "fuchsia")]
72pub struct DebugSynchronousProxy {
73    client: fidl::client::sync::Client,
74}
75
76#[cfg(target_os = "fuchsia")]
77impl fidl::endpoints::SynchronousProxy for DebugSynchronousProxy {
78    type Proxy = DebugProxy;
79    type Protocol = DebugMarker;
80
81    fn from_channel(inner: fidl::Channel) -> Self {
82        Self::new(inner)
83    }
84
85    fn into_channel(self) -> fidl::Channel {
86        self.client.into_channel()
87    }
88
89    fn as_channel(&self) -> &fidl::Channel {
90        self.client.as_channel()
91    }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl DebugSynchronousProxy {
96    pub fn new(channel: fidl::Channel) -> Self {
97        Self { client: fidl::client::sync::Client::new(channel) }
98    }
99
100    pub fn into_channel(self) -> fidl::Channel {
101        self.client.into_channel()
102    }
103
104    /// Waits until an event arrives and returns it. It is safe for other
105    /// threads to make concurrent requests while waiting for an event.
106    pub fn wait_for_event(
107        &self,
108        deadline: zx::MonotonicInstant,
109    ) -> Result<DebugEvent, fidl::Error> {
110        DebugEvent::decode(self.client.wait_for_event::<DebugMarker>(deadline)?)
111    }
112
113    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
114    /// via the corresponding driver node.
115    ///
116    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
117    /// May return an error if there is no such target on the bus; otherwise errors will be returned
118    /// when attempting to access the client.
119    pub fn r#connect_target(
120        &self,
121        mut target_id: u8,
122        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
123        ___deadline: zx::MonotonicInstant,
124    ) -> Result<DebugConnectTargetResult, fidl::Error> {
125        let _response = self.client.send_query::<
126            DebugConnectTargetRequest,
127            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DriverError>,
128            DebugMarker,
129        >(
130            (target_id, server,),
131            0xb18ebc371c68d19,
132            fidl::encoding::DynamicFlags::empty(),
133            ___deadline,
134        )?;
135        Ok(_response.map(|x| x))
136    }
137
138    /// Returns the properties of the host SPMI controller.
139    pub fn r#get_controller_properties(
140        &self,
141        ___deadline: zx::MonotonicInstant,
142    ) -> Result<DebugGetControllerPropertiesResponse, fidl::Error> {
143        let _response = self.client.send_query::<
144            fidl::encoding::EmptyPayload,
145            DebugGetControllerPropertiesResponse,
146            DebugMarker,
147        >(
148            (),
149            0x41b1c4ef901d051f,
150            fidl::encoding::DynamicFlags::empty(),
151            ___deadline,
152        )?;
153        Ok(_response)
154    }
155}
156
157#[cfg(target_os = "fuchsia")]
158impl From<DebugSynchronousProxy> for zx::NullableHandle {
159    fn from(value: DebugSynchronousProxy) -> Self {
160        value.into_channel().into()
161    }
162}
163
164#[cfg(target_os = "fuchsia")]
165impl From<fidl::Channel> for DebugSynchronousProxy {
166    fn from(value: fidl::Channel) -> Self {
167        Self::new(value)
168    }
169}
170
171#[cfg(target_os = "fuchsia")]
172impl fidl::endpoints::FromClient for DebugSynchronousProxy {
173    type Protocol = DebugMarker;
174
175    fn from_client(value: fidl::endpoints::ClientEnd<DebugMarker>) -> Self {
176        Self::new(value.into_channel())
177    }
178}
179
180#[derive(Debug, Clone)]
181pub struct DebugProxy {
182    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
183}
184
185impl fidl::endpoints::Proxy for DebugProxy {
186    type Protocol = DebugMarker;
187
188    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
189        Self::new(inner)
190    }
191
192    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
193        self.client.into_channel().map_err(|client| Self { client })
194    }
195
196    fn as_channel(&self) -> &::fidl::AsyncChannel {
197        self.client.as_channel()
198    }
199}
200
201impl DebugProxy {
202    /// Create a new Proxy for fuchsia.hardware.spmi/Debug.
203    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
204        let protocol_name = <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
205        Self { client: fidl::client::Client::new(channel, protocol_name) }
206    }
207
208    /// Get a Stream of events from the remote end of the protocol.
209    ///
210    /// # Panics
211    ///
212    /// Panics if the event stream was already taken.
213    pub fn take_event_stream(&self) -> DebugEventStream {
214        DebugEventStream { event_receiver: self.client.take_event_receiver() }
215    }
216
217    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
218    /// via the corresponding driver node.
219    ///
220    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
221    /// May return an error if there is no such target on the bus; otherwise errors will be returned
222    /// when attempting to access the client.
223    pub fn r#connect_target(
224        &self,
225        mut target_id: u8,
226        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
227    ) -> fidl::client::QueryResponseFut<
228        DebugConnectTargetResult,
229        fidl::encoding::DefaultFuchsiaResourceDialect,
230    > {
231        DebugProxyInterface::r#connect_target(self, target_id, server)
232    }
233
234    /// Returns the properties of the host SPMI controller.
235    pub fn r#get_controller_properties(
236        &self,
237    ) -> fidl::client::QueryResponseFut<
238        DebugGetControllerPropertiesResponse,
239        fidl::encoding::DefaultFuchsiaResourceDialect,
240    > {
241        DebugProxyInterface::r#get_controller_properties(self)
242    }
243}
244
245impl DebugProxyInterface for DebugProxy {
246    type ConnectTargetResponseFut = fidl::client::QueryResponseFut<
247        DebugConnectTargetResult,
248        fidl::encoding::DefaultFuchsiaResourceDialect,
249    >;
250    fn r#connect_target(
251        &self,
252        mut target_id: u8,
253        mut server: fidl::endpoints::ServerEnd<DeviceMarker>,
254    ) -> Self::ConnectTargetResponseFut {
255        fn _decode(
256            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
257        ) -> Result<DebugConnectTargetResult, fidl::Error> {
258            let _response = fidl::client::decode_transaction_body::<
259                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DriverError>,
260                fidl::encoding::DefaultFuchsiaResourceDialect,
261                0xb18ebc371c68d19,
262            >(_buf?)?;
263            Ok(_response.map(|x| x))
264        }
265        self.client.send_query_and_decode::<DebugConnectTargetRequest, DebugConnectTargetResult>(
266            (target_id, server),
267            0xb18ebc371c68d19,
268            fidl::encoding::DynamicFlags::empty(),
269            _decode,
270        )
271    }
272
273    type GetControllerPropertiesResponseFut = fidl::client::QueryResponseFut<
274        DebugGetControllerPropertiesResponse,
275        fidl::encoding::DefaultFuchsiaResourceDialect,
276    >;
277    fn r#get_controller_properties(&self) -> Self::GetControllerPropertiesResponseFut {
278        fn _decode(
279            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
280        ) -> Result<DebugGetControllerPropertiesResponse, fidl::Error> {
281            let _response = fidl::client::decode_transaction_body::<
282                DebugGetControllerPropertiesResponse,
283                fidl::encoding::DefaultFuchsiaResourceDialect,
284                0x41b1c4ef901d051f,
285            >(_buf?)?;
286            Ok(_response)
287        }
288        self.client.send_query_and_decode::<
289            fidl::encoding::EmptyPayload,
290            DebugGetControllerPropertiesResponse,
291        >(
292            (),
293            0x41b1c4ef901d051f,
294            fidl::encoding::DynamicFlags::empty(),
295            _decode,
296        )
297    }
298}
299
300pub struct DebugEventStream {
301    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
302}
303
304impl std::marker::Unpin for DebugEventStream {}
305
306impl futures::stream::FusedStream for DebugEventStream {
307    fn is_terminated(&self) -> bool {
308        self.event_receiver.is_terminated()
309    }
310}
311
312impl futures::Stream for DebugEventStream {
313    type Item = Result<DebugEvent, fidl::Error>;
314
315    fn poll_next(
316        mut self: std::pin::Pin<&mut Self>,
317        cx: &mut std::task::Context<'_>,
318    ) -> std::task::Poll<Option<Self::Item>> {
319        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
320            &mut self.event_receiver,
321            cx
322        )?) {
323            Some(buf) => std::task::Poll::Ready(Some(DebugEvent::decode(buf))),
324            None => std::task::Poll::Ready(None),
325        }
326    }
327}
328
329#[derive(Debug)]
330pub enum DebugEvent {
331    #[non_exhaustive]
332    _UnknownEvent {
333        /// Ordinal of the event that was sent.
334        ordinal: u64,
335    },
336}
337
338impl DebugEvent {
339    /// Decodes a message buffer as a [`DebugEvent`].
340    fn decode(
341        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
342    ) -> Result<DebugEvent, fidl::Error> {
343        let (bytes, _handles) = buf.split_mut();
344        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
345        debug_assert_eq!(tx_header.tx_id, 0);
346        match tx_header.ordinal {
347            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
348                Ok(DebugEvent::_UnknownEvent { ordinal: tx_header.ordinal })
349            }
350            _ => Err(fidl::Error::UnknownOrdinal {
351                ordinal: tx_header.ordinal,
352                protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
353            }),
354        }
355    }
356}
357
358/// A Stream of incoming requests for fuchsia.hardware.spmi/Debug.
359pub struct DebugRequestStream {
360    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
361    is_terminated: bool,
362}
363
364impl std::marker::Unpin for DebugRequestStream {}
365
366impl futures::stream::FusedStream for DebugRequestStream {
367    fn is_terminated(&self) -> bool {
368        self.is_terminated
369    }
370}
371
372impl fidl::endpoints::RequestStream for DebugRequestStream {
373    type Protocol = DebugMarker;
374    type ControlHandle = DebugControlHandle;
375
376    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
377        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
378    }
379
380    fn control_handle(&self) -> Self::ControlHandle {
381        DebugControlHandle { inner: self.inner.clone() }
382    }
383
384    fn into_inner(
385        self,
386    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
387    {
388        (self.inner, self.is_terminated)
389    }
390
391    fn from_inner(
392        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
393        is_terminated: bool,
394    ) -> Self {
395        Self { inner, is_terminated }
396    }
397}
398
399impl futures::Stream for DebugRequestStream {
400    type Item = Result<DebugRequest, fidl::Error>;
401
402    fn poll_next(
403        mut self: std::pin::Pin<&mut Self>,
404        cx: &mut std::task::Context<'_>,
405    ) -> std::task::Poll<Option<Self::Item>> {
406        let this = &mut *self;
407        if this.inner.check_shutdown(cx) {
408            this.is_terminated = true;
409            return std::task::Poll::Ready(None);
410        }
411        if this.is_terminated {
412            panic!("polled DebugRequestStream after completion");
413        }
414        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
415            |bytes, handles| {
416                match this.inner.channel().read_etc(cx, bytes, handles) {
417                    std::task::Poll::Ready(Ok(())) => {}
418                    std::task::Poll::Pending => return std::task::Poll::Pending,
419                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
420                        this.is_terminated = true;
421                        return std::task::Poll::Ready(None);
422                    }
423                    std::task::Poll::Ready(Err(e)) => {
424                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
425                            e.into(),
426                        ))));
427                    }
428                }
429
430                // A message has been received from the channel
431                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
432
433                std::task::Poll::Ready(Some(match header.ordinal {
434                    0xb18ebc371c68d19 => {
435                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
436                        let mut req = fidl::new_empty!(
437                            DebugConnectTargetRequest,
438                            fidl::encoding::DefaultFuchsiaResourceDialect
439                        );
440                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DebugConnectTargetRequest>(&header, _body_bytes, handles, &mut req)?;
441                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
442                        Ok(DebugRequest::ConnectTarget {
443                            target_id: req.target_id,
444                            server: req.server,
445
446                            responder: DebugConnectTargetResponder {
447                                control_handle: std::mem::ManuallyDrop::new(control_handle),
448                                tx_id: header.tx_id,
449                            },
450                        })
451                    }
452                    0x41b1c4ef901d051f => {
453                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
454                        let mut req = fidl::new_empty!(
455                            fidl::encoding::EmptyPayload,
456                            fidl::encoding::DefaultFuchsiaResourceDialect
457                        );
458                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
459                        let control_handle = DebugControlHandle { inner: this.inner.clone() };
460                        Ok(DebugRequest::GetControllerProperties {
461                            responder: DebugGetControllerPropertiesResponder {
462                                control_handle: std::mem::ManuallyDrop::new(control_handle),
463                                tx_id: header.tx_id,
464                            },
465                        })
466                    }
467                    _ if header.tx_id == 0
468                        && header
469                            .dynamic_flags()
470                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
471                    {
472                        Ok(DebugRequest::_UnknownMethod {
473                            ordinal: header.ordinal,
474                            control_handle: DebugControlHandle { inner: this.inner.clone() },
475                            method_type: fidl::MethodType::OneWay,
476                        })
477                    }
478                    _ if header
479                        .dynamic_flags()
480                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
481                    {
482                        this.inner.send_framework_err(
483                            fidl::encoding::FrameworkErr::UnknownMethod,
484                            header.tx_id,
485                            header.ordinal,
486                            header.dynamic_flags(),
487                            (bytes, handles),
488                        )?;
489                        Ok(DebugRequest::_UnknownMethod {
490                            ordinal: header.ordinal,
491                            control_handle: DebugControlHandle { inner: this.inner.clone() },
492                            method_type: fidl::MethodType::TwoWay,
493                        })
494                    }
495                    _ => Err(fidl::Error::UnknownOrdinal {
496                        ordinal: header.ordinal,
497                        protocol_name: <DebugMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
498                    }),
499                }))
500            },
501        )
502    }
503}
504
505#[derive(Debug)]
506pub enum DebugRequest {
507    /// Connects to the target device with the given ID. Equivalent to connecting to `TargetService`
508    /// via the corresponding driver node.
509    ///
510    /// Returns `INVALID_ARGS` if `target_id` is greater than or equal to `MAX_TARGETS`.
511    /// May return an error if there is no such target on the bus; otherwise errors will be returned
512    /// when attempting to access the client.
513    ConnectTarget {
514        target_id: u8,
515        server: fidl::endpoints::ServerEnd<DeviceMarker>,
516        responder: DebugConnectTargetResponder,
517    },
518    /// Returns the properties of the host SPMI controller.
519    GetControllerProperties { responder: DebugGetControllerPropertiesResponder },
520    /// An interaction was received which does not match any known method.
521    #[non_exhaustive]
522    _UnknownMethod {
523        /// Ordinal of the method that was called.
524        ordinal: u64,
525        control_handle: DebugControlHandle,
526        method_type: fidl::MethodType,
527    },
528}
529
530impl DebugRequest {
531    #[allow(irrefutable_let_patterns)]
532    pub fn into_connect_target(
533        self,
534    ) -> Option<(u8, fidl::endpoints::ServerEnd<DeviceMarker>, DebugConnectTargetResponder)> {
535        if let DebugRequest::ConnectTarget { target_id, server, responder } = self {
536            Some((target_id, server, responder))
537        } else {
538            None
539        }
540    }
541
542    #[allow(irrefutable_let_patterns)]
543    pub fn into_get_controller_properties(self) -> Option<(DebugGetControllerPropertiesResponder)> {
544        if let DebugRequest::GetControllerProperties { responder } = self {
545            Some((responder))
546        } else {
547            None
548        }
549    }
550
551    /// Name of the method defined in FIDL
552    pub fn method_name(&self) -> &'static str {
553        match *self {
554            DebugRequest::ConnectTarget { .. } => "connect_target",
555            DebugRequest::GetControllerProperties { .. } => "get_controller_properties",
556            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
557                "unknown one-way method"
558            }
559            DebugRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
560                "unknown two-way method"
561            }
562        }
563    }
564}
565
566#[derive(Debug, Clone)]
567pub struct DebugControlHandle {
568    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
569}
570
571impl fidl::endpoints::ControlHandle for DebugControlHandle {
572    fn shutdown(&self) {
573        self.inner.shutdown()
574    }
575
576    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
577        self.inner.shutdown_with_epitaph(status)
578    }
579
580    fn is_closed(&self) -> bool {
581        self.inner.channel().is_closed()
582    }
583    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
584        self.inner.channel().on_closed()
585    }
586
587    #[cfg(target_os = "fuchsia")]
588    fn signal_peer(
589        &self,
590        clear_mask: zx::Signals,
591        set_mask: zx::Signals,
592    ) -> Result<(), zx_status::Status> {
593        use fidl::Peered;
594        self.inner.channel().signal_peer(clear_mask, set_mask)
595    }
596}
597
598impl DebugControlHandle {}
599
600#[must_use = "FIDL methods require a response to be sent"]
601#[derive(Debug)]
602pub struct DebugConnectTargetResponder {
603    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
604    tx_id: u32,
605}
606
607/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
608/// if the responder is dropped without sending a response, so that the client
609/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
610impl std::ops::Drop for DebugConnectTargetResponder {
611    fn drop(&mut self) {
612        self.control_handle.shutdown();
613        // Safety: drops once, never accessed again
614        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
615    }
616}
617
618impl fidl::endpoints::Responder for DebugConnectTargetResponder {
619    type ControlHandle = DebugControlHandle;
620
621    fn control_handle(&self) -> &DebugControlHandle {
622        &self.control_handle
623    }
624
625    fn drop_without_shutdown(mut self) {
626        // Safety: drops once, never accessed again due to mem::forget
627        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
628        // Prevent Drop from running (which would shut down the channel)
629        std::mem::forget(self);
630    }
631}
632
633impl DebugConnectTargetResponder {
634    /// Sends a response to the FIDL transaction.
635    ///
636    /// Sets the channel to shutdown if an error occurs.
637    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
638        let _result = self.send_raw(result);
639        if _result.is_err() {
640            self.control_handle.shutdown();
641        }
642        self.drop_without_shutdown();
643        _result
644    }
645
646    /// Similar to "send" but does not shutdown the channel if an error occurs.
647    pub fn send_no_shutdown_on_err(
648        self,
649        mut result: Result<(), DriverError>,
650    ) -> Result<(), fidl::Error> {
651        let _result = self.send_raw(result);
652        self.drop_without_shutdown();
653        _result
654    }
655
656    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
657        self.control_handle.inner.send::<fidl::encoding::ResultType<
658            fidl::encoding::EmptyStruct,
659            DriverError,
660        >>(
661            result,
662            self.tx_id,
663            0xb18ebc371c68d19,
664            fidl::encoding::DynamicFlags::empty(),
665        )
666    }
667}
668
669#[must_use = "FIDL methods require a response to be sent"]
670#[derive(Debug)]
671pub struct DebugGetControllerPropertiesResponder {
672    control_handle: std::mem::ManuallyDrop<DebugControlHandle>,
673    tx_id: u32,
674}
675
676/// Set the the channel to be shutdown (see [`DebugControlHandle::shutdown`])
677/// if the responder is dropped without sending a response, so that the client
678/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
679impl std::ops::Drop for DebugGetControllerPropertiesResponder {
680    fn drop(&mut self) {
681        self.control_handle.shutdown();
682        // Safety: drops once, never accessed again
683        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
684    }
685}
686
687impl fidl::endpoints::Responder for DebugGetControllerPropertiesResponder {
688    type ControlHandle = DebugControlHandle;
689
690    fn control_handle(&self) -> &DebugControlHandle {
691        &self.control_handle
692    }
693
694    fn drop_without_shutdown(mut self) {
695        // Safety: drops once, never accessed again due to mem::forget
696        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
697        // Prevent Drop from running (which would shut down the channel)
698        std::mem::forget(self);
699    }
700}
701
702impl DebugGetControllerPropertiesResponder {
703    /// Sends a response to the FIDL transaction.
704    ///
705    /// Sets the channel to shutdown if an error occurs.
706    pub fn send(
707        self,
708        mut payload: &DebugGetControllerPropertiesResponse,
709    ) -> Result<(), fidl::Error> {
710        let _result = self.send_raw(payload);
711        if _result.is_err() {
712            self.control_handle.shutdown();
713        }
714        self.drop_without_shutdown();
715        _result
716    }
717
718    /// Similar to "send" but does not shutdown the channel if an error occurs.
719    pub fn send_no_shutdown_on_err(
720        self,
721        mut payload: &DebugGetControllerPropertiesResponse,
722    ) -> Result<(), fidl::Error> {
723        let _result = self.send_raw(payload);
724        self.drop_without_shutdown();
725        _result
726    }
727
728    fn send_raw(
729        &self,
730        mut payload: &DebugGetControllerPropertiesResponse,
731    ) -> Result<(), fidl::Error> {
732        self.control_handle.inner.send::<DebugGetControllerPropertiesResponse>(
733            payload,
734            self.tx_id,
735            0x41b1c4ef901d051f,
736            fidl::encoding::DynamicFlags::empty(),
737        )
738    }
739}
740
741#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
742pub struct DeviceMarker;
743
744impl fidl::endpoints::ProtocolMarker for DeviceMarker {
745    type Proxy = DeviceProxy;
746    type RequestStream = DeviceRequestStream;
747    #[cfg(target_os = "fuchsia")]
748    type SynchronousProxy = DeviceSynchronousProxy;
749
750    const DEBUG_NAME: &'static str = "fuchsia.hardware.spmi.Device";
751}
752impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
753pub type DeviceRegisterReadResult = Result<Vec<u8>, DriverError>;
754pub type DeviceRegisterWriteResult = Result<(), DriverError>;
755pub type DeviceWatchControllerWriteCommandsResult =
756    Result<(Vec<Register8>, Option<fidl::EventPair>), DriverError>;
757pub type DeviceCancelWatchControllerWriteCommandsResult = Result<(), DriverError>;
758
759pub trait DeviceProxyInterface: Send + Sync {
760    type RegisterReadResponseFut: std::future::Future<Output = Result<DeviceRegisterReadResult, fidl::Error>>
761        + Send;
762    fn r#register_read(&self, address: u16, size_bytes: u32) -> Self::RegisterReadResponseFut;
763    type RegisterWriteResponseFut: std::future::Future<Output = Result<DeviceRegisterWriteResult, fidl::Error>>
764        + Send;
765    fn r#register_write(&self, address: u16, data: &[u8]) -> Self::RegisterWriteResponseFut;
766    type GetPropertiesResponseFut: std::future::Future<Output = Result<DeviceGetPropertiesResponse, fidl::Error>>
767        + Send;
768    fn r#get_properties(&self) -> Self::GetPropertiesResponseFut;
769    type WatchControllerWriteCommandsResponseFut: std::future::Future<Output = Result<DeviceWatchControllerWriteCommandsResult, fidl::Error>>
770        + Send;
771    fn r#watch_controller_write_commands(
772        &self,
773        address: u8,
774        size: u16,
775        setup_wake_lease: Option<fidl::EventPair>,
776    ) -> Self::WatchControllerWriteCommandsResponseFut;
777    type CancelWatchControllerWriteCommandsResponseFut: std::future::Future<
778            Output = Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error>,
779        > + Send;
780    fn r#cancel_watch_controller_write_commands(
781        &self,
782        address: u8,
783        size: u16,
784    ) -> Self::CancelWatchControllerWriteCommandsResponseFut;
785}
786#[derive(Debug)]
787#[cfg(target_os = "fuchsia")]
788pub struct DeviceSynchronousProxy {
789    client: fidl::client::sync::Client,
790}
791
792#[cfg(target_os = "fuchsia")]
793impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
794    type Proxy = DeviceProxy;
795    type Protocol = DeviceMarker;
796
797    fn from_channel(inner: fidl::Channel) -> Self {
798        Self::new(inner)
799    }
800
801    fn into_channel(self) -> fidl::Channel {
802        self.client.into_channel()
803    }
804
805    fn as_channel(&self) -> &fidl::Channel {
806        self.client.as_channel()
807    }
808}
809
810#[cfg(target_os = "fuchsia")]
811impl DeviceSynchronousProxy {
812    pub fn new(channel: fidl::Channel) -> Self {
813        Self { client: fidl::client::sync::Client::new(channel) }
814    }
815
816    pub fn into_channel(self) -> fidl::Channel {
817        self.client.into_channel()
818    }
819
820    /// Waits until an event arrives and returns it. It is safe for other
821    /// threads to make concurrent requests while waiting for an event.
822    pub fn wait_for_event(
823        &self,
824        deadline: zx::MonotonicInstant,
825    ) -> Result<DeviceEvent, fidl::Error> {
826        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
827    }
828
829    /// Issue register read commands to the SPMI device.
830    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
831    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
832    /// `address` in the device.
833    pub fn r#register_read(
834        &self,
835        mut address: u16,
836        mut size_bytes: u32,
837        ___deadline: zx::MonotonicInstant,
838    ) -> Result<DeviceRegisterReadResult, fidl::Error> {
839        let _response = self.client.send_query::<
840            DeviceRegisterReadRequest,
841            fidl::encoding::FlexibleResultType<DeviceRegisterReadResponse, DriverError>,
842            DeviceMarker,
843        >(
844            (address, size_bytes,),
845            0x1b0f6eff7638b5,
846            fidl::encoding::DynamicFlags::FLEXIBLE,
847            ___deadline,
848        )?
849        .into_result::<DeviceMarker>("register_read")?;
850        Ok(_response.map(|x| x.data))
851    }
852
853    /// Issue register write commands to the SPMI device.
854    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
855    /// When this command is successful, `data` will be written contiguously starting from
856    /// `address` in the device.
857    pub fn r#register_write(
858        &self,
859        mut address: u16,
860        mut data: &[u8],
861        ___deadline: zx::MonotonicInstant,
862    ) -> Result<DeviceRegisterWriteResult, fidl::Error> {
863        let _response = self.client.send_query::<
864            DeviceRegisterWriteRequest,
865            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
866            DeviceMarker,
867        >(
868            (address, data,),
869            0xe7f4ed59770bb2b,
870            fidl::encoding::DynamicFlags::FLEXIBLE,
871            ___deadline,
872        )?
873        .into_result::<DeviceMarker>("register_write")?;
874        Ok(_response.map(|x| x))
875    }
876
877    /// Get the properties of the SPMI device.
878    pub fn r#get_properties(
879        &self,
880        ___deadline: zx::MonotonicInstant,
881    ) -> Result<DeviceGetPropertiesResponse, fidl::Error> {
882        let _response = self.client.send_query::<
883            fidl::encoding::EmptyPayload,
884            fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>,
885            DeviceMarker,
886        >(
887            (),
888            0x1e946ec04006ffbb,
889            fidl::encoding::DynamicFlags::FLEXIBLE,
890            ___deadline,
891        )?
892        .into_result::<DeviceMarker>("get_properties")?;
893        Ok(_response)
894    }
895
896    /// Hanging-get method to receive controller write commands from the device. `address` and
897    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
898    /// this method are not allowed.
899    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
900    /// is pending for this register range. Returns `CANCELED` if
901    /// `CancelWatchControllerWriteCommands()` was called for this register range.
902    ///
903    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
904    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
905    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
906    ///
907    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
908    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
909    /// Activity Governor.
910    ///
911    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
912    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
913    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
914    /// the system needs to stay awake, or a client must get its own wake lease from the Power
915    /// Framework before it drops `wake_lease` to prevent suspension.
916    pub fn r#watch_controller_write_commands(
917        &self,
918        mut address: u8,
919        mut size: u16,
920        mut setup_wake_lease: Option<fidl::EventPair>,
921        ___deadline: zx::MonotonicInstant,
922    ) -> Result<DeviceWatchControllerWriteCommandsResult, fidl::Error> {
923        let _response = self.client.send_query::<
924            DeviceWatchControllerWriteCommandsRequest,
925            fidl::encoding::FlexibleResultType<DeviceWatchControllerWriteCommandsResponse, DriverError>,
926            DeviceMarker,
927        >(
928            (address, size, setup_wake_lease,),
929            0x41674c1eba4d05ac,
930            fidl::encoding::DynamicFlags::FLEXIBLE,
931            ___deadline,
932        )?
933        .into_result::<DeviceMarker>("watch_controller_write_commands")?;
934        Ok(_response.map(|x| (x.writes, x.wake_lease)))
935    }
936
937    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
938    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
939    /// is returned.
940    pub fn r#cancel_watch_controller_write_commands(
941        &self,
942        mut address: u8,
943        mut size: u16,
944        ___deadline: zx::MonotonicInstant,
945    ) -> Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error> {
946        let _response = self.client.send_query::<
947            DeviceCancelWatchControllerWriteCommandsRequest,
948            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
949            DeviceMarker,
950        >(
951            (address, size,),
952            0x5057c280e6f0d420,
953            fidl::encoding::DynamicFlags::FLEXIBLE,
954            ___deadline,
955        )?
956        .into_result::<DeviceMarker>("cancel_watch_controller_write_commands")?;
957        Ok(_response.map(|x| x))
958    }
959}
960
961#[cfg(target_os = "fuchsia")]
962impl From<DeviceSynchronousProxy> for zx::NullableHandle {
963    fn from(value: DeviceSynchronousProxy) -> Self {
964        value.into_channel().into()
965    }
966}
967
968#[cfg(target_os = "fuchsia")]
969impl From<fidl::Channel> for DeviceSynchronousProxy {
970    fn from(value: fidl::Channel) -> Self {
971        Self::new(value)
972    }
973}
974
975#[cfg(target_os = "fuchsia")]
976impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
977    type Protocol = DeviceMarker;
978
979    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
980        Self::new(value.into_channel())
981    }
982}
983
984#[derive(Debug, Clone)]
985pub struct DeviceProxy {
986    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
987}
988
989impl fidl::endpoints::Proxy for DeviceProxy {
990    type Protocol = DeviceMarker;
991
992    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
993        Self::new(inner)
994    }
995
996    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
997        self.client.into_channel().map_err(|client| Self { client })
998    }
999
1000    fn as_channel(&self) -> &::fidl::AsyncChannel {
1001        self.client.as_channel()
1002    }
1003}
1004
1005impl DeviceProxy {
1006    /// Create a new Proxy for fuchsia.hardware.spmi/Device.
1007    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1008        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1009        Self { client: fidl::client::Client::new(channel, protocol_name) }
1010    }
1011
1012    /// Get a Stream of events from the remote end of the protocol.
1013    ///
1014    /// # Panics
1015    ///
1016    /// Panics if the event stream was already taken.
1017    pub fn take_event_stream(&self) -> DeviceEventStream {
1018        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
1019    }
1020
1021    /// Issue register read commands to the SPMI device.
1022    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1023    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
1024    /// `address` in the device.
1025    pub fn r#register_read(
1026        &self,
1027        mut address: u16,
1028        mut size_bytes: u32,
1029    ) -> fidl::client::QueryResponseFut<
1030        DeviceRegisterReadResult,
1031        fidl::encoding::DefaultFuchsiaResourceDialect,
1032    > {
1033        DeviceProxyInterface::r#register_read(self, address, size_bytes)
1034    }
1035
1036    /// Issue register write commands to the SPMI device.
1037    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1038    /// When this command is successful, `data` will be written contiguously starting from
1039    /// `address` in the device.
1040    pub fn r#register_write(
1041        &self,
1042        mut address: u16,
1043        mut data: &[u8],
1044    ) -> fidl::client::QueryResponseFut<
1045        DeviceRegisterWriteResult,
1046        fidl::encoding::DefaultFuchsiaResourceDialect,
1047    > {
1048        DeviceProxyInterface::r#register_write(self, address, data)
1049    }
1050
1051    /// Get the properties of the SPMI device.
1052    pub fn r#get_properties(
1053        &self,
1054    ) -> fidl::client::QueryResponseFut<
1055        DeviceGetPropertiesResponse,
1056        fidl::encoding::DefaultFuchsiaResourceDialect,
1057    > {
1058        DeviceProxyInterface::r#get_properties(self)
1059    }
1060
1061    /// Hanging-get method to receive controller write commands from the device. `address` and
1062    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
1063    /// this method are not allowed.
1064    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
1065    /// is pending for this register range. Returns `CANCELED` if
1066    /// `CancelWatchControllerWriteCommands()` was called for this register range.
1067    ///
1068    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
1069    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
1070    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
1071    ///
1072    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
1073    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
1074    /// Activity Governor.
1075    ///
1076    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
1077    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
1078    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
1079    /// the system needs to stay awake, or a client must get its own wake lease from the Power
1080    /// Framework before it drops `wake_lease` to prevent suspension.
1081    pub fn r#watch_controller_write_commands(
1082        &self,
1083        mut address: u8,
1084        mut size: u16,
1085        mut setup_wake_lease: Option<fidl::EventPair>,
1086    ) -> fidl::client::QueryResponseFut<
1087        DeviceWatchControllerWriteCommandsResult,
1088        fidl::encoding::DefaultFuchsiaResourceDialect,
1089    > {
1090        DeviceProxyInterface::r#watch_controller_write_commands(
1091            self,
1092            address,
1093            size,
1094            setup_wake_lease,
1095        )
1096    }
1097
1098    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
1099    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
1100    /// is returned.
1101    pub fn r#cancel_watch_controller_write_commands(
1102        &self,
1103        mut address: u8,
1104        mut size: u16,
1105    ) -> fidl::client::QueryResponseFut<
1106        DeviceCancelWatchControllerWriteCommandsResult,
1107        fidl::encoding::DefaultFuchsiaResourceDialect,
1108    > {
1109        DeviceProxyInterface::r#cancel_watch_controller_write_commands(self, address, size)
1110    }
1111}
1112
1113impl DeviceProxyInterface for DeviceProxy {
1114    type RegisterReadResponseFut = fidl::client::QueryResponseFut<
1115        DeviceRegisterReadResult,
1116        fidl::encoding::DefaultFuchsiaResourceDialect,
1117    >;
1118    fn r#register_read(
1119        &self,
1120        mut address: u16,
1121        mut size_bytes: u32,
1122    ) -> Self::RegisterReadResponseFut {
1123        fn _decode(
1124            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1125        ) -> Result<DeviceRegisterReadResult, fidl::Error> {
1126            let _response = fidl::client::decode_transaction_body::<
1127                fidl::encoding::FlexibleResultType<DeviceRegisterReadResponse, DriverError>,
1128                fidl::encoding::DefaultFuchsiaResourceDialect,
1129                0x1b0f6eff7638b5,
1130            >(_buf?)?
1131            .into_result::<DeviceMarker>("register_read")?;
1132            Ok(_response.map(|x| x.data))
1133        }
1134        self.client.send_query_and_decode::<DeviceRegisterReadRequest, DeviceRegisterReadResult>(
1135            (address, size_bytes),
1136            0x1b0f6eff7638b5,
1137            fidl::encoding::DynamicFlags::FLEXIBLE,
1138            _decode,
1139        )
1140    }
1141
1142    type RegisterWriteResponseFut = fidl::client::QueryResponseFut<
1143        DeviceRegisterWriteResult,
1144        fidl::encoding::DefaultFuchsiaResourceDialect,
1145    >;
1146    fn r#register_write(
1147        &self,
1148        mut address: u16,
1149        mut data: &[u8],
1150    ) -> Self::RegisterWriteResponseFut {
1151        fn _decode(
1152            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1153        ) -> Result<DeviceRegisterWriteResult, fidl::Error> {
1154            let _response = fidl::client::decode_transaction_body::<
1155                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
1156                fidl::encoding::DefaultFuchsiaResourceDialect,
1157                0xe7f4ed59770bb2b,
1158            >(_buf?)?
1159            .into_result::<DeviceMarker>("register_write")?;
1160            Ok(_response.map(|x| x))
1161        }
1162        self.client.send_query_and_decode::<DeviceRegisterWriteRequest, DeviceRegisterWriteResult>(
1163            (address, data),
1164            0xe7f4ed59770bb2b,
1165            fidl::encoding::DynamicFlags::FLEXIBLE,
1166            _decode,
1167        )
1168    }
1169
1170    type GetPropertiesResponseFut = fidl::client::QueryResponseFut<
1171        DeviceGetPropertiesResponse,
1172        fidl::encoding::DefaultFuchsiaResourceDialect,
1173    >;
1174    fn r#get_properties(&self) -> Self::GetPropertiesResponseFut {
1175        fn _decode(
1176            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1177        ) -> Result<DeviceGetPropertiesResponse, fidl::Error> {
1178            let _response = fidl::client::decode_transaction_body::<
1179                fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>,
1180                fidl::encoding::DefaultFuchsiaResourceDialect,
1181                0x1e946ec04006ffbb,
1182            >(_buf?)?
1183            .into_result::<DeviceMarker>("get_properties")?;
1184            Ok(_response)
1185        }
1186        self.client
1187            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetPropertiesResponse>(
1188                (),
1189                0x1e946ec04006ffbb,
1190                fidl::encoding::DynamicFlags::FLEXIBLE,
1191                _decode,
1192            )
1193    }
1194
1195    type WatchControllerWriteCommandsResponseFut = fidl::client::QueryResponseFut<
1196        DeviceWatchControllerWriteCommandsResult,
1197        fidl::encoding::DefaultFuchsiaResourceDialect,
1198    >;
1199    fn r#watch_controller_write_commands(
1200        &self,
1201        mut address: u8,
1202        mut size: u16,
1203        mut setup_wake_lease: Option<fidl::EventPair>,
1204    ) -> Self::WatchControllerWriteCommandsResponseFut {
1205        fn _decode(
1206            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1207        ) -> Result<DeviceWatchControllerWriteCommandsResult, fidl::Error> {
1208            let _response = fidl::client::decode_transaction_body::<
1209                fidl::encoding::FlexibleResultType<
1210                    DeviceWatchControllerWriteCommandsResponse,
1211                    DriverError,
1212                >,
1213                fidl::encoding::DefaultFuchsiaResourceDialect,
1214                0x41674c1eba4d05ac,
1215            >(_buf?)?
1216            .into_result::<DeviceMarker>("watch_controller_write_commands")?;
1217            Ok(_response.map(|x| (x.writes, x.wake_lease)))
1218        }
1219        self.client.send_query_and_decode::<
1220            DeviceWatchControllerWriteCommandsRequest,
1221            DeviceWatchControllerWriteCommandsResult,
1222        >(
1223            (address, size, setup_wake_lease,),
1224            0x41674c1eba4d05ac,
1225            fidl::encoding::DynamicFlags::FLEXIBLE,
1226            _decode,
1227        )
1228    }
1229
1230    type CancelWatchControllerWriteCommandsResponseFut = fidl::client::QueryResponseFut<
1231        DeviceCancelWatchControllerWriteCommandsResult,
1232        fidl::encoding::DefaultFuchsiaResourceDialect,
1233    >;
1234    fn r#cancel_watch_controller_write_commands(
1235        &self,
1236        mut address: u8,
1237        mut size: u16,
1238    ) -> Self::CancelWatchControllerWriteCommandsResponseFut {
1239        fn _decode(
1240            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1241        ) -> Result<DeviceCancelWatchControllerWriteCommandsResult, fidl::Error> {
1242            let _response = fidl::client::decode_transaction_body::<
1243                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, DriverError>,
1244                fidl::encoding::DefaultFuchsiaResourceDialect,
1245                0x5057c280e6f0d420,
1246            >(_buf?)?
1247            .into_result::<DeviceMarker>("cancel_watch_controller_write_commands")?;
1248            Ok(_response.map(|x| x))
1249        }
1250        self.client.send_query_and_decode::<
1251            DeviceCancelWatchControllerWriteCommandsRequest,
1252            DeviceCancelWatchControllerWriteCommandsResult,
1253        >(
1254            (address, size,),
1255            0x5057c280e6f0d420,
1256            fidl::encoding::DynamicFlags::FLEXIBLE,
1257            _decode,
1258        )
1259    }
1260}
1261
1262pub struct DeviceEventStream {
1263    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1264}
1265
1266impl std::marker::Unpin for DeviceEventStream {}
1267
1268impl futures::stream::FusedStream for DeviceEventStream {
1269    fn is_terminated(&self) -> bool {
1270        self.event_receiver.is_terminated()
1271    }
1272}
1273
1274impl futures::Stream for DeviceEventStream {
1275    type Item = Result<DeviceEvent, fidl::Error>;
1276
1277    fn poll_next(
1278        mut self: std::pin::Pin<&mut Self>,
1279        cx: &mut std::task::Context<'_>,
1280    ) -> std::task::Poll<Option<Self::Item>> {
1281        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1282            &mut self.event_receiver,
1283            cx
1284        )?) {
1285            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
1286            None => std::task::Poll::Ready(None),
1287        }
1288    }
1289}
1290
1291#[derive(Debug)]
1292pub enum DeviceEvent {
1293    #[non_exhaustive]
1294    _UnknownEvent {
1295        /// Ordinal of the event that was sent.
1296        ordinal: u64,
1297    },
1298}
1299
1300impl DeviceEvent {
1301    /// Decodes a message buffer as a [`DeviceEvent`].
1302    fn decode(
1303        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1304    ) -> Result<DeviceEvent, fidl::Error> {
1305        let (bytes, _handles) = buf.split_mut();
1306        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1307        debug_assert_eq!(tx_header.tx_id, 0);
1308        match tx_header.ordinal {
1309            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1310                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1311            }
1312            _ => Err(fidl::Error::UnknownOrdinal {
1313                ordinal: tx_header.ordinal,
1314                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1315            }),
1316        }
1317    }
1318}
1319
1320/// A Stream of incoming requests for fuchsia.hardware.spmi/Device.
1321pub struct DeviceRequestStream {
1322    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1323    is_terminated: bool,
1324}
1325
1326impl std::marker::Unpin for DeviceRequestStream {}
1327
1328impl futures::stream::FusedStream for DeviceRequestStream {
1329    fn is_terminated(&self) -> bool {
1330        self.is_terminated
1331    }
1332}
1333
1334impl fidl::endpoints::RequestStream for DeviceRequestStream {
1335    type Protocol = DeviceMarker;
1336    type ControlHandle = DeviceControlHandle;
1337
1338    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1339        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1340    }
1341
1342    fn control_handle(&self) -> Self::ControlHandle {
1343        DeviceControlHandle { inner: self.inner.clone() }
1344    }
1345
1346    fn into_inner(
1347        self,
1348    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1349    {
1350        (self.inner, self.is_terminated)
1351    }
1352
1353    fn from_inner(
1354        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1355        is_terminated: bool,
1356    ) -> Self {
1357        Self { inner, is_terminated }
1358    }
1359}
1360
1361impl futures::Stream for DeviceRequestStream {
1362    type Item = Result<DeviceRequest, fidl::Error>;
1363
1364    fn poll_next(
1365        mut self: std::pin::Pin<&mut Self>,
1366        cx: &mut std::task::Context<'_>,
1367    ) -> std::task::Poll<Option<Self::Item>> {
1368        let this = &mut *self;
1369        if this.inner.check_shutdown(cx) {
1370            this.is_terminated = true;
1371            return std::task::Poll::Ready(None);
1372        }
1373        if this.is_terminated {
1374            panic!("polled DeviceRequestStream after completion");
1375        }
1376        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1377            |bytes, handles| {
1378                match this.inner.channel().read_etc(cx, bytes, handles) {
1379                    std::task::Poll::Ready(Ok(())) => {}
1380                    std::task::Poll::Pending => return std::task::Poll::Pending,
1381                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1382                        this.is_terminated = true;
1383                        return std::task::Poll::Ready(None);
1384                    }
1385                    std::task::Poll::Ready(Err(e)) => {
1386                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1387                            e.into(),
1388                        ))));
1389                    }
1390                }
1391
1392                // A message has been received from the channel
1393                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1394
1395                std::task::Poll::Ready(Some(match header.ordinal {
1396                    0x1b0f6eff7638b5 => {
1397                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1398                        let mut req = fidl::new_empty!(
1399                            DeviceRegisterReadRequest,
1400                            fidl::encoding::DefaultFuchsiaResourceDialect
1401                        );
1402                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceRegisterReadRequest>(&header, _body_bytes, handles, &mut req)?;
1403                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1404                        Ok(DeviceRequest::RegisterRead {
1405                            address: req.address,
1406                            size_bytes: req.size_bytes,
1407
1408                            responder: DeviceRegisterReadResponder {
1409                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1410                                tx_id: header.tx_id,
1411                            },
1412                        })
1413                    }
1414                    0xe7f4ed59770bb2b => {
1415                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1416                        let mut req = fidl::new_empty!(
1417                            DeviceRegisterWriteRequest,
1418                            fidl::encoding::DefaultFuchsiaResourceDialect
1419                        );
1420                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceRegisterWriteRequest>(&header, _body_bytes, handles, &mut req)?;
1421                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1422                        Ok(DeviceRequest::RegisterWrite {
1423                            address: req.address,
1424                            data: req.data,
1425
1426                            responder: DeviceRegisterWriteResponder {
1427                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1428                                tx_id: header.tx_id,
1429                            },
1430                        })
1431                    }
1432                    0x1e946ec04006ffbb => {
1433                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1434                        let mut req = fidl::new_empty!(
1435                            fidl::encoding::EmptyPayload,
1436                            fidl::encoding::DefaultFuchsiaResourceDialect
1437                        );
1438                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1439                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1440                        Ok(DeviceRequest::GetProperties {
1441                            responder: DeviceGetPropertiesResponder {
1442                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1443                                tx_id: header.tx_id,
1444                            },
1445                        })
1446                    }
1447                    0x41674c1eba4d05ac => {
1448                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1449                        let mut req = fidl::new_empty!(
1450                            DeviceWatchControllerWriteCommandsRequest,
1451                            fidl::encoding::DefaultFuchsiaResourceDialect
1452                        );
1453                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceWatchControllerWriteCommandsRequest>(&header, _body_bytes, handles, &mut req)?;
1454                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1455                        Ok(DeviceRequest::WatchControllerWriteCommands {
1456                            address: req.address,
1457                            size: req.size,
1458                            setup_wake_lease: req.setup_wake_lease,
1459
1460                            responder: DeviceWatchControllerWriteCommandsResponder {
1461                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1462                                tx_id: header.tx_id,
1463                            },
1464                        })
1465                    }
1466                    0x5057c280e6f0d420 => {
1467                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1468                        let mut req = fidl::new_empty!(
1469                            DeviceCancelWatchControllerWriteCommandsRequest,
1470                            fidl::encoding::DefaultFuchsiaResourceDialect
1471                        );
1472                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceCancelWatchControllerWriteCommandsRequest>(&header, _body_bytes, handles, &mut req)?;
1473                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
1474                        Ok(DeviceRequest::CancelWatchControllerWriteCommands {
1475                            address: req.address,
1476                            size: req.size,
1477
1478                            responder: DeviceCancelWatchControllerWriteCommandsResponder {
1479                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1480                                tx_id: header.tx_id,
1481                            },
1482                        })
1483                    }
1484                    _ if header.tx_id == 0
1485                        && header
1486                            .dynamic_flags()
1487                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1488                    {
1489                        Ok(DeviceRequest::_UnknownMethod {
1490                            ordinal: header.ordinal,
1491                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
1492                            method_type: fidl::MethodType::OneWay,
1493                        })
1494                    }
1495                    _ if header
1496                        .dynamic_flags()
1497                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1498                    {
1499                        this.inner.send_framework_err(
1500                            fidl::encoding::FrameworkErr::UnknownMethod,
1501                            header.tx_id,
1502                            header.ordinal,
1503                            header.dynamic_flags(),
1504                            (bytes, handles),
1505                        )?;
1506                        Ok(DeviceRequest::_UnknownMethod {
1507                            ordinal: header.ordinal,
1508                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
1509                            method_type: fidl::MethodType::TwoWay,
1510                        })
1511                    }
1512                    _ => Err(fidl::Error::UnknownOrdinal {
1513                        ordinal: header.ordinal,
1514                        protocol_name:
1515                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1516                    }),
1517                }))
1518            },
1519        )
1520    }
1521}
1522
1523/// Each instance of `Device` represents a target/secondary SPMI device on a SPMI bus.
1524/// To support multiple SPMI devices, multiple nodes must be instantiated.
1525#[derive(Debug)]
1526pub enum DeviceRequest {
1527    /// Issue register read commands to the SPMI device.
1528    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1529    /// When successful, it returns `size_bytes` in `data` read contiguously starting from
1530    /// `address` in the device.
1531    RegisterRead { address: u16, size_bytes: u32, responder: DeviceRegisterReadResponder },
1532    /// Issue register write commands to the SPMI device.
1533    /// The implementation may choose which SPMI variation (e.g. extended, long) to use.
1534    /// When this command is successful, `data` will be written contiguously starting from
1535    /// `address` in the device.
1536    RegisterWrite { address: u16, data: Vec<u8>, responder: DeviceRegisterWriteResponder },
1537    /// Get the properties of the SPMI device.
1538    GetProperties { responder: DeviceGetPropertiesResponder },
1539    /// Hanging-get method to receive controller write commands from the device. `address` and
1540    /// `size` specify the register range to monitor for commands. Multiple overlapping calls to
1541    /// this method are not allowed.
1542    /// Returns `INVALID_ARGS` if `address` or `size` are invalid, or `BAD_STATE` if another call
1543    /// is pending for this register range. Returns `CANCELED` if
1544    /// `CancelWatchControllerWriteCommands()` was called for this register range.
1545    ///
1546    /// If this method is meant to keep the system awake (prevents suspension) while watch is setup,
1547    /// use the passed-in `setup_wake_lease` `LeaseToken`. Then, when the watch is triggered this
1548    /// method will return a second `wake_lease` `LeaseToken` to prevent suspension.
1549    ///
1550    /// These keep alive wake lease tokens are provided by the Power Framework's System Activity
1551    /// Governor. A driver supporting keep alive must be able to get `wake_lease` from System
1552    /// Activity Governor.
1553    ///
1554    /// When `wake_lease` is closed, then the created wake lease keeping the system from suspending
1555    /// at the time of watch triggering is dropped. Hence, to guarantee that the system is not
1556    /// suspended by the Power Framework a client must either keep this `wake_lease` for as long as
1557    /// the system needs to stay awake, or a client must get its own wake lease from the Power
1558    /// Framework before it drops `wake_lease` to prevent suspension.
1559    WatchControllerWriteCommands {
1560        address: u8,
1561        size: u16,
1562        setup_wake_lease: Option<fidl::EventPair>,
1563        responder: DeviceWatchControllerWriteCommandsResponder,
1564    },
1565    /// Cancels an pending call to `WatchControllerWriteCommands`. `address` and `size` must
1566    /// exactly match a previous call to `WatchControllerWriteCommands()`, otherwise `NOT_FOUND`
1567    /// is returned.
1568    CancelWatchControllerWriteCommands {
1569        address: u8,
1570        size: u16,
1571        responder: DeviceCancelWatchControllerWriteCommandsResponder,
1572    },
1573    /// An interaction was received which does not match any known method.
1574    #[non_exhaustive]
1575    _UnknownMethod {
1576        /// Ordinal of the method that was called.
1577        ordinal: u64,
1578        control_handle: DeviceControlHandle,
1579        method_type: fidl::MethodType,
1580    },
1581}
1582
1583impl DeviceRequest {
1584    #[allow(irrefutable_let_patterns)]
1585    pub fn into_register_read(self) -> Option<(u16, u32, DeviceRegisterReadResponder)> {
1586        if let DeviceRequest::RegisterRead { address, size_bytes, responder } = self {
1587            Some((address, size_bytes, responder))
1588        } else {
1589            None
1590        }
1591    }
1592
1593    #[allow(irrefutable_let_patterns)]
1594    pub fn into_register_write(self) -> Option<(u16, Vec<u8>, DeviceRegisterWriteResponder)> {
1595        if let DeviceRequest::RegisterWrite { address, data, responder } = self {
1596            Some((address, data, responder))
1597        } else {
1598            None
1599        }
1600    }
1601
1602    #[allow(irrefutable_let_patterns)]
1603    pub fn into_get_properties(self) -> Option<(DeviceGetPropertiesResponder)> {
1604        if let DeviceRequest::GetProperties { responder } = self { Some((responder)) } else { None }
1605    }
1606
1607    #[allow(irrefutable_let_patterns)]
1608    pub fn into_watch_controller_write_commands(
1609        self,
1610    ) -> Option<(u8, u16, Option<fidl::EventPair>, DeviceWatchControllerWriteCommandsResponder)>
1611    {
1612        if let DeviceRequest::WatchControllerWriteCommands {
1613            address,
1614            size,
1615            setup_wake_lease,
1616            responder,
1617        } = self
1618        {
1619            Some((address, size, setup_wake_lease, responder))
1620        } else {
1621            None
1622        }
1623    }
1624
1625    #[allow(irrefutable_let_patterns)]
1626    pub fn into_cancel_watch_controller_write_commands(
1627        self,
1628    ) -> Option<(u8, u16, DeviceCancelWatchControllerWriteCommandsResponder)> {
1629        if let DeviceRequest::CancelWatchControllerWriteCommands { address, size, responder } = self
1630        {
1631            Some((address, size, responder))
1632        } else {
1633            None
1634        }
1635    }
1636
1637    /// Name of the method defined in FIDL
1638    pub fn method_name(&self) -> &'static str {
1639        match *self {
1640            DeviceRequest::RegisterRead { .. } => "register_read",
1641            DeviceRequest::RegisterWrite { .. } => "register_write",
1642            DeviceRequest::GetProperties { .. } => "get_properties",
1643            DeviceRequest::WatchControllerWriteCommands { .. } => "watch_controller_write_commands",
1644            DeviceRequest::CancelWatchControllerWriteCommands { .. } => {
1645                "cancel_watch_controller_write_commands"
1646            }
1647            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1648                "unknown one-way method"
1649            }
1650            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1651                "unknown two-way method"
1652            }
1653        }
1654    }
1655}
1656
1657#[derive(Debug, Clone)]
1658pub struct DeviceControlHandle {
1659    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1660}
1661
1662impl fidl::endpoints::ControlHandle for DeviceControlHandle {
1663    fn shutdown(&self) {
1664        self.inner.shutdown()
1665    }
1666
1667    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1668        self.inner.shutdown_with_epitaph(status)
1669    }
1670
1671    fn is_closed(&self) -> bool {
1672        self.inner.channel().is_closed()
1673    }
1674    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1675        self.inner.channel().on_closed()
1676    }
1677
1678    #[cfg(target_os = "fuchsia")]
1679    fn signal_peer(
1680        &self,
1681        clear_mask: zx::Signals,
1682        set_mask: zx::Signals,
1683    ) -> Result<(), zx_status::Status> {
1684        use fidl::Peered;
1685        self.inner.channel().signal_peer(clear_mask, set_mask)
1686    }
1687}
1688
1689impl DeviceControlHandle {}
1690
1691#[must_use = "FIDL methods require a response to be sent"]
1692#[derive(Debug)]
1693pub struct DeviceRegisterReadResponder {
1694    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1695    tx_id: u32,
1696}
1697
1698/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1699/// if the responder is dropped without sending a response, so that the client
1700/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1701impl std::ops::Drop for DeviceRegisterReadResponder {
1702    fn drop(&mut self) {
1703        self.control_handle.shutdown();
1704        // Safety: drops once, never accessed again
1705        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1706    }
1707}
1708
1709impl fidl::endpoints::Responder for DeviceRegisterReadResponder {
1710    type ControlHandle = DeviceControlHandle;
1711
1712    fn control_handle(&self) -> &DeviceControlHandle {
1713        &self.control_handle
1714    }
1715
1716    fn drop_without_shutdown(mut self) {
1717        // Safety: drops once, never accessed again due to mem::forget
1718        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1719        // Prevent Drop from running (which would shut down the channel)
1720        std::mem::forget(self);
1721    }
1722}
1723
1724impl DeviceRegisterReadResponder {
1725    /// Sends a response to the FIDL transaction.
1726    ///
1727    /// Sets the channel to shutdown if an error occurs.
1728    pub fn send(self, mut result: Result<&[u8], DriverError>) -> Result<(), fidl::Error> {
1729        let _result = self.send_raw(result);
1730        if _result.is_err() {
1731            self.control_handle.shutdown();
1732        }
1733        self.drop_without_shutdown();
1734        _result
1735    }
1736
1737    /// Similar to "send" but does not shutdown the channel if an error occurs.
1738    pub fn send_no_shutdown_on_err(
1739        self,
1740        mut result: Result<&[u8], DriverError>,
1741    ) -> Result<(), fidl::Error> {
1742        let _result = self.send_raw(result);
1743        self.drop_without_shutdown();
1744        _result
1745    }
1746
1747    fn send_raw(&self, mut result: Result<&[u8], DriverError>) -> Result<(), fidl::Error> {
1748        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1749            DeviceRegisterReadResponse,
1750            DriverError,
1751        >>(
1752            fidl::encoding::FlexibleResult::new(result.map(|data| (data,))),
1753            self.tx_id,
1754            0x1b0f6eff7638b5,
1755            fidl::encoding::DynamicFlags::FLEXIBLE,
1756        )
1757    }
1758}
1759
1760#[must_use = "FIDL methods require a response to be sent"]
1761#[derive(Debug)]
1762pub struct DeviceRegisterWriteResponder {
1763    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1764    tx_id: u32,
1765}
1766
1767/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1768/// if the responder is dropped without sending a response, so that the client
1769/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1770impl std::ops::Drop for DeviceRegisterWriteResponder {
1771    fn drop(&mut self) {
1772        self.control_handle.shutdown();
1773        // Safety: drops once, never accessed again
1774        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1775    }
1776}
1777
1778impl fidl::endpoints::Responder for DeviceRegisterWriteResponder {
1779    type ControlHandle = DeviceControlHandle;
1780
1781    fn control_handle(&self) -> &DeviceControlHandle {
1782        &self.control_handle
1783    }
1784
1785    fn drop_without_shutdown(mut self) {
1786        // Safety: drops once, never accessed again due to mem::forget
1787        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1788        // Prevent Drop from running (which would shut down the channel)
1789        std::mem::forget(self);
1790    }
1791}
1792
1793impl DeviceRegisterWriteResponder {
1794    /// Sends a response to the FIDL transaction.
1795    ///
1796    /// Sets the channel to shutdown if an error occurs.
1797    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
1798        let _result = self.send_raw(result);
1799        if _result.is_err() {
1800            self.control_handle.shutdown();
1801        }
1802        self.drop_without_shutdown();
1803        _result
1804    }
1805
1806    /// Similar to "send" but does not shutdown the channel if an error occurs.
1807    pub fn send_no_shutdown_on_err(
1808        self,
1809        mut result: Result<(), DriverError>,
1810    ) -> Result<(), fidl::Error> {
1811        let _result = self.send_raw(result);
1812        self.drop_without_shutdown();
1813        _result
1814    }
1815
1816    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
1817        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1818            fidl::encoding::EmptyStruct,
1819            DriverError,
1820        >>(
1821            fidl::encoding::FlexibleResult::new(result),
1822            self.tx_id,
1823            0xe7f4ed59770bb2b,
1824            fidl::encoding::DynamicFlags::FLEXIBLE,
1825        )
1826    }
1827}
1828
1829#[must_use = "FIDL methods require a response to be sent"]
1830#[derive(Debug)]
1831pub struct DeviceGetPropertiesResponder {
1832    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1833    tx_id: u32,
1834}
1835
1836/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1837/// if the responder is dropped without sending a response, so that the client
1838/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1839impl std::ops::Drop for DeviceGetPropertiesResponder {
1840    fn drop(&mut self) {
1841        self.control_handle.shutdown();
1842        // Safety: drops once, never accessed again
1843        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1844    }
1845}
1846
1847impl fidl::endpoints::Responder for DeviceGetPropertiesResponder {
1848    type ControlHandle = DeviceControlHandle;
1849
1850    fn control_handle(&self) -> &DeviceControlHandle {
1851        &self.control_handle
1852    }
1853
1854    fn drop_without_shutdown(mut self) {
1855        // Safety: drops once, never accessed again due to mem::forget
1856        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1857        // Prevent Drop from running (which would shut down the channel)
1858        std::mem::forget(self);
1859    }
1860}
1861
1862impl DeviceGetPropertiesResponder {
1863    /// Sends a response to the FIDL transaction.
1864    ///
1865    /// Sets the channel to shutdown if an error occurs.
1866    pub fn send(self, mut payload: &DeviceGetPropertiesResponse) -> Result<(), fidl::Error> {
1867        let _result = self.send_raw(payload);
1868        if _result.is_err() {
1869            self.control_handle.shutdown();
1870        }
1871        self.drop_without_shutdown();
1872        _result
1873    }
1874
1875    /// Similar to "send" but does not shutdown the channel if an error occurs.
1876    pub fn send_no_shutdown_on_err(
1877        self,
1878        mut payload: &DeviceGetPropertiesResponse,
1879    ) -> Result<(), fidl::Error> {
1880        let _result = self.send_raw(payload);
1881        self.drop_without_shutdown();
1882        _result
1883    }
1884
1885    fn send_raw(&self, mut payload: &DeviceGetPropertiesResponse) -> Result<(), fidl::Error> {
1886        self.control_handle.inner.send::<fidl::encoding::FlexibleType<DeviceGetPropertiesResponse>>(
1887            fidl::encoding::Flexible::new(payload),
1888            self.tx_id,
1889            0x1e946ec04006ffbb,
1890            fidl::encoding::DynamicFlags::FLEXIBLE,
1891        )
1892    }
1893}
1894
1895#[must_use = "FIDL methods require a response to be sent"]
1896#[derive(Debug)]
1897pub struct DeviceWatchControllerWriteCommandsResponder {
1898    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1899    tx_id: u32,
1900}
1901
1902/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1903/// if the responder is dropped without sending a response, so that the client
1904/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1905impl std::ops::Drop for DeviceWatchControllerWriteCommandsResponder {
1906    fn drop(&mut self) {
1907        self.control_handle.shutdown();
1908        // Safety: drops once, never accessed again
1909        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1910    }
1911}
1912
1913impl fidl::endpoints::Responder for DeviceWatchControllerWriteCommandsResponder {
1914    type ControlHandle = DeviceControlHandle;
1915
1916    fn control_handle(&self) -> &DeviceControlHandle {
1917        &self.control_handle
1918    }
1919
1920    fn drop_without_shutdown(mut self) {
1921        // Safety: drops once, never accessed again due to mem::forget
1922        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1923        // Prevent Drop from running (which would shut down the channel)
1924        std::mem::forget(self);
1925    }
1926}
1927
1928impl DeviceWatchControllerWriteCommandsResponder {
1929    /// Sends a response to the FIDL transaction.
1930    ///
1931    /// Sets the channel to shutdown if an error occurs.
1932    pub fn send(
1933        self,
1934        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1935    ) -> Result<(), fidl::Error> {
1936        let _result = self.send_raw(result);
1937        if _result.is_err() {
1938            self.control_handle.shutdown();
1939        }
1940        self.drop_without_shutdown();
1941        _result
1942    }
1943
1944    /// Similar to "send" but does not shutdown the channel if an error occurs.
1945    pub fn send_no_shutdown_on_err(
1946        self,
1947        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1948    ) -> Result<(), fidl::Error> {
1949        let _result = self.send_raw(result);
1950        self.drop_without_shutdown();
1951        _result
1952    }
1953
1954    fn send_raw(
1955        &self,
1956        mut result: Result<(&[Register8], Option<fidl::EventPair>), DriverError>,
1957    ) -> Result<(), fidl::Error> {
1958        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1959            DeviceWatchControllerWriteCommandsResponse,
1960            DriverError,
1961        >>(
1962            fidl::encoding::FlexibleResult::new(result),
1963            self.tx_id,
1964            0x41674c1eba4d05ac,
1965            fidl::encoding::DynamicFlags::FLEXIBLE,
1966        )
1967    }
1968}
1969
1970#[must_use = "FIDL methods require a response to be sent"]
1971#[derive(Debug)]
1972pub struct DeviceCancelWatchControllerWriteCommandsResponder {
1973    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1974    tx_id: u32,
1975}
1976
1977/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1978/// if the responder is dropped without sending a response, so that the client
1979/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1980impl std::ops::Drop for DeviceCancelWatchControllerWriteCommandsResponder {
1981    fn drop(&mut self) {
1982        self.control_handle.shutdown();
1983        // Safety: drops once, never accessed again
1984        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1985    }
1986}
1987
1988impl fidl::endpoints::Responder for DeviceCancelWatchControllerWriteCommandsResponder {
1989    type ControlHandle = DeviceControlHandle;
1990
1991    fn control_handle(&self) -> &DeviceControlHandle {
1992        &self.control_handle
1993    }
1994
1995    fn drop_without_shutdown(mut self) {
1996        // Safety: drops once, never accessed again due to mem::forget
1997        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1998        // Prevent Drop from running (which would shut down the channel)
1999        std::mem::forget(self);
2000    }
2001}
2002
2003impl DeviceCancelWatchControllerWriteCommandsResponder {
2004    /// Sends a response to the FIDL transaction.
2005    ///
2006    /// Sets the channel to shutdown if an error occurs.
2007    pub fn send(self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
2008        let _result = self.send_raw(result);
2009        if _result.is_err() {
2010            self.control_handle.shutdown();
2011        }
2012        self.drop_without_shutdown();
2013        _result
2014    }
2015
2016    /// Similar to "send" but does not shutdown the channel if an error occurs.
2017    pub fn send_no_shutdown_on_err(
2018        self,
2019        mut result: Result<(), DriverError>,
2020    ) -> Result<(), fidl::Error> {
2021        let _result = self.send_raw(result);
2022        self.drop_without_shutdown();
2023        _result
2024    }
2025
2026    fn send_raw(&self, mut result: Result<(), DriverError>) -> Result<(), fidl::Error> {
2027        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
2028            fidl::encoding::EmptyStruct,
2029            DriverError,
2030        >>(
2031            fidl::encoding::FlexibleResult::new(result),
2032            self.tx_id,
2033            0x5057c280e6f0d420,
2034            fidl::encoding::DynamicFlags::FLEXIBLE,
2035        )
2036    }
2037}
2038
2039#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2040pub struct DebugServiceMarker;
2041
2042#[cfg(target_os = "fuchsia")]
2043impl fidl::endpoints::ServiceMarker for DebugServiceMarker {
2044    type Proxy = DebugServiceProxy;
2045    type Request = DebugServiceRequest;
2046    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.DebugService";
2047}
2048
2049/// A request for one of the member protocols of DebugService.
2050///
2051/// This service can be used by command-line utilities and tests to connect to any target device on
2052/// the SPMI bus. It is not exposed to drivers.
2053#[cfg(target_os = "fuchsia")]
2054pub enum DebugServiceRequest {
2055    Device(DebugRequestStream),
2056}
2057
2058#[cfg(target_os = "fuchsia")]
2059impl fidl::endpoints::ServiceRequest for DebugServiceRequest {
2060    type Service = DebugServiceMarker;
2061
2062    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2063        match name {
2064            "device" => Self::Device(
2065                <DebugRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2066            ),
2067            _ => panic!("no such member protocol name for service DebugService"),
2068        }
2069    }
2070
2071    fn member_names() -> &'static [&'static str] {
2072        &["device"]
2073    }
2074}
2075/// This service can be used by command-line utilities and tests to connect to any target device on
2076/// the SPMI bus. It is not exposed to drivers.
2077#[cfg(target_os = "fuchsia")]
2078pub struct DebugServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2079
2080#[cfg(target_os = "fuchsia")]
2081impl fidl::endpoints::ServiceProxy for DebugServiceProxy {
2082    type Service = DebugServiceMarker;
2083
2084    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2085        Self(opener)
2086    }
2087}
2088
2089#[cfg(target_os = "fuchsia")]
2090impl DebugServiceProxy {
2091    pub fn connect_to_device(&self) -> Result<DebugProxy, fidl::Error> {
2092        let (proxy, server_end) = fidl::endpoints::create_proxy::<DebugMarker>();
2093        self.connect_channel_to_device(server_end)?;
2094        Ok(proxy)
2095    }
2096
2097    /// Like `connect_to_device`, but returns a sync proxy.
2098    /// See [`Self::connect_to_device`] for more details.
2099    pub fn connect_to_device_sync(&self) -> Result<DebugSynchronousProxy, fidl::Error> {
2100        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DebugMarker>();
2101        self.connect_channel_to_device(server_end)?;
2102        Ok(proxy)
2103    }
2104
2105    /// Like `connect_to_device`, but accepts a server end.
2106    /// See [`Self::connect_to_device`] for more details.
2107    pub fn connect_channel_to_device(
2108        &self,
2109        server_end: fidl::endpoints::ServerEnd<DebugMarker>,
2110    ) -> Result<(), fidl::Error> {
2111        self.0.open_member("device", server_end.into_channel())
2112    }
2113
2114    pub fn instance_name(&self) -> &str {
2115        self.0.instance_name()
2116    }
2117}
2118
2119#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2120pub struct SubTargetServiceMarker;
2121
2122#[cfg(target_os = "fuchsia")]
2123impl fidl::endpoints::ServiceMarker for SubTargetServiceMarker {
2124    type Proxy = SubTargetServiceProxy;
2125    type Request = SubTargetServiceRequest;
2126    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.SubTargetService";
2127}
2128
2129/// A request for one of the member protocols of SubTargetService.
2130///
2131/// This service represents a sub-target device within an SPMI target. Clients have access to a
2132/// subset of the SPMI register range as determined by the controller driver.
2133#[cfg(target_os = "fuchsia")]
2134pub enum SubTargetServiceRequest {
2135    Device(DeviceRequestStream),
2136}
2137
2138#[cfg(target_os = "fuchsia")]
2139impl fidl::endpoints::ServiceRequest for SubTargetServiceRequest {
2140    type Service = SubTargetServiceMarker;
2141
2142    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2143        match name {
2144            "device" => Self::Device(
2145                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2146            ),
2147            _ => panic!("no such member protocol name for service SubTargetService"),
2148        }
2149    }
2150
2151    fn member_names() -> &'static [&'static str] {
2152        &["device"]
2153    }
2154}
2155/// This service represents a sub-target device within an SPMI target. Clients have access to a
2156/// subset of the SPMI register range as determined by the controller driver.
2157#[cfg(target_os = "fuchsia")]
2158pub struct SubTargetServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2159
2160#[cfg(target_os = "fuchsia")]
2161impl fidl::endpoints::ServiceProxy for SubTargetServiceProxy {
2162    type Service = SubTargetServiceMarker;
2163
2164    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2165        Self(opener)
2166    }
2167}
2168
2169#[cfg(target_os = "fuchsia")]
2170impl SubTargetServiceProxy {
2171    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
2172        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
2173        self.connect_channel_to_device(server_end)?;
2174        Ok(proxy)
2175    }
2176
2177    /// Like `connect_to_device`, but returns a sync proxy.
2178    /// See [`Self::connect_to_device`] for more details.
2179    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
2180        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
2181        self.connect_channel_to_device(server_end)?;
2182        Ok(proxy)
2183    }
2184
2185    /// Like `connect_to_device`, but accepts a server end.
2186    /// See [`Self::connect_to_device`] for more details.
2187    pub fn connect_channel_to_device(
2188        &self,
2189        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
2190    ) -> Result<(), fidl::Error> {
2191        self.0.open_member("device", server_end.into_channel())
2192    }
2193
2194    pub fn instance_name(&self) -> &str {
2195        self.0.instance_name()
2196    }
2197}
2198
2199#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
2200pub struct TargetServiceMarker;
2201
2202#[cfg(target_os = "fuchsia")]
2203impl fidl::endpoints::ServiceMarker for TargetServiceMarker {
2204    type Proxy = TargetServiceProxy;
2205    type Request = TargetServiceRequest;
2206    const SERVICE_NAME: &'static str = "fuchsia.hardware.spmi.TargetService";
2207}
2208
2209/// A request for one of the member protocols of TargetService.
2210///
2211/// This service represents an SPMI target device. Clients have access to the entire SPMI register
2212/// range.
2213#[cfg(target_os = "fuchsia")]
2214pub enum TargetServiceRequest {
2215    Device(DeviceRequestStream),
2216}
2217
2218#[cfg(target_os = "fuchsia")]
2219impl fidl::endpoints::ServiceRequest for TargetServiceRequest {
2220    type Service = TargetServiceMarker;
2221
2222    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
2223        match name {
2224            "device" => Self::Device(
2225                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
2226            ),
2227            _ => panic!("no such member protocol name for service TargetService"),
2228        }
2229    }
2230
2231    fn member_names() -> &'static [&'static str] {
2232        &["device"]
2233    }
2234}
2235/// This service represents an SPMI target device. Clients have access to the entire SPMI register
2236/// range.
2237#[cfg(target_os = "fuchsia")]
2238pub struct TargetServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
2239
2240#[cfg(target_os = "fuchsia")]
2241impl fidl::endpoints::ServiceProxy for TargetServiceProxy {
2242    type Service = TargetServiceMarker;
2243
2244    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
2245        Self(opener)
2246    }
2247}
2248
2249#[cfg(target_os = "fuchsia")]
2250impl TargetServiceProxy {
2251    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
2252        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
2253        self.connect_channel_to_device(server_end)?;
2254        Ok(proxy)
2255    }
2256
2257    /// Like `connect_to_device`, but returns a sync proxy.
2258    /// See [`Self::connect_to_device`] for more details.
2259    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
2260        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
2261        self.connect_channel_to_device(server_end)?;
2262        Ok(proxy)
2263    }
2264
2265    /// Like `connect_to_device`, but accepts a server end.
2266    /// See [`Self::connect_to_device`] for more details.
2267    pub fn connect_channel_to_device(
2268        &self,
2269        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
2270    ) -> Result<(), fidl::Error> {
2271        self.0.open_member("device", server_end.into_channel())
2272    }
2273
2274    pub fn instance_name(&self) -> &str {
2275        self.0.instance_name()
2276    }
2277}
2278
2279mod internal {
2280    use super::*;
2281
2282    impl fidl::encoding::ResourceTypeMarker for DebugConnectTargetRequest {
2283        type Borrowed<'a> = &'a mut Self;
2284        fn take_or_borrow<'a>(
2285            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2286        ) -> Self::Borrowed<'a> {
2287            value
2288        }
2289    }
2290
2291    unsafe impl fidl::encoding::TypeMarker for DebugConnectTargetRequest {
2292        type Owned = Self;
2293
2294        #[inline(always)]
2295        fn inline_align(_context: fidl::encoding::Context) -> usize {
2296            4
2297        }
2298
2299        #[inline(always)]
2300        fn inline_size(_context: fidl::encoding::Context) -> usize {
2301            8
2302        }
2303    }
2304
2305    unsafe impl
2306        fidl::encoding::Encode<
2307            DebugConnectTargetRequest,
2308            fidl::encoding::DefaultFuchsiaResourceDialect,
2309        > for &mut DebugConnectTargetRequest
2310    {
2311        #[inline]
2312        unsafe fn encode(
2313            self,
2314            encoder: &mut fidl::encoding::Encoder<
2315                '_,
2316                fidl::encoding::DefaultFuchsiaResourceDialect,
2317            >,
2318            offset: usize,
2319            _depth: fidl::encoding::Depth,
2320        ) -> fidl::Result<()> {
2321            encoder.debug_check_bounds::<DebugConnectTargetRequest>(offset);
2322            // Delegate to tuple encoding.
2323            fidl::encoding::Encode::<DebugConnectTargetRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2324                (
2325                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.target_id),
2326                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.server),
2327                ),
2328                encoder, offset, _depth
2329            )
2330        }
2331    }
2332    unsafe impl<
2333        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
2334        T1: fidl::encoding::Encode<
2335                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2336                fidl::encoding::DefaultFuchsiaResourceDialect,
2337            >,
2338    >
2339        fidl::encoding::Encode<
2340            DebugConnectTargetRequest,
2341            fidl::encoding::DefaultFuchsiaResourceDialect,
2342        > for (T0, T1)
2343    {
2344        #[inline]
2345        unsafe fn encode(
2346            self,
2347            encoder: &mut fidl::encoding::Encoder<
2348                '_,
2349                fidl::encoding::DefaultFuchsiaResourceDialect,
2350            >,
2351            offset: usize,
2352            depth: fidl::encoding::Depth,
2353        ) -> fidl::Result<()> {
2354            encoder.debug_check_bounds::<DebugConnectTargetRequest>(offset);
2355            // Zero out padding regions. There's no need to apply masks
2356            // because the unmasked parts will be overwritten by fields.
2357            unsafe {
2358                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
2359                (ptr as *mut u32).write_unaligned(0);
2360            }
2361            // Write the fields.
2362            self.0.encode(encoder, offset + 0, depth)?;
2363            self.1.encode(encoder, offset + 4, depth)?;
2364            Ok(())
2365        }
2366    }
2367
2368    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2369        for DebugConnectTargetRequest
2370    {
2371        #[inline(always)]
2372        fn new_empty() -> Self {
2373            Self {
2374                target_id: fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect),
2375                server: fidl::new_empty!(
2376                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2377                    fidl::encoding::DefaultFuchsiaResourceDialect
2378                ),
2379            }
2380        }
2381
2382        #[inline]
2383        unsafe fn decode(
2384            &mut self,
2385            decoder: &mut fidl::encoding::Decoder<
2386                '_,
2387                fidl::encoding::DefaultFuchsiaResourceDialect,
2388            >,
2389            offset: usize,
2390            _depth: fidl::encoding::Depth,
2391        ) -> fidl::Result<()> {
2392            decoder.debug_check_bounds::<Self>(offset);
2393            // Verify that padding bytes are zero.
2394            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
2395            let padval = unsafe { (ptr as *const u32).read_unaligned() };
2396            let mask = 0xffffff00u32;
2397            let maskedval = padval & mask;
2398            if maskedval != 0 {
2399                return Err(fidl::Error::NonZeroPadding {
2400                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2401                });
2402            }
2403            fidl::decode!(
2404                u8,
2405                fidl::encoding::DefaultFuchsiaResourceDialect,
2406                &mut self.target_id,
2407                decoder,
2408                offset + 0,
2409                _depth
2410            )?;
2411            fidl::decode!(
2412                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
2413                fidl::encoding::DefaultFuchsiaResourceDialect,
2414                &mut self.server,
2415                decoder,
2416                offset + 4,
2417                _depth
2418            )?;
2419            Ok(())
2420        }
2421    }
2422
2423    impl fidl::encoding::ResourceTypeMarker for DeviceWatchControllerWriteCommandsRequest {
2424        type Borrowed<'a> = &'a mut Self;
2425        fn take_or_borrow<'a>(
2426            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2427        ) -> Self::Borrowed<'a> {
2428            value
2429        }
2430    }
2431
2432    unsafe impl fidl::encoding::TypeMarker for DeviceWatchControllerWriteCommandsRequest {
2433        type Owned = Self;
2434
2435        #[inline(always)]
2436        fn inline_align(_context: fidl::encoding::Context) -> usize {
2437            4
2438        }
2439
2440        #[inline(always)]
2441        fn inline_size(_context: fidl::encoding::Context) -> usize {
2442            8
2443        }
2444    }
2445
2446    unsafe impl
2447        fidl::encoding::Encode<
2448            DeviceWatchControllerWriteCommandsRequest,
2449            fidl::encoding::DefaultFuchsiaResourceDialect,
2450        > for &mut DeviceWatchControllerWriteCommandsRequest
2451    {
2452        #[inline]
2453        unsafe fn encode(
2454            self,
2455            encoder: &mut fidl::encoding::Encoder<
2456                '_,
2457                fidl::encoding::DefaultFuchsiaResourceDialect,
2458            >,
2459            offset: usize,
2460            _depth: fidl::encoding::Depth,
2461        ) -> fidl::Result<()> {
2462            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsRequest>(offset);
2463            // Delegate to tuple encoding.
2464            fidl::encoding::Encode::<
2465                DeviceWatchControllerWriteCommandsRequest,
2466                fidl::encoding::DefaultFuchsiaResourceDialect,
2467            >::encode(
2468                (
2469                    <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.address),
2470                    <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.size),
2471                    <fidl::encoding::Optional<
2472                        fidl::encoding::HandleType<
2473                            fidl::EventPair,
2474                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2475                            16387,
2476                        >,
2477                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
2478                        &mut self.setup_wake_lease,
2479                    ),
2480                ),
2481                encoder,
2482                offset,
2483                _depth,
2484            )
2485        }
2486    }
2487    unsafe impl<
2488        T0: fidl::encoding::Encode<u8, fidl::encoding::DefaultFuchsiaResourceDialect>,
2489        T1: fidl::encoding::Encode<u16, fidl::encoding::DefaultFuchsiaResourceDialect>,
2490        T2: fidl::encoding::Encode<
2491                fidl::encoding::Optional<
2492                    fidl::encoding::HandleType<
2493                        fidl::EventPair,
2494                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2495                        16387,
2496                    >,
2497                >,
2498                fidl::encoding::DefaultFuchsiaResourceDialect,
2499            >,
2500    >
2501        fidl::encoding::Encode<
2502            DeviceWatchControllerWriteCommandsRequest,
2503            fidl::encoding::DefaultFuchsiaResourceDialect,
2504        > for (T0, T1, T2)
2505    {
2506        #[inline]
2507        unsafe fn encode(
2508            self,
2509            encoder: &mut fidl::encoding::Encoder<
2510                '_,
2511                fidl::encoding::DefaultFuchsiaResourceDialect,
2512            >,
2513            offset: usize,
2514            depth: fidl::encoding::Depth,
2515        ) -> fidl::Result<()> {
2516            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsRequest>(offset);
2517            // Zero out padding regions. There's no need to apply masks
2518            // because the unmasked parts will be overwritten by fields.
2519            unsafe {
2520                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
2521                (ptr as *mut u32).write_unaligned(0);
2522            }
2523            // Write the fields.
2524            self.0.encode(encoder, offset + 0, depth)?;
2525            self.1.encode(encoder, offset + 2, depth)?;
2526            self.2.encode(encoder, offset + 4, depth)?;
2527            Ok(())
2528        }
2529    }
2530
2531    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2532        for DeviceWatchControllerWriteCommandsRequest
2533    {
2534        #[inline(always)]
2535        fn new_empty() -> Self {
2536            Self {
2537                address: fidl::new_empty!(u8, fidl::encoding::DefaultFuchsiaResourceDialect),
2538                size: fidl::new_empty!(u16, fidl::encoding::DefaultFuchsiaResourceDialect),
2539                setup_wake_lease: fidl::new_empty!(
2540                    fidl::encoding::Optional<
2541                        fidl::encoding::HandleType<
2542                            fidl::EventPair,
2543                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2544                            16387,
2545                        >,
2546                    >,
2547                    fidl::encoding::DefaultFuchsiaResourceDialect
2548                ),
2549            }
2550        }
2551
2552        #[inline]
2553        unsafe fn decode(
2554            &mut self,
2555            decoder: &mut fidl::encoding::Decoder<
2556                '_,
2557                fidl::encoding::DefaultFuchsiaResourceDialect,
2558            >,
2559            offset: usize,
2560            _depth: fidl::encoding::Depth,
2561        ) -> fidl::Result<()> {
2562            decoder.debug_check_bounds::<Self>(offset);
2563            // Verify that padding bytes are zero.
2564            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
2565            let padval = unsafe { (ptr as *const u32).read_unaligned() };
2566            let mask = 0xff00u32;
2567            let maskedval = padval & mask;
2568            if maskedval != 0 {
2569                return Err(fidl::Error::NonZeroPadding {
2570                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
2571                });
2572            }
2573            fidl::decode!(
2574                u8,
2575                fidl::encoding::DefaultFuchsiaResourceDialect,
2576                &mut self.address,
2577                decoder,
2578                offset + 0,
2579                _depth
2580            )?;
2581            fidl::decode!(
2582                u16,
2583                fidl::encoding::DefaultFuchsiaResourceDialect,
2584                &mut self.size,
2585                decoder,
2586                offset + 2,
2587                _depth
2588            )?;
2589            fidl::decode!(
2590                fidl::encoding::Optional<
2591                    fidl::encoding::HandleType<
2592                        fidl::EventPair,
2593                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2594                        16387,
2595                    >,
2596                >,
2597                fidl::encoding::DefaultFuchsiaResourceDialect,
2598                &mut self.setup_wake_lease,
2599                decoder,
2600                offset + 4,
2601                _depth
2602            )?;
2603            Ok(())
2604        }
2605    }
2606
2607    impl fidl::encoding::ResourceTypeMarker for DeviceWatchControllerWriteCommandsResponse {
2608        type Borrowed<'a> = &'a mut Self;
2609        fn take_or_borrow<'a>(
2610            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
2611        ) -> Self::Borrowed<'a> {
2612            value
2613        }
2614    }
2615
2616    unsafe impl fidl::encoding::TypeMarker for DeviceWatchControllerWriteCommandsResponse {
2617        type Owned = Self;
2618
2619        #[inline(always)]
2620        fn inline_align(_context: fidl::encoding::Context) -> usize {
2621            8
2622        }
2623
2624        #[inline(always)]
2625        fn inline_size(_context: fidl::encoding::Context) -> usize {
2626            24
2627        }
2628    }
2629
2630    unsafe impl
2631        fidl::encoding::Encode<
2632            DeviceWatchControllerWriteCommandsResponse,
2633            fidl::encoding::DefaultFuchsiaResourceDialect,
2634        > for &mut DeviceWatchControllerWriteCommandsResponse
2635    {
2636        #[inline]
2637        unsafe fn encode(
2638            self,
2639            encoder: &mut fidl::encoding::Encoder<
2640                '_,
2641                fidl::encoding::DefaultFuchsiaResourceDialect,
2642            >,
2643            offset: usize,
2644            _depth: fidl::encoding::Depth,
2645        ) -> fidl::Result<()> {
2646            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsResponse>(offset);
2647            // Delegate to tuple encoding.
2648            fidl::encoding::Encode::<DeviceWatchControllerWriteCommandsResponse, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
2649                (
2650                    <fidl::encoding::Vector<Register8, 256> as fidl::encoding::ValueTypeMarker>::borrow(&self.writes),
2651                    <fidl::encoding::Optional<fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 16387>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.wake_lease),
2652                ),
2653                encoder, offset, _depth
2654            )
2655        }
2656    }
2657    unsafe impl<
2658        T0: fidl::encoding::Encode<
2659                fidl::encoding::Vector<Register8, 256>,
2660                fidl::encoding::DefaultFuchsiaResourceDialect,
2661            >,
2662        T1: fidl::encoding::Encode<
2663                fidl::encoding::Optional<
2664                    fidl::encoding::HandleType<
2665                        fidl::EventPair,
2666                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2667                        16387,
2668                    >,
2669                >,
2670                fidl::encoding::DefaultFuchsiaResourceDialect,
2671            >,
2672    >
2673        fidl::encoding::Encode<
2674            DeviceWatchControllerWriteCommandsResponse,
2675            fidl::encoding::DefaultFuchsiaResourceDialect,
2676        > for (T0, T1)
2677    {
2678        #[inline]
2679        unsafe fn encode(
2680            self,
2681            encoder: &mut fidl::encoding::Encoder<
2682                '_,
2683                fidl::encoding::DefaultFuchsiaResourceDialect,
2684            >,
2685            offset: usize,
2686            depth: fidl::encoding::Depth,
2687        ) -> fidl::Result<()> {
2688            encoder.debug_check_bounds::<DeviceWatchControllerWriteCommandsResponse>(offset);
2689            // Zero out padding regions. There's no need to apply masks
2690            // because the unmasked parts will be overwritten by fields.
2691            unsafe {
2692                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
2693                (ptr as *mut u64).write_unaligned(0);
2694            }
2695            // Write the fields.
2696            self.0.encode(encoder, offset + 0, depth)?;
2697            self.1.encode(encoder, offset + 16, depth)?;
2698            Ok(())
2699        }
2700    }
2701
2702    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
2703        for DeviceWatchControllerWriteCommandsResponse
2704    {
2705        #[inline(always)]
2706        fn new_empty() -> Self {
2707            Self {
2708                writes: fidl::new_empty!(fidl::encoding::Vector<Register8, 256>, fidl::encoding::DefaultFuchsiaResourceDialect),
2709                wake_lease: fidl::new_empty!(
2710                    fidl::encoding::Optional<
2711                        fidl::encoding::HandleType<
2712                            fidl::EventPair,
2713                            { fidl::ObjectType::EVENTPAIR.into_raw() },
2714                            16387,
2715                        >,
2716                    >,
2717                    fidl::encoding::DefaultFuchsiaResourceDialect
2718                ),
2719            }
2720        }
2721
2722        #[inline]
2723        unsafe fn decode(
2724            &mut self,
2725            decoder: &mut fidl::encoding::Decoder<
2726                '_,
2727                fidl::encoding::DefaultFuchsiaResourceDialect,
2728            >,
2729            offset: usize,
2730            _depth: fidl::encoding::Depth,
2731        ) -> fidl::Result<()> {
2732            decoder.debug_check_bounds::<Self>(offset);
2733            // Verify that padding bytes are zero.
2734            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
2735            let padval = unsafe { (ptr as *const u64).read_unaligned() };
2736            let mask = 0xffffffff00000000u64;
2737            let maskedval = padval & mask;
2738            if maskedval != 0 {
2739                return Err(fidl::Error::NonZeroPadding {
2740                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
2741                });
2742            }
2743            fidl::decode!(fidl::encoding::Vector<Register8, 256>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.writes, decoder, offset + 0, _depth)?;
2744            fidl::decode!(
2745                fidl::encoding::Optional<
2746                    fidl::encoding::HandleType<
2747                        fidl::EventPair,
2748                        { fidl::ObjectType::EVENTPAIR.into_raw() },
2749                        16387,
2750                    >,
2751                >,
2752                fidl::encoding::DefaultFuchsiaResourceDialect,
2753                &mut self.wake_lease,
2754                decoder,
2755                offset + 16,
2756                _depth
2757            )?;
2758            Ok(())
2759        }
2760    }
2761}