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