Skip to main content

fidl_fuchsia_hardware_power_source/
fidl_fuchsia_hardware_power_source.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_power_source_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct SourceWatchRequest {
16    pub interest: Status,
17    pub wake_on: Status,
18    pub lease: Option<fidl::EventPair>,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for SourceWatchRequest {}
22
23#[derive(Debug, PartialEq)]
24pub struct SourceWatchResponse {
25    pub status: Status,
26    pub wake_lease: Option<fidl::EventPair>,
27}
28
29impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for SourceWatchResponse {}
30
31#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
32pub struct SourceMarker;
33
34impl fidl::endpoints::ProtocolMarker for SourceMarker {
35    type Proxy = SourceProxy;
36    type RequestStream = SourceRequestStream;
37    #[cfg(target_os = "fuchsia")]
38    type SynchronousProxy = SourceSynchronousProxy;
39
40    const DEBUG_NAME: &'static str = "(anonymous) Source";
41}
42pub type SourceGetSpecResult = Result<Spec, Error>;
43pub type SourceGetStatusResult = Result<Status, Error>;
44pub type SourceSetRoleResult = Result<(), Error>;
45pub type SourceWatchResult = Result<(Status, Option<fidl::EventPair>), Error>;
46
47pub trait SourceProxyInterface: Send + Sync {
48    type GetSpecResponseFut: std::future::Future<Output = Result<SourceGetSpecResult, fidl::Error>>
49        + Send;
50    fn r#get_spec(&self) -> Self::GetSpecResponseFut;
51    type GetStatusResponseFut: std::future::Future<Output = Result<SourceGetStatusResult, fidl::Error>>
52        + Send;
53    fn r#get_status(&self) -> Self::GetStatusResponseFut;
54    type SetRoleResponseFut: std::future::Future<Output = Result<SourceSetRoleResult, fidl::Error>>
55        + Send;
56    fn r#set_role(&self, role: &Role) -> Self::SetRoleResponseFut;
57    type WatchResponseFut: std::future::Future<Output = Result<SourceWatchResult, fidl::Error>>
58        + Send;
59    fn r#watch(
60        &self,
61        interest: &Status,
62        wake_on: &Status,
63        lease: Option<fidl::EventPair>,
64    ) -> Self::WatchResponseFut;
65}
66#[derive(Debug)]
67#[cfg(target_os = "fuchsia")]
68pub struct SourceSynchronousProxy {
69    client: fidl::client::sync::Client,
70}
71
72#[cfg(target_os = "fuchsia")]
73impl fidl::endpoints::SynchronousProxy for SourceSynchronousProxy {
74    type Proxy = SourceProxy;
75    type Protocol = SourceMarker;
76
77    fn from_channel(inner: fidl::Channel) -> Self {
78        Self::new(inner)
79    }
80
81    fn into_channel(self) -> fidl::Channel {
82        self.client.into_channel()
83    }
84
85    fn as_channel(&self) -> &fidl::Channel {
86        self.client.as_channel()
87    }
88}
89
90#[cfg(target_os = "fuchsia")]
91impl SourceSynchronousProxy {
92    pub fn new(channel: fidl::Channel) -> Self {
93        Self { client: fidl::client::sync::Client::new(channel) }
94    }
95
96    pub fn into_channel(self) -> fidl::Channel {
97        self.client.into_channel()
98    }
99
100    /// Waits until an event arrives and returns it. It is safe for other
101    /// threads to make concurrent requests while waiting for an event.
102    pub fn wait_for_event(
103        &self,
104        deadline: zx::MonotonicInstant,
105    ) -> Result<SourceEvent, fidl::Error> {
106        SourceEvent::decode(self.client.wait_for_event::<SourceMarker>(deadline)?)
107    }
108
109    /// Returns static hardware characteristics that do not change during operation.
110    pub fn r#get_spec(
111        &self,
112        ___deadline: zx::MonotonicInstant,
113    ) -> Result<SourceGetSpecResult, fidl::Error> {
114        let _response = self.client.send_query::<
115            fidl::encoding::EmptyPayload,
116            fidl::encoding::FlexibleResultType<SourceGetSpecResponse, Error>,
117            SourceMarker,
118        >(
119            (),
120            0x7f756685c3daa1ac,
121            fidl::encoding::DynamicFlags::FLEXIBLE,
122            ___deadline,
123        )?
124        .into_result::<SourceMarker>("get_spec")?;
125        Ok(_response.map(|x| x.spec))
126    }
127
128    /// Returns dynamic status of the source immediately.
129    pub fn r#get_status(
130        &self,
131        ___deadline: zx::MonotonicInstant,
132    ) -> Result<SourceGetStatusResult, fidl::Error> {
133        let _response = self.client.send_query::<
134            fidl::encoding::EmptyPayload,
135            fidl::encoding::FlexibleResultType<SourceGetStatusResponse, Error>,
136            SourceMarker,
137        >(
138            (),
139            0x121659a401919be7,
140            fidl::encoding::DynamicFlags::FLEXIBLE,
141            ___deadline,
142        )?
143        .into_result::<SourceMarker>("get_status")?;
144        Ok(_response.map(|x| x.status))
145    }
146
147    /// Set the role of this specific node.
148    ///
149    /// Errors:
150    /// + `INVALID_ARGS`: If the provided role is invalid.
151    /// + `NOT_SUPPORTED`: If the requested role is not supported by the hardware.
152    /// + `INTERNAL`: If an unexpected error occurred.
153    pub fn r#set_role(
154        &self,
155        mut role: &Role,
156        ___deadline: zx::MonotonicInstant,
157    ) -> Result<SourceSetRoleResult, fidl::Error> {
158        let _response = self.client.send_query::<
159            SourceSetRoleRequest,
160            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, Error>,
161            SourceMarker,
162        >(
163            (role,),
164            0x2a0b0990da5f4ae1,
165            fidl::encoding::DynamicFlags::FLEXIBLE,
166            ___deadline,
167        )?
168        .into_result::<SourceMarker>("set_role")?;
169        Ok(_response.map(|x| x))
170    }
171
172    /// Change notification for power source state using a "hanging-get" pattern.
173    ///
174    /// The first call to this method returns the current hardware state immediately.
175    /// Subsequent calls block until a change occurs that matches the provided masks.
176    ///
177    /// At most one `Watch` call may be outstanding at a time per connection.
178    /// Completing a call acknowledges that the client has received the previous update.
179    ///
180    /// ### Power Management and Suspend
181    /// To prevent lost wakeups, the server (driver) must ensure that the `Watch` call
182    /// remains active (and hardware interrupts armed) while the system is suspended.
183    ///
184    /// + **Interest Triggers**: If a change in the `interest` mask occurs while the
185    ///   system is suspended, the server MUST NOT complete the `Watch` call until
186    ///   the system wakes for another reason (e.g., a `wake_on` event or external trigger).
187    ///   This ensures the CPU remains asleep for non-critical updates.
188    /// + **Wake-On Triggers**: If a change in the `wake_on` mask occurs, the server
189    ///   MUST wake the system and complete the call immediately with a `wake_lease`.
190    ///
191    /// As a result of this queuing behavior, if multiple changes occur while the
192    /// system is suspended, they may be merged into a single returned `status` table,
193    /// and intermediate state transitions may be lost.
194    ///
195    /// + `interest`: The client wants to be notified if any of the fields present
196    ///   in this table change. If any field in `interest` changes, the method returns.
197    /// + `wake_on`: Similar to `interest`, but if a change occurs in these fields,
198    ///   the server will attempt to keep the system awake using the provided `lease`
199    ///   (or by returning a `wake_lease`) until the client acknowledges the update.
200    /// + `lease`: A power lease token used to coordinate handoff between the server
201    ///   and client, ensuring the system does not suspend before the client can
202    ///   process a critical power event.
203    ///
204    /// Returns:
205    /// + `status`: The updated status table containing the fields that changed.
206    /// + `wake_lease`: An optional lease token provided if the change triggered
207    ///   a `wake_on` condition and the server is maintaining system state.
208    ///
209    /// Errors:
210    /// + `ALREADY_BOUND`: If the source is already being watched.
211    pub fn r#watch(
212        &self,
213        mut interest: &Status,
214        mut wake_on: &Status,
215        mut lease: Option<fidl::EventPair>,
216        ___deadline: zx::MonotonicInstant,
217    ) -> Result<SourceWatchResult, fidl::Error> {
218        let _response = self.client.send_query::<
219            SourceWatchRequest,
220            fidl::encoding::FlexibleResultType<SourceWatchResponse, Error>,
221            SourceMarker,
222        >(
223            (interest, wake_on, lease,),
224            0x15f6187735c58e1,
225            fidl::encoding::DynamicFlags::FLEXIBLE,
226            ___deadline,
227        )?
228        .into_result::<SourceMarker>("watch")?;
229        Ok(_response.map(|x| (x.status, x.wake_lease)))
230    }
231}
232
233#[cfg(target_os = "fuchsia")]
234impl From<SourceSynchronousProxy> for zx::NullableHandle {
235    fn from(value: SourceSynchronousProxy) -> Self {
236        value.into_channel().into()
237    }
238}
239
240#[cfg(target_os = "fuchsia")]
241impl From<fidl::Channel> for SourceSynchronousProxy {
242    fn from(value: fidl::Channel) -> Self {
243        Self::new(value)
244    }
245}
246
247#[cfg(target_os = "fuchsia")]
248impl fidl::endpoints::FromClient for SourceSynchronousProxy {
249    type Protocol = SourceMarker;
250
251    fn from_client(value: fidl::endpoints::ClientEnd<SourceMarker>) -> Self {
252        Self::new(value.into_channel())
253    }
254}
255
256#[derive(Debug, Clone)]
257pub struct SourceProxy {
258    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
259}
260
261impl fidl::endpoints::Proxy for SourceProxy {
262    type Protocol = SourceMarker;
263
264    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
265        Self::new(inner)
266    }
267
268    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
269        self.client.into_channel().map_err(|client| Self { client })
270    }
271
272    fn as_channel(&self) -> &::fidl::AsyncChannel {
273        self.client.as_channel()
274    }
275}
276
277impl SourceProxy {
278    /// Create a new Proxy for fuchsia.hardware.power.source/Source.
279    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
280        let protocol_name = <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
281        Self { client: fidl::client::Client::new(channel, protocol_name) }
282    }
283
284    /// Get a Stream of events from the remote end of the protocol.
285    ///
286    /// # Panics
287    ///
288    /// Panics if the event stream was already taken.
289    pub fn take_event_stream(&self) -> SourceEventStream {
290        SourceEventStream { event_receiver: self.client.take_event_receiver() }
291    }
292
293    /// Returns static hardware characteristics that do not change during operation.
294    pub fn r#get_spec(
295        &self,
296    ) -> fidl::client::QueryResponseFut<
297        SourceGetSpecResult,
298        fidl::encoding::DefaultFuchsiaResourceDialect,
299    > {
300        SourceProxyInterface::r#get_spec(self)
301    }
302
303    /// Returns dynamic status of the source immediately.
304    pub fn r#get_status(
305        &self,
306    ) -> fidl::client::QueryResponseFut<
307        SourceGetStatusResult,
308        fidl::encoding::DefaultFuchsiaResourceDialect,
309    > {
310        SourceProxyInterface::r#get_status(self)
311    }
312
313    /// Set the role of this specific node.
314    ///
315    /// Errors:
316    /// + `INVALID_ARGS`: If the provided role is invalid.
317    /// + `NOT_SUPPORTED`: If the requested role is not supported by the hardware.
318    /// + `INTERNAL`: If an unexpected error occurred.
319    pub fn r#set_role(
320        &self,
321        mut role: &Role,
322    ) -> fidl::client::QueryResponseFut<
323        SourceSetRoleResult,
324        fidl::encoding::DefaultFuchsiaResourceDialect,
325    > {
326        SourceProxyInterface::r#set_role(self, role)
327    }
328
329    /// Change notification for power source state using a "hanging-get" pattern.
330    ///
331    /// The first call to this method returns the current hardware state immediately.
332    /// Subsequent calls block until a change occurs that matches the provided masks.
333    ///
334    /// At most one `Watch` call may be outstanding at a time per connection.
335    /// Completing a call acknowledges that the client has received the previous update.
336    ///
337    /// ### Power Management and Suspend
338    /// To prevent lost wakeups, the server (driver) must ensure that the `Watch` call
339    /// remains active (and hardware interrupts armed) while the system is suspended.
340    ///
341    /// + **Interest Triggers**: If a change in the `interest` mask occurs while the
342    ///   system is suspended, the server MUST NOT complete the `Watch` call until
343    ///   the system wakes for another reason (e.g., a `wake_on` event or external trigger).
344    ///   This ensures the CPU remains asleep for non-critical updates.
345    /// + **Wake-On Triggers**: If a change in the `wake_on` mask occurs, the server
346    ///   MUST wake the system and complete the call immediately with a `wake_lease`.
347    ///
348    /// As a result of this queuing behavior, if multiple changes occur while the
349    /// system is suspended, they may be merged into a single returned `status` table,
350    /// and intermediate state transitions may be lost.
351    ///
352    /// + `interest`: The client wants to be notified if any of the fields present
353    ///   in this table change. If any field in `interest` changes, the method returns.
354    /// + `wake_on`: Similar to `interest`, but if a change occurs in these fields,
355    ///   the server will attempt to keep the system awake using the provided `lease`
356    ///   (or by returning a `wake_lease`) until the client acknowledges the update.
357    /// + `lease`: A power lease token used to coordinate handoff between the server
358    ///   and client, ensuring the system does not suspend before the client can
359    ///   process a critical power event.
360    ///
361    /// Returns:
362    /// + `status`: The updated status table containing the fields that changed.
363    /// + `wake_lease`: An optional lease token provided if the change triggered
364    ///   a `wake_on` condition and the server is maintaining system state.
365    ///
366    /// Errors:
367    /// + `ALREADY_BOUND`: If the source is already being watched.
368    pub fn r#watch(
369        &self,
370        mut interest: &Status,
371        mut wake_on: &Status,
372        mut lease: Option<fidl::EventPair>,
373    ) -> fidl::client::QueryResponseFut<
374        SourceWatchResult,
375        fidl::encoding::DefaultFuchsiaResourceDialect,
376    > {
377        SourceProxyInterface::r#watch(self, interest, wake_on, lease)
378    }
379}
380
381impl SourceProxyInterface for SourceProxy {
382    type GetSpecResponseFut = fidl::client::QueryResponseFut<
383        SourceGetSpecResult,
384        fidl::encoding::DefaultFuchsiaResourceDialect,
385    >;
386    fn r#get_spec(&self) -> Self::GetSpecResponseFut {
387        fn _decode(
388            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
389        ) -> Result<SourceGetSpecResult, fidl::Error> {
390            let _response = fidl::client::decode_transaction_body::<
391                fidl::encoding::FlexibleResultType<SourceGetSpecResponse, Error>,
392                fidl::encoding::DefaultFuchsiaResourceDialect,
393                0x7f756685c3daa1ac,
394            >(_buf?)?
395            .into_result::<SourceMarker>("get_spec")?;
396            Ok(_response.map(|x| x.spec))
397        }
398        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SourceGetSpecResult>(
399            (),
400            0x7f756685c3daa1ac,
401            fidl::encoding::DynamicFlags::FLEXIBLE,
402            _decode,
403        )
404    }
405
406    type GetStatusResponseFut = fidl::client::QueryResponseFut<
407        SourceGetStatusResult,
408        fidl::encoding::DefaultFuchsiaResourceDialect,
409    >;
410    fn r#get_status(&self) -> Self::GetStatusResponseFut {
411        fn _decode(
412            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
413        ) -> Result<SourceGetStatusResult, fidl::Error> {
414            let _response = fidl::client::decode_transaction_body::<
415                fidl::encoding::FlexibleResultType<SourceGetStatusResponse, Error>,
416                fidl::encoding::DefaultFuchsiaResourceDialect,
417                0x121659a401919be7,
418            >(_buf?)?
419            .into_result::<SourceMarker>("get_status")?;
420            Ok(_response.map(|x| x.status))
421        }
422        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SourceGetStatusResult>(
423            (),
424            0x121659a401919be7,
425            fidl::encoding::DynamicFlags::FLEXIBLE,
426            _decode,
427        )
428    }
429
430    type SetRoleResponseFut = fidl::client::QueryResponseFut<
431        SourceSetRoleResult,
432        fidl::encoding::DefaultFuchsiaResourceDialect,
433    >;
434    fn r#set_role(&self, mut role: &Role) -> Self::SetRoleResponseFut {
435        fn _decode(
436            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
437        ) -> Result<SourceSetRoleResult, fidl::Error> {
438            let _response = fidl::client::decode_transaction_body::<
439                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, Error>,
440                fidl::encoding::DefaultFuchsiaResourceDialect,
441                0x2a0b0990da5f4ae1,
442            >(_buf?)?
443            .into_result::<SourceMarker>("set_role")?;
444            Ok(_response.map(|x| x))
445        }
446        self.client.send_query_and_decode::<SourceSetRoleRequest, SourceSetRoleResult>(
447            (role,),
448            0x2a0b0990da5f4ae1,
449            fidl::encoding::DynamicFlags::FLEXIBLE,
450            _decode,
451        )
452    }
453
454    type WatchResponseFut = fidl::client::QueryResponseFut<
455        SourceWatchResult,
456        fidl::encoding::DefaultFuchsiaResourceDialect,
457    >;
458    fn r#watch(
459        &self,
460        mut interest: &Status,
461        mut wake_on: &Status,
462        mut lease: Option<fidl::EventPair>,
463    ) -> Self::WatchResponseFut {
464        fn _decode(
465            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
466        ) -> Result<SourceWatchResult, fidl::Error> {
467            let _response = fidl::client::decode_transaction_body::<
468                fidl::encoding::FlexibleResultType<SourceWatchResponse, Error>,
469                fidl::encoding::DefaultFuchsiaResourceDialect,
470                0x15f6187735c58e1,
471            >(_buf?)?
472            .into_result::<SourceMarker>("watch")?;
473            Ok(_response.map(|x| (x.status, x.wake_lease)))
474        }
475        self.client.send_query_and_decode::<SourceWatchRequest, SourceWatchResult>(
476            (interest, wake_on, lease),
477            0x15f6187735c58e1,
478            fidl::encoding::DynamicFlags::FLEXIBLE,
479            _decode,
480        )
481    }
482}
483
484pub struct SourceEventStream {
485    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
486}
487
488impl std::marker::Unpin for SourceEventStream {}
489
490impl futures::stream::FusedStream for SourceEventStream {
491    fn is_terminated(&self) -> bool {
492        self.event_receiver.is_terminated()
493    }
494}
495
496impl futures::Stream for SourceEventStream {
497    type Item = Result<SourceEvent, fidl::Error>;
498
499    fn poll_next(
500        mut self: std::pin::Pin<&mut Self>,
501        cx: &mut std::task::Context<'_>,
502    ) -> std::task::Poll<Option<Self::Item>> {
503        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
504            &mut self.event_receiver,
505            cx
506        )?) {
507            Some(buf) => std::task::Poll::Ready(Some(SourceEvent::decode(buf))),
508            None => std::task::Poll::Ready(None),
509        }
510    }
511}
512
513#[derive(Debug)]
514pub enum SourceEvent {
515    #[non_exhaustive]
516    _UnknownEvent {
517        /// Ordinal of the event that was sent.
518        ordinal: u64,
519    },
520}
521
522impl SourceEvent {
523    /// Decodes a message buffer as a [`SourceEvent`].
524    fn decode(
525        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
526    ) -> Result<SourceEvent, fidl::Error> {
527        let (bytes, _handles) = buf.split_mut();
528        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
529        debug_assert_eq!(tx_header.tx_id, 0);
530        match tx_header.ordinal {
531            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
532                Ok(SourceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
533            }
534            _ => Err(fidl::Error::UnknownOrdinal {
535                ordinal: tx_header.ordinal,
536                protocol_name: <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
537            }),
538        }
539    }
540}
541
542/// A Stream of incoming requests for fuchsia.hardware.power.source/Source.
543pub struct SourceRequestStream {
544    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
545    is_terminated: bool,
546}
547
548impl std::marker::Unpin for SourceRequestStream {}
549
550impl futures::stream::FusedStream for SourceRequestStream {
551    fn is_terminated(&self) -> bool {
552        self.is_terminated
553    }
554}
555
556impl fidl::endpoints::RequestStream for SourceRequestStream {
557    type Protocol = SourceMarker;
558    type ControlHandle = SourceControlHandle;
559
560    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
561        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
562    }
563
564    fn control_handle(&self) -> Self::ControlHandle {
565        SourceControlHandle { inner: self.inner.clone() }
566    }
567
568    fn into_inner(
569        self,
570    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
571    {
572        (self.inner, self.is_terminated)
573    }
574
575    fn from_inner(
576        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
577        is_terminated: bool,
578    ) -> Self {
579        Self { inner, is_terminated }
580    }
581}
582
583impl futures::Stream for SourceRequestStream {
584    type Item = Result<SourceRequest, fidl::Error>;
585
586    fn poll_next(
587        mut self: std::pin::Pin<&mut Self>,
588        cx: &mut std::task::Context<'_>,
589    ) -> std::task::Poll<Option<Self::Item>> {
590        let this = &mut *self;
591        if this.inner.check_shutdown(cx) {
592            this.is_terminated = true;
593            return std::task::Poll::Ready(None);
594        }
595        if this.is_terminated {
596            panic!("polled SourceRequestStream after completion");
597        }
598        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
599            |bytes, handles| {
600                match this.inner.channel().read_etc(cx, bytes, handles) {
601                    std::task::Poll::Ready(Ok(())) => {}
602                    std::task::Poll::Pending => return std::task::Poll::Pending,
603                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
604                        this.is_terminated = true;
605                        return std::task::Poll::Ready(None);
606                    }
607                    std::task::Poll::Ready(Err(e)) => {
608                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
609                            e.into(),
610                        ))));
611                    }
612                }
613
614                // A message has been received from the channel
615                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
616
617                std::task::Poll::Ready(Some(match header.ordinal {
618                    0x7f756685c3daa1ac => {
619                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
620                        let mut req = fidl::new_empty!(
621                            fidl::encoding::EmptyPayload,
622                            fidl::encoding::DefaultFuchsiaResourceDialect
623                        );
624                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
625                        let control_handle = SourceControlHandle { inner: this.inner.clone() };
626                        Ok(SourceRequest::GetSpec {
627                            responder: SourceGetSpecResponder {
628                                control_handle: std::mem::ManuallyDrop::new(control_handle),
629                                tx_id: header.tx_id,
630                            },
631                        })
632                    }
633                    0x121659a401919be7 => {
634                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
635                        let mut req = fidl::new_empty!(
636                            fidl::encoding::EmptyPayload,
637                            fidl::encoding::DefaultFuchsiaResourceDialect
638                        );
639                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
640                        let control_handle = SourceControlHandle { inner: this.inner.clone() };
641                        Ok(SourceRequest::GetStatus {
642                            responder: SourceGetStatusResponder {
643                                control_handle: std::mem::ManuallyDrop::new(control_handle),
644                                tx_id: header.tx_id,
645                            },
646                        })
647                    }
648                    0x2a0b0990da5f4ae1 => {
649                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
650                        let mut req = fidl::new_empty!(
651                            SourceSetRoleRequest,
652                            fidl::encoding::DefaultFuchsiaResourceDialect
653                        );
654                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SourceSetRoleRequest>(&header, _body_bytes, handles, &mut req)?;
655                        let control_handle = SourceControlHandle { inner: this.inner.clone() };
656                        Ok(SourceRequest::SetRole {
657                            role: req.role,
658
659                            responder: SourceSetRoleResponder {
660                                control_handle: std::mem::ManuallyDrop::new(control_handle),
661                                tx_id: header.tx_id,
662                            },
663                        })
664                    }
665                    0x15f6187735c58e1 => {
666                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
667                        let mut req = fidl::new_empty!(
668                            SourceWatchRequest,
669                            fidl::encoding::DefaultFuchsiaResourceDialect
670                        );
671                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SourceWatchRequest>(&header, _body_bytes, handles, &mut req)?;
672                        let control_handle = SourceControlHandle { inner: this.inner.clone() };
673                        Ok(SourceRequest::Watch {
674                            interest: req.interest,
675                            wake_on: req.wake_on,
676                            lease: req.lease,
677
678                            responder: SourceWatchResponder {
679                                control_handle: std::mem::ManuallyDrop::new(control_handle),
680                                tx_id: header.tx_id,
681                            },
682                        })
683                    }
684                    _ if header.tx_id == 0
685                        && header
686                            .dynamic_flags()
687                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
688                    {
689                        Ok(SourceRequest::_UnknownMethod {
690                            ordinal: header.ordinal,
691                            control_handle: SourceControlHandle { inner: this.inner.clone() },
692                            method_type: fidl::MethodType::OneWay,
693                        })
694                    }
695                    _ if header
696                        .dynamic_flags()
697                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
698                    {
699                        this.inner.send_framework_err(
700                            fidl::encoding::FrameworkErr::UnknownMethod,
701                            header.tx_id,
702                            header.ordinal,
703                            header.dynamic_flags(),
704                            (bytes, handles),
705                        )?;
706                        Ok(SourceRequest::_UnknownMethod {
707                            ordinal: header.ordinal,
708                            control_handle: SourceControlHandle { inner: this.inner.clone() },
709                            method_type: fidl::MethodType::TwoWay,
710                        })
711                    }
712                    _ => Err(fidl::Error::UnknownOrdinal {
713                        ordinal: header.ordinal,
714                        protocol_name:
715                            <SourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
716                    }),
717                }))
718            },
719        )
720    }
721}
722
723#[derive(Debug)]
724pub enum SourceRequest {
725    /// Returns static hardware characteristics that do not change during operation.
726    GetSpec { responder: SourceGetSpecResponder },
727    /// Returns dynamic status of the source immediately.
728    GetStatus { responder: SourceGetStatusResponder },
729    /// Set the role of this specific node.
730    ///
731    /// Errors:
732    /// + `INVALID_ARGS`: If the provided role is invalid.
733    /// + `NOT_SUPPORTED`: If the requested role is not supported by the hardware.
734    /// + `INTERNAL`: If an unexpected error occurred.
735    SetRole { role: Role, responder: SourceSetRoleResponder },
736    /// Change notification for power source state using a "hanging-get" pattern.
737    ///
738    /// The first call to this method returns the current hardware state immediately.
739    /// Subsequent calls block until a change occurs that matches the provided masks.
740    ///
741    /// At most one `Watch` call may be outstanding at a time per connection.
742    /// Completing a call acknowledges that the client has received the previous update.
743    ///
744    /// ### Power Management and Suspend
745    /// To prevent lost wakeups, the server (driver) must ensure that the `Watch` call
746    /// remains active (and hardware interrupts armed) while the system is suspended.
747    ///
748    /// + **Interest Triggers**: If a change in the `interest` mask occurs while the
749    ///   system is suspended, the server MUST NOT complete the `Watch` call until
750    ///   the system wakes for another reason (e.g., a `wake_on` event or external trigger).
751    ///   This ensures the CPU remains asleep for non-critical updates.
752    /// + **Wake-On Triggers**: If a change in the `wake_on` mask occurs, the server
753    ///   MUST wake the system and complete the call immediately with a `wake_lease`.
754    ///
755    /// As a result of this queuing behavior, if multiple changes occur while the
756    /// system is suspended, they may be merged into a single returned `status` table,
757    /// and intermediate state transitions may be lost.
758    ///
759    /// + `interest`: The client wants to be notified if any of the fields present
760    ///   in this table change. If any field in `interest` changes, the method returns.
761    /// + `wake_on`: Similar to `interest`, but if a change occurs in these fields,
762    ///   the server will attempt to keep the system awake using the provided `lease`
763    ///   (or by returning a `wake_lease`) until the client acknowledges the update.
764    /// + `lease`: A power lease token used to coordinate handoff between the server
765    ///   and client, ensuring the system does not suspend before the client can
766    ///   process a critical power event.
767    ///
768    /// Returns:
769    /// + `status`: The updated status table containing the fields that changed.
770    /// + `wake_lease`: An optional lease token provided if the change triggered
771    ///   a `wake_on` condition and the server is maintaining system state.
772    ///
773    /// Errors:
774    /// + `ALREADY_BOUND`: If the source is already being watched.
775    Watch {
776        interest: Status,
777        wake_on: Status,
778        lease: Option<fidl::EventPair>,
779        responder: SourceWatchResponder,
780    },
781    /// An interaction was received which does not match any known method.
782    #[non_exhaustive]
783    _UnknownMethod {
784        /// Ordinal of the method that was called.
785        ordinal: u64,
786        control_handle: SourceControlHandle,
787        method_type: fidl::MethodType,
788    },
789}
790
791impl SourceRequest {
792    #[allow(irrefutable_let_patterns)]
793    pub fn into_get_spec(self) -> Option<(SourceGetSpecResponder)> {
794        if let SourceRequest::GetSpec { responder } = self { Some((responder)) } else { None }
795    }
796
797    #[allow(irrefutable_let_patterns)]
798    pub fn into_get_status(self) -> Option<(SourceGetStatusResponder)> {
799        if let SourceRequest::GetStatus { responder } = self { Some((responder)) } else { None }
800    }
801
802    #[allow(irrefutable_let_patterns)]
803    pub fn into_set_role(self) -> Option<(Role, SourceSetRoleResponder)> {
804        if let SourceRequest::SetRole { role, responder } = self {
805            Some((role, responder))
806        } else {
807            None
808        }
809    }
810
811    #[allow(irrefutable_let_patterns)]
812    pub fn into_watch(
813        self,
814    ) -> Option<(Status, Status, Option<fidl::EventPair>, SourceWatchResponder)> {
815        if let SourceRequest::Watch { interest, wake_on, lease, responder } = self {
816            Some((interest, wake_on, lease, responder))
817        } else {
818            None
819        }
820    }
821
822    /// Name of the method defined in FIDL
823    pub fn method_name(&self) -> &'static str {
824        match *self {
825            SourceRequest::GetSpec { .. } => "get_spec",
826            SourceRequest::GetStatus { .. } => "get_status",
827            SourceRequest::SetRole { .. } => "set_role",
828            SourceRequest::Watch { .. } => "watch",
829            SourceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
830                "unknown one-way method"
831            }
832            SourceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
833                "unknown two-way method"
834            }
835        }
836    }
837}
838
839#[derive(Debug, Clone)]
840pub struct SourceControlHandle {
841    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
842}
843
844impl SourceControlHandle {
845    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
846        self.inner.shutdown_with_epitaph(status.into())
847    }
848}
849
850impl fidl::endpoints::ControlHandle for SourceControlHandle {
851    fn shutdown(&self) {
852        self.inner.shutdown()
853    }
854
855    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
856        self.inner.shutdown_with_epitaph(status)
857    }
858
859    fn is_closed(&self) -> bool {
860        self.inner.channel().is_closed()
861    }
862    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
863        self.inner.channel().on_closed()
864    }
865
866    #[cfg(target_os = "fuchsia")]
867    fn signal_peer(
868        &self,
869        clear_mask: zx::Signals,
870        set_mask: zx::Signals,
871    ) -> Result<(), zx_status::Status> {
872        use fidl::Peered;
873        self.inner.channel().signal_peer(clear_mask, set_mask)
874    }
875}
876
877impl SourceControlHandle {}
878
879#[must_use = "FIDL methods require a response to be sent"]
880#[derive(Debug)]
881pub struct SourceGetSpecResponder {
882    control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
883    tx_id: u32,
884}
885
886/// Set the the channel to be shutdown (see [`SourceControlHandle::shutdown`])
887/// if the responder is dropped without sending a response, so that the client
888/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
889impl std::ops::Drop for SourceGetSpecResponder {
890    fn drop(&mut self) {
891        self.control_handle.shutdown();
892        // Safety: drops once, never accessed again
893        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
894    }
895}
896
897impl fidl::endpoints::Responder for SourceGetSpecResponder {
898    type ControlHandle = SourceControlHandle;
899
900    fn control_handle(&self) -> &SourceControlHandle {
901        &self.control_handle
902    }
903
904    fn drop_without_shutdown(mut self) {
905        // Safety: drops once, never accessed again due to mem::forget
906        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
907        // Prevent Drop from running (which would shut down the channel)
908        std::mem::forget(self);
909    }
910}
911
912impl SourceGetSpecResponder {
913    /// Sends a response to the FIDL transaction.
914    ///
915    /// Sets the channel to shutdown if an error occurs.
916    pub fn send(self, mut result: Result<&Spec, Error>) -> Result<(), fidl::Error> {
917        let _result = self.send_raw(result);
918        if _result.is_err() {
919            self.control_handle.shutdown();
920        }
921        self.drop_without_shutdown();
922        _result
923    }
924
925    /// Similar to "send" but does not shutdown the channel if an error occurs.
926    pub fn send_no_shutdown_on_err(
927        self,
928        mut result: Result<&Spec, Error>,
929    ) -> Result<(), fidl::Error> {
930        let _result = self.send_raw(result);
931        self.drop_without_shutdown();
932        _result
933    }
934
935    fn send_raw(&self, mut result: Result<&Spec, Error>) -> Result<(), fidl::Error> {
936        self.control_handle
937            .inner
938            .send::<fidl::encoding::FlexibleResultType<SourceGetSpecResponse, Error>>(
939                fidl::encoding::FlexibleResult::new(result.map(|spec| (spec,))),
940                self.tx_id,
941                0x7f756685c3daa1ac,
942                fidl::encoding::DynamicFlags::FLEXIBLE,
943            )
944    }
945}
946
947#[must_use = "FIDL methods require a response to be sent"]
948#[derive(Debug)]
949pub struct SourceGetStatusResponder {
950    control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
951    tx_id: u32,
952}
953
954/// Set the the channel to be shutdown (see [`SourceControlHandle::shutdown`])
955/// if the responder is dropped without sending a response, so that the client
956/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
957impl std::ops::Drop for SourceGetStatusResponder {
958    fn drop(&mut self) {
959        self.control_handle.shutdown();
960        // Safety: drops once, never accessed again
961        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
962    }
963}
964
965impl fidl::endpoints::Responder for SourceGetStatusResponder {
966    type ControlHandle = SourceControlHandle;
967
968    fn control_handle(&self) -> &SourceControlHandle {
969        &self.control_handle
970    }
971
972    fn drop_without_shutdown(mut self) {
973        // Safety: drops once, never accessed again due to mem::forget
974        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
975        // Prevent Drop from running (which would shut down the channel)
976        std::mem::forget(self);
977    }
978}
979
980impl SourceGetStatusResponder {
981    /// Sends a response to the FIDL transaction.
982    ///
983    /// Sets the channel to shutdown if an error occurs.
984    pub fn send(self, mut result: Result<&Status, Error>) -> Result<(), fidl::Error> {
985        let _result = self.send_raw(result);
986        if _result.is_err() {
987            self.control_handle.shutdown();
988        }
989        self.drop_without_shutdown();
990        _result
991    }
992
993    /// Similar to "send" but does not shutdown the channel if an error occurs.
994    pub fn send_no_shutdown_on_err(
995        self,
996        mut result: Result<&Status, Error>,
997    ) -> Result<(), fidl::Error> {
998        let _result = self.send_raw(result);
999        self.drop_without_shutdown();
1000        _result
1001    }
1002
1003    fn send_raw(&self, mut result: Result<&Status, Error>) -> Result<(), fidl::Error> {
1004        self.control_handle
1005            .inner
1006            .send::<fidl::encoding::FlexibleResultType<SourceGetStatusResponse, Error>>(
1007                fidl::encoding::FlexibleResult::new(result.map(|status| (status,))),
1008                self.tx_id,
1009                0x121659a401919be7,
1010                fidl::encoding::DynamicFlags::FLEXIBLE,
1011            )
1012    }
1013}
1014
1015#[must_use = "FIDL methods require a response to be sent"]
1016#[derive(Debug)]
1017pub struct SourceSetRoleResponder {
1018    control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
1019    tx_id: u32,
1020}
1021
1022/// Set the the channel to be shutdown (see [`SourceControlHandle::shutdown`])
1023/// if the responder is dropped without sending a response, so that the client
1024/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1025impl std::ops::Drop for SourceSetRoleResponder {
1026    fn drop(&mut self) {
1027        self.control_handle.shutdown();
1028        // Safety: drops once, never accessed again
1029        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1030    }
1031}
1032
1033impl fidl::endpoints::Responder for SourceSetRoleResponder {
1034    type ControlHandle = SourceControlHandle;
1035
1036    fn control_handle(&self) -> &SourceControlHandle {
1037        &self.control_handle
1038    }
1039
1040    fn drop_without_shutdown(mut self) {
1041        // Safety: drops once, never accessed again due to mem::forget
1042        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1043        // Prevent Drop from running (which would shut down the channel)
1044        std::mem::forget(self);
1045    }
1046}
1047
1048impl SourceSetRoleResponder {
1049    /// Sends a response to the FIDL transaction.
1050    ///
1051    /// Sets the channel to shutdown if an error occurs.
1052    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1053        let _result = self.send_raw(result);
1054        if _result.is_err() {
1055            self.control_handle.shutdown();
1056        }
1057        self.drop_without_shutdown();
1058        _result
1059    }
1060
1061    /// Similar to "send" but does not shutdown the channel if an error occurs.
1062    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1063        let _result = self.send_raw(result);
1064        self.drop_without_shutdown();
1065        _result
1066    }
1067
1068    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1069        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1070            fidl::encoding::EmptyStruct,
1071            Error,
1072        >>(
1073            fidl::encoding::FlexibleResult::new(result),
1074            self.tx_id,
1075            0x2a0b0990da5f4ae1,
1076            fidl::encoding::DynamicFlags::FLEXIBLE,
1077        )
1078    }
1079}
1080
1081#[must_use = "FIDL methods require a response to be sent"]
1082#[derive(Debug)]
1083pub struct SourceWatchResponder {
1084    control_handle: std::mem::ManuallyDrop<SourceControlHandle>,
1085    tx_id: u32,
1086}
1087
1088/// Set the the channel to be shutdown (see [`SourceControlHandle::shutdown`])
1089/// if the responder is dropped without sending a response, so that the client
1090/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1091impl std::ops::Drop for SourceWatchResponder {
1092    fn drop(&mut self) {
1093        self.control_handle.shutdown();
1094        // Safety: drops once, never accessed again
1095        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1096    }
1097}
1098
1099impl fidl::endpoints::Responder for SourceWatchResponder {
1100    type ControlHandle = SourceControlHandle;
1101
1102    fn control_handle(&self) -> &SourceControlHandle {
1103        &self.control_handle
1104    }
1105
1106    fn drop_without_shutdown(mut self) {
1107        // Safety: drops once, never accessed again due to mem::forget
1108        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1109        // Prevent Drop from running (which would shut down the channel)
1110        std::mem::forget(self);
1111    }
1112}
1113
1114impl SourceWatchResponder {
1115    /// Sends a response to the FIDL transaction.
1116    ///
1117    /// Sets the channel to shutdown if an error occurs.
1118    pub fn send(
1119        self,
1120        mut result: Result<(&Status, Option<fidl::EventPair>), Error>,
1121    ) -> Result<(), fidl::Error> {
1122        let _result = self.send_raw(result);
1123        if _result.is_err() {
1124            self.control_handle.shutdown();
1125        }
1126        self.drop_without_shutdown();
1127        _result
1128    }
1129
1130    /// Similar to "send" but does not shutdown the channel if an error occurs.
1131    pub fn send_no_shutdown_on_err(
1132        self,
1133        mut result: Result<(&Status, Option<fidl::EventPair>), Error>,
1134    ) -> Result<(), fidl::Error> {
1135        let _result = self.send_raw(result);
1136        self.drop_without_shutdown();
1137        _result
1138    }
1139
1140    fn send_raw(
1141        &self,
1142        mut result: Result<(&Status, Option<fidl::EventPair>), Error>,
1143    ) -> Result<(), fidl::Error> {
1144        self.control_handle
1145            .inner
1146            .send::<fidl::encoding::FlexibleResultType<SourceWatchResponse, Error>>(
1147                fidl::encoding::FlexibleResult::new(result),
1148                self.tx_id,
1149                0x15f6187735c58e1,
1150                fidl::encoding::DynamicFlags::FLEXIBLE,
1151            )
1152    }
1153}
1154
1155#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1156pub struct ServiceMarker;
1157
1158#[cfg(target_os = "fuchsia")]
1159impl fidl::endpoints::ServiceMarker for ServiceMarker {
1160    type Proxy = ServiceProxy;
1161    type Request = ServiceRequest;
1162    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.source.Service";
1163}
1164
1165/// A request for one of the member protocols of Service.
1166///
1167#[cfg(target_os = "fuchsia")]
1168pub enum ServiceRequest {
1169    Source(SourceRequestStream),
1170}
1171
1172#[cfg(target_os = "fuchsia")]
1173impl fidl::endpoints::ServiceRequest for ServiceRequest {
1174    type Service = ServiceMarker;
1175
1176    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1177        match name {
1178            "source" => Self::Source(
1179                <SourceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1180            ),
1181            _ => panic!("no such member protocol name for service Service"),
1182        }
1183    }
1184
1185    fn member_names() -> &'static [&'static str] {
1186        &["source"]
1187    }
1188}
1189#[cfg(target_os = "fuchsia")]
1190pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1191
1192#[cfg(target_os = "fuchsia")]
1193impl fidl::endpoints::ServiceProxy for ServiceProxy {
1194    type Service = ServiceMarker;
1195
1196    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1197        Self(opener)
1198    }
1199}
1200
1201#[cfg(target_os = "fuchsia")]
1202impl ServiceProxy {
1203    pub fn connect_to_source(&self) -> Result<SourceProxy, fidl::Error> {
1204        let (proxy, server_end) = fidl::endpoints::create_proxy::<SourceMarker>();
1205        self.connect_channel_to_source(server_end)?;
1206        Ok(proxy)
1207    }
1208
1209    /// Like `connect_to_source`, but returns a sync proxy.
1210    /// See [`Self::connect_to_source`] for more details.
1211    pub fn connect_to_source_sync(&self) -> Result<SourceSynchronousProxy, fidl::Error> {
1212        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<SourceMarker>();
1213        self.connect_channel_to_source(server_end)?;
1214        Ok(proxy)
1215    }
1216
1217    /// Like `connect_to_source`, but accepts a server end.
1218    /// See [`Self::connect_to_source`] for more details.
1219    pub fn connect_channel_to_source(
1220        &self,
1221        server_end: fidl::endpoints::ServerEnd<SourceMarker>,
1222    ) -> Result<(), fidl::Error> {
1223        self.0.open_member("source", server_end.into_channel())
1224    }
1225
1226    pub fn instance_name(&self) -> &str {
1227        self.0.instance_name()
1228    }
1229}
1230
1231mod internal {
1232    use super::*;
1233
1234    impl fidl::encoding::ResourceTypeMarker for SourceWatchRequest {
1235        type Borrowed<'a> = &'a mut Self;
1236        fn take_or_borrow<'a>(
1237            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1238        ) -> Self::Borrowed<'a> {
1239            value
1240        }
1241    }
1242
1243    unsafe impl fidl::encoding::TypeMarker for SourceWatchRequest {
1244        type Owned = Self;
1245
1246        #[inline(always)]
1247        fn inline_align(_context: fidl::encoding::Context) -> usize {
1248            8
1249        }
1250
1251        #[inline(always)]
1252        fn inline_size(_context: fidl::encoding::Context) -> usize {
1253            40
1254        }
1255    }
1256
1257    unsafe impl
1258        fidl::encoding::Encode<SourceWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1259        for &mut SourceWatchRequest
1260    {
1261        #[inline]
1262        unsafe fn encode(
1263            self,
1264            encoder: &mut fidl::encoding::Encoder<
1265                '_,
1266                fidl::encoding::DefaultFuchsiaResourceDialect,
1267            >,
1268            offset: usize,
1269            _depth: fidl::encoding::Depth,
1270        ) -> fidl::Result<()> {
1271            encoder.debug_check_bounds::<SourceWatchRequest>(offset);
1272            // Delegate to tuple encoding.
1273            fidl::encoding::Encode::<
1274                SourceWatchRequest,
1275                fidl::encoding::DefaultFuchsiaResourceDialect,
1276            >::encode(
1277                (
1278                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.interest),
1279                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.wake_on),
1280                    <fidl::encoding::Optional<
1281                        fidl::encoding::HandleType<
1282                            fidl::EventPair,
1283                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1284                            16387,
1285                        >,
1286                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1287                        &mut self.lease
1288                    ),
1289                ),
1290                encoder,
1291                offset,
1292                _depth,
1293            )
1294        }
1295    }
1296    unsafe impl<
1297        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1298        T1: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1299        T2: fidl::encoding::Encode<
1300                fidl::encoding::Optional<
1301                    fidl::encoding::HandleType<
1302                        fidl::EventPair,
1303                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1304                        16387,
1305                    >,
1306                >,
1307                fidl::encoding::DefaultFuchsiaResourceDialect,
1308            >,
1309    > fidl::encoding::Encode<SourceWatchRequest, fidl::encoding::DefaultFuchsiaResourceDialect>
1310        for (T0, T1, T2)
1311    {
1312        #[inline]
1313        unsafe fn encode(
1314            self,
1315            encoder: &mut fidl::encoding::Encoder<
1316                '_,
1317                fidl::encoding::DefaultFuchsiaResourceDialect,
1318            >,
1319            offset: usize,
1320            depth: fidl::encoding::Depth,
1321        ) -> fidl::Result<()> {
1322            encoder.debug_check_bounds::<SourceWatchRequest>(offset);
1323            // Zero out padding regions. There's no need to apply masks
1324            // because the unmasked parts will be overwritten by fields.
1325            unsafe {
1326                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
1327                (ptr as *mut u64).write_unaligned(0);
1328            }
1329            // Write the fields.
1330            self.0.encode(encoder, offset + 0, depth)?;
1331            self.1.encode(encoder, offset + 16, depth)?;
1332            self.2.encode(encoder, offset + 32, depth)?;
1333            Ok(())
1334        }
1335    }
1336
1337    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1338        for SourceWatchRequest
1339    {
1340        #[inline(always)]
1341        fn new_empty() -> Self {
1342            Self {
1343                interest: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1344                wake_on: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1345                lease: fidl::new_empty!(
1346                    fidl::encoding::Optional<
1347                        fidl::encoding::HandleType<
1348                            fidl::EventPair,
1349                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1350                            16387,
1351                        >,
1352                    >,
1353                    fidl::encoding::DefaultFuchsiaResourceDialect
1354                ),
1355            }
1356        }
1357
1358        #[inline]
1359        unsafe fn decode(
1360            &mut self,
1361            decoder: &mut fidl::encoding::Decoder<
1362                '_,
1363                fidl::encoding::DefaultFuchsiaResourceDialect,
1364            >,
1365            offset: usize,
1366            _depth: fidl::encoding::Depth,
1367        ) -> fidl::Result<()> {
1368            decoder.debug_check_bounds::<Self>(offset);
1369            // Verify that padding bytes are zero.
1370            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
1371            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1372            let mask = 0xffffffff00000000u64;
1373            let maskedval = padval & mask;
1374            if maskedval != 0 {
1375                return Err(fidl::Error::NonZeroPadding {
1376                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
1377                });
1378            }
1379            fidl::decode!(
1380                Status,
1381                fidl::encoding::DefaultFuchsiaResourceDialect,
1382                &mut self.interest,
1383                decoder,
1384                offset + 0,
1385                _depth
1386            )?;
1387            fidl::decode!(
1388                Status,
1389                fidl::encoding::DefaultFuchsiaResourceDialect,
1390                &mut self.wake_on,
1391                decoder,
1392                offset + 16,
1393                _depth
1394            )?;
1395            fidl::decode!(
1396                fidl::encoding::Optional<
1397                    fidl::encoding::HandleType<
1398                        fidl::EventPair,
1399                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1400                        16387,
1401                    >,
1402                >,
1403                fidl::encoding::DefaultFuchsiaResourceDialect,
1404                &mut self.lease,
1405                decoder,
1406                offset + 32,
1407                _depth
1408            )?;
1409            Ok(())
1410        }
1411    }
1412
1413    impl fidl::encoding::ResourceTypeMarker for SourceWatchResponse {
1414        type Borrowed<'a> = &'a mut Self;
1415        fn take_or_borrow<'a>(
1416            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1417        ) -> Self::Borrowed<'a> {
1418            value
1419        }
1420    }
1421
1422    unsafe impl fidl::encoding::TypeMarker for SourceWatchResponse {
1423        type Owned = Self;
1424
1425        #[inline(always)]
1426        fn inline_align(_context: fidl::encoding::Context) -> usize {
1427            8
1428        }
1429
1430        #[inline(always)]
1431        fn inline_size(_context: fidl::encoding::Context) -> usize {
1432            24
1433        }
1434    }
1435
1436    unsafe impl
1437        fidl::encoding::Encode<SourceWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1438        for &mut SourceWatchResponse
1439    {
1440        #[inline]
1441        unsafe fn encode(
1442            self,
1443            encoder: &mut fidl::encoding::Encoder<
1444                '_,
1445                fidl::encoding::DefaultFuchsiaResourceDialect,
1446            >,
1447            offset: usize,
1448            _depth: fidl::encoding::Depth,
1449        ) -> fidl::Result<()> {
1450            encoder.debug_check_bounds::<SourceWatchResponse>(offset);
1451            // Delegate to tuple encoding.
1452            fidl::encoding::Encode::<
1453                SourceWatchResponse,
1454                fidl::encoding::DefaultFuchsiaResourceDialect,
1455            >::encode(
1456                (
1457                    <Status as fidl::encoding::ValueTypeMarker>::borrow(&self.status),
1458                    <fidl::encoding::Optional<
1459                        fidl::encoding::HandleType<
1460                            fidl::EventPair,
1461                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1462                            16387,
1463                        >,
1464                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
1465                        &mut self.wake_lease
1466                    ),
1467                ),
1468                encoder,
1469                offset,
1470                _depth,
1471            )
1472        }
1473    }
1474    unsafe impl<
1475        T0: fidl::encoding::Encode<Status, fidl::encoding::DefaultFuchsiaResourceDialect>,
1476        T1: fidl::encoding::Encode<
1477                fidl::encoding::Optional<
1478                    fidl::encoding::HandleType<
1479                        fidl::EventPair,
1480                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1481                        16387,
1482                    >,
1483                >,
1484                fidl::encoding::DefaultFuchsiaResourceDialect,
1485            >,
1486    > fidl::encoding::Encode<SourceWatchResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
1487        for (T0, T1)
1488    {
1489        #[inline]
1490        unsafe fn encode(
1491            self,
1492            encoder: &mut fidl::encoding::Encoder<
1493                '_,
1494                fidl::encoding::DefaultFuchsiaResourceDialect,
1495            >,
1496            offset: usize,
1497            depth: fidl::encoding::Depth,
1498        ) -> fidl::Result<()> {
1499            encoder.debug_check_bounds::<SourceWatchResponse>(offset);
1500            // Zero out padding regions. There's no need to apply masks
1501            // because the unmasked parts will be overwritten by fields.
1502            unsafe {
1503                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(16);
1504                (ptr as *mut u64).write_unaligned(0);
1505            }
1506            // Write the fields.
1507            self.0.encode(encoder, offset + 0, depth)?;
1508            self.1.encode(encoder, offset + 16, depth)?;
1509            Ok(())
1510        }
1511    }
1512
1513    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1514        for SourceWatchResponse
1515    {
1516        #[inline(always)]
1517        fn new_empty() -> Self {
1518            Self {
1519                status: fidl::new_empty!(Status, fidl::encoding::DefaultFuchsiaResourceDialect),
1520                wake_lease: fidl::new_empty!(
1521                    fidl::encoding::Optional<
1522                        fidl::encoding::HandleType<
1523                            fidl::EventPair,
1524                            { fidl::ObjectType::EVENTPAIR.into_raw() },
1525                            16387,
1526                        >,
1527                    >,
1528                    fidl::encoding::DefaultFuchsiaResourceDialect
1529                ),
1530            }
1531        }
1532
1533        #[inline]
1534        unsafe fn decode(
1535            &mut self,
1536            decoder: &mut fidl::encoding::Decoder<
1537                '_,
1538                fidl::encoding::DefaultFuchsiaResourceDialect,
1539            >,
1540            offset: usize,
1541            _depth: fidl::encoding::Depth,
1542        ) -> fidl::Result<()> {
1543            decoder.debug_check_bounds::<Self>(offset);
1544            // Verify that padding bytes are zero.
1545            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(16) };
1546            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1547            let mask = 0xffffffff00000000u64;
1548            let maskedval = padval & mask;
1549            if maskedval != 0 {
1550                return Err(fidl::Error::NonZeroPadding {
1551                    padding_start: offset + 16 + ((mask as u64).trailing_zeros() / 8) as usize,
1552                });
1553            }
1554            fidl::decode!(
1555                Status,
1556                fidl::encoding::DefaultFuchsiaResourceDialect,
1557                &mut self.status,
1558                decoder,
1559                offset + 0,
1560                _depth
1561            )?;
1562            fidl::decode!(
1563                fidl::encoding::Optional<
1564                    fidl::encoding::HandleType<
1565                        fidl::EventPair,
1566                        { fidl::ObjectType::EVENTPAIR.into_raw() },
1567                        16387,
1568                    >,
1569                >,
1570                fidl::encoding::DefaultFuchsiaResourceDialect,
1571                &mut self.wake_lease,
1572                decoder,
1573                offset + 16,
1574                _depth
1575            )?;
1576            Ok(())
1577        }
1578    }
1579}