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