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