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