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