fidl_fuchsia_hardware_power_sensor/
fidl_fuchsia_hardware_power_sensor.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_hardware_power_sensor__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18    type Proxy = DeviceProxy;
19    type RequestStream = DeviceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.hardware.power.sensor.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26pub type DeviceGetPowerWattsResult = Result<f32, i32>;
27pub type DeviceGetVoltageVoltsResult = Result<f32, i32>;
28
29pub trait DeviceProxyInterface: Send + Sync {
30    type GetPowerWattsResponseFut: std::future::Future<Output = Result<DeviceGetPowerWattsResult, fidl::Error>>
31        + Send;
32    fn r#get_power_watts(&self) -> Self::GetPowerWattsResponseFut;
33    type GetVoltageVoltsResponseFut: std::future::Future<Output = Result<DeviceGetVoltageVoltsResult, fidl::Error>>
34        + Send;
35    fn r#get_voltage_volts(&self) -> Self::GetVoltageVoltsResponseFut;
36    type GetSensorNameResponseFut: std::future::Future<Output = Result<String, fidl::Error>> + Send;
37    fn r#get_sensor_name(&self) -> Self::GetSensorNameResponseFut;
38}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct DeviceSynchronousProxy {
42    client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
47    type Proxy = DeviceProxy;
48    type Protocol = DeviceMarker;
49
50    fn from_channel(inner: fidl::Channel) -> Self {
51        Self::new(inner)
52    }
53
54    fn into_channel(self) -> fidl::Channel {
55        self.client.into_channel()
56    }
57
58    fn as_channel(&self) -> &fidl::Channel {
59        self.client.as_channel()
60    }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl DeviceSynchronousProxy {
65    pub fn new(channel: fidl::Channel) -> Self {
66        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
67        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
68    }
69
70    pub fn into_channel(self) -> fidl::Channel {
71        self.client.into_channel()
72    }
73
74    /// Waits until an event arrives and returns it. It is safe for other
75    /// threads to make concurrent requests while waiting for an event.
76    pub fn wait_for_event(
77        &self,
78        deadline: zx::MonotonicInstant,
79    ) -> Result<DeviceEvent, fidl::Error> {
80        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
81    }
82
83    pub fn r#get_power_watts(
84        &self,
85        ___deadline: zx::MonotonicInstant,
86    ) -> Result<DeviceGetPowerWattsResult, fidl::Error> {
87        let _response = self.client.send_query::<
88            fidl::encoding::EmptyPayload,
89            fidl::encoding::ResultType<DeviceGetPowerWattsResponse, i32>,
90        >(
91            (),
92            0x552bb46982c1957b,
93            fidl::encoding::DynamicFlags::empty(),
94            ___deadline,
95        )?;
96        Ok(_response.map(|x| x.power))
97    }
98
99    pub fn r#get_voltage_volts(
100        &self,
101        ___deadline: zx::MonotonicInstant,
102    ) -> Result<DeviceGetVoltageVoltsResult, fidl::Error> {
103        let _response = self.client.send_query::<
104            fidl::encoding::EmptyPayload,
105            fidl::encoding::ResultType<DeviceGetVoltageVoltsResponse, i32>,
106        >(
107            (),
108            0x4b0d0841e3445c37,
109            fidl::encoding::DynamicFlags::empty(),
110            ___deadline,
111        )?;
112        Ok(_response.map(|x| x.voltage))
113    }
114
115    pub fn r#get_sensor_name(
116        &self,
117        ___deadline: zx::MonotonicInstant,
118    ) -> Result<String, fidl::Error> {
119        let _response =
120            self.client.send_query::<fidl::encoding::EmptyPayload, DeviceGetSensorNameResponse>(
121                (),
122                0x3cf646dfaf29b21a,
123                fidl::encoding::DynamicFlags::empty(),
124                ___deadline,
125            )?;
126        Ok(_response.name)
127    }
128}
129
130#[cfg(target_os = "fuchsia")]
131impl From<DeviceSynchronousProxy> for zx::Handle {
132    fn from(value: DeviceSynchronousProxy) -> Self {
133        value.into_channel().into()
134    }
135}
136
137#[cfg(target_os = "fuchsia")]
138impl From<fidl::Channel> for DeviceSynchronousProxy {
139    fn from(value: fidl::Channel) -> Self {
140        Self::new(value)
141    }
142}
143
144#[cfg(target_os = "fuchsia")]
145impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
146    type Protocol = DeviceMarker;
147
148    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
149        Self::new(value.into_channel())
150    }
151}
152
153#[derive(Debug, Clone)]
154pub struct DeviceProxy {
155    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
156}
157
158impl fidl::endpoints::Proxy for DeviceProxy {
159    type Protocol = DeviceMarker;
160
161    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
162        Self::new(inner)
163    }
164
165    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
166        self.client.into_channel().map_err(|client| Self { client })
167    }
168
169    fn as_channel(&self) -> &::fidl::AsyncChannel {
170        self.client.as_channel()
171    }
172}
173
174impl DeviceProxy {
175    /// Create a new Proxy for fuchsia.hardware.power.sensor/Device.
176    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
177        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
178        Self { client: fidl::client::Client::new(channel, protocol_name) }
179    }
180
181    /// Get a Stream of events from the remote end of the protocol.
182    ///
183    /// # Panics
184    ///
185    /// Panics if the event stream was already taken.
186    pub fn take_event_stream(&self) -> DeviceEventStream {
187        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
188    }
189
190    pub fn r#get_power_watts(
191        &self,
192    ) -> fidl::client::QueryResponseFut<
193        DeviceGetPowerWattsResult,
194        fidl::encoding::DefaultFuchsiaResourceDialect,
195    > {
196        DeviceProxyInterface::r#get_power_watts(self)
197    }
198
199    pub fn r#get_voltage_volts(
200        &self,
201    ) -> fidl::client::QueryResponseFut<
202        DeviceGetVoltageVoltsResult,
203        fidl::encoding::DefaultFuchsiaResourceDialect,
204    > {
205        DeviceProxyInterface::r#get_voltage_volts(self)
206    }
207
208    pub fn r#get_sensor_name(
209        &self,
210    ) -> fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect> {
211        DeviceProxyInterface::r#get_sensor_name(self)
212    }
213}
214
215impl DeviceProxyInterface for DeviceProxy {
216    type GetPowerWattsResponseFut = fidl::client::QueryResponseFut<
217        DeviceGetPowerWattsResult,
218        fidl::encoding::DefaultFuchsiaResourceDialect,
219    >;
220    fn r#get_power_watts(&self) -> Self::GetPowerWattsResponseFut {
221        fn _decode(
222            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
223        ) -> Result<DeviceGetPowerWattsResult, fidl::Error> {
224            let _response = fidl::client::decode_transaction_body::<
225                fidl::encoding::ResultType<DeviceGetPowerWattsResponse, i32>,
226                fidl::encoding::DefaultFuchsiaResourceDialect,
227                0x552bb46982c1957b,
228            >(_buf?)?;
229            Ok(_response.map(|x| x.power))
230        }
231        self.client
232            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetPowerWattsResult>(
233                (),
234                0x552bb46982c1957b,
235                fidl::encoding::DynamicFlags::empty(),
236                _decode,
237            )
238    }
239
240    type GetVoltageVoltsResponseFut = fidl::client::QueryResponseFut<
241        DeviceGetVoltageVoltsResult,
242        fidl::encoding::DefaultFuchsiaResourceDialect,
243    >;
244    fn r#get_voltage_volts(&self) -> Self::GetVoltageVoltsResponseFut {
245        fn _decode(
246            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
247        ) -> Result<DeviceGetVoltageVoltsResult, fidl::Error> {
248            let _response = fidl::client::decode_transaction_body::<
249                fidl::encoding::ResultType<DeviceGetVoltageVoltsResponse, i32>,
250                fidl::encoding::DefaultFuchsiaResourceDialect,
251                0x4b0d0841e3445c37,
252            >(_buf?)?;
253            Ok(_response.map(|x| x.voltage))
254        }
255        self.client
256            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetVoltageVoltsResult>(
257                (),
258                0x4b0d0841e3445c37,
259                fidl::encoding::DynamicFlags::empty(),
260                _decode,
261            )
262    }
263
264    type GetSensorNameResponseFut =
265        fidl::client::QueryResponseFut<String, fidl::encoding::DefaultFuchsiaResourceDialect>;
266    fn r#get_sensor_name(&self) -> Self::GetSensorNameResponseFut {
267        fn _decode(
268            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
269        ) -> Result<String, fidl::Error> {
270            let _response = fidl::client::decode_transaction_body::<
271                DeviceGetSensorNameResponse,
272                fidl::encoding::DefaultFuchsiaResourceDialect,
273                0x3cf646dfaf29b21a,
274            >(_buf?)?;
275            Ok(_response.name)
276        }
277        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, String>(
278            (),
279            0x3cf646dfaf29b21a,
280            fidl::encoding::DynamicFlags::empty(),
281            _decode,
282        )
283    }
284}
285
286pub struct DeviceEventStream {
287    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
288}
289
290impl std::marker::Unpin for DeviceEventStream {}
291
292impl futures::stream::FusedStream for DeviceEventStream {
293    fn is_terminated(&self) -> bool {
294        self.event_receiver.is_terminated()
295    }
296}
297
298impl futures::Stream for DeviceEventStream {
299    type Item = Result<DeviceEvent, fidl::Error>;
300
301    fn poll_next(
302        mut self: std::pin::Pin<&mut Self>,
303        cx: &mut std::task::Context<'_>,
304    ) -> std::task::Poll<Option<Self::Item>> {
305        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
306            &mut self.event_receiver,
307            cx
308        )?) {
309            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
310            None => std::task::Poll::Ready(None),
311        }
312    }
313}
314
315#[derive(Debug)]
316pub enum DeviceEvent {}
317
318impl DeviceEvent {
319    /// Decodes a message buffer as a [`DeviceEvent`].
320    fn decode(
321        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
322    ) -> Result<DeviceEvent, fidl::Error> {
323        let (bytes, _handles) = buf.split_mut();
324        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
325        debug_assert_eq!(tx_header.tx_id, 0);
326        match tx_header.ordinal {
327            _ => Err(fidl::Error::UnknownOrdinal {
328                ordinal: tx_header.ordinal,
329                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
330            }),
331        }
332    }
333}
334
335/// A Stream of incoming requests for fuchsia.hardware.power.sensor/Device.
336pub struct DeviceRequestStream {
337    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
338    is_terminated: bool,
339}
340
341impl std::marker::Unpin for DeviceRequestStream {}
342
343impl futures::stream::FusedStream for DeviceRequestStream {
344    fn is_terminated(&self) -> bool {
345        self.is_terminated
346    }
347}
348
349impl fidl::endpoints::RequestStream for DeviceRequestStream {
350    type Protocol = DeviceMarker;
351    type ControlHandle = DeviceControlHandle;
352
353    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
354        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
355    }
356
357    fn control_handle(&self) -> Self::ControlHandle {
358        DeviceControlHandle { inner: self.inner.clone() }
359    }
360
361    fn into_inner(
362        self,
363    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
364    {
365        (self.inner, self.is_terminated)
366    }
367
368    fn from_inner(
369        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
370        is_terminated: bool,
371    ) -> Self {
372        Self { inner, is_terminated }
373    }
374}
375
376impl futures::Stream for DeviceRequestStream {
377    type Item = Result<DeviceRequest, fidl::Error>;
378
379    fn poll_next(
380        mut self: std::pin::Pin<&mut Self>,
381        cx: &mut std::task::Context<'_>,
382    ) -> std::task::Poll<Option<Self::Item>> {
383        let this = &mut *self;
384        if this.inner.check_shutdown(cx) {
385            this.is_terminated = true;
386            return std::task::Poll::Ready(None);
387        }
388        if this.is_terminated {
389            panic!("polled DeviceRequestStream after completion");
390        }
391        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
392            |bytes, handles| {
393                match this.inner.channel().read_etc(cx, bytes, handles) {
394                    std::task::Poll::Ready(Ok(())) => {}
395                    std::task::Poll::Pending => return std::task::Poll::Pending,
396                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
397                        this.is_terminated = true;
398                        return std::task::Poll::Ready(None);
399                    }
400                    std::task::Poll::Ready(Err(e)) => {
401                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
402                            e.into(),
403                        ))))
404                    }
405                }
406
407                // A message has been received from the channel
408                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
409
410                std::task::Poll::Ready(Some(match header.ordinal {
411                    0x552bb46982c1957b => {
412                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
413                        let mut req = fidl::new_empty!(
414                            fidl::encoding::EmptyPayload,
415                            fidl::encoding::DefaultFuchsiaResourceDialect
416                        );
417                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
418                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
419                        Ok(DeviceRequest::GetPowerWatts {
420                            responder: DeviceGetPowerWattsResponder {
421                                control_handle: std::mem::ManuallyDrop::new(control_handle),
422                                tx_id: header.tx_id,
423                            },
424                        })
425                    }
426                    0x4b0d0841e3445c37 => {
427                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
428                        let mut req = fidl::new_empty!(
429                            fidl::encoding::EmptyPayload,
430                            fidl::encoding::DefaultFuchsiaResourceDialect
431                        );
432                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
433                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
434                        Ok(DeviceRequest::GetVoltageVolts {
435                            responder: DeviceGetVoltageVoltsResponder {
436                                control_handle: std::mem::ManuallyDrop::new(control_handle),
437                                tx_id: header.tx_id,
438                            },
439                        })
440                    }
441                    0x3cf646dfaf29b21a => {
442                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
443                        let mut req = fidl::new_empty!(
444                            fidl::encoding::EmptyPayload,
445                            fidl::encoding::DefaultFuchsiaResourceDialect
446                        );
447                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
448                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
449                        Ok(DeviceRequest::GetSensorName {
450                            responder: DeviceGetSensorNameResponder {
451                                control_handle: std::mem::ManuallyDrop::new(control_handle),
452                                tx_id: header.tx_id,
453                            },
454                        })
455                    }
456                    _ => Err(fidl::Error::UnknownOrdinal {
457                        ordinal: header.ordinal,
458                        protocol_name:
459                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
460                    }),
461                }))
462            },
463        )
464    }
465}
466
467#[derive(Debug)]
468pub enum DeviceRequest {
469    GetPowerWatts { responder: DeviceGetPowerWattsResponder },
470    GetVoltageVolts { responder: DeviceGetVoltageVoltsResponder },
471    GetSensorName { responder: DeviceGetSensorNameResponder },
472}
473
474impl DeviceRequest {
475    #[allow(irrefutable_let_patterns)]
476    pub fn into_get_power_watts(self) -> Option<(DeviceGetPowerWattsResponder)> {
477        if let DeviceRequest::GetPowerWatts { responder } = self {
478            Some((responder))
479        } else {
480            None
481        }
482    }
483
484    #[allow(irrefutable_let_patterns)]
485    pub fn into_get_voltage_volts(self) -> Option<(DeviceGetVoltageVoltsResponder)> {
486        if let DeviceRequest::GetVoltageVolts { responder } = self {
487            Some((responder))
488        } else {
489            None
490        }
491    }
492
493    #[allow(irrefutable_let_patterns)]
494    pub fn into_get_sensor_name(self) -> Option<(DeviceGetSensorNameResponder)> {
495        if let DeviceRequest::GetSensorName { responder } = self {
496            Some((responder))
497        } else {
498            None
499        }
500    }
501
502    /// Name of the method defined in FIDL
503    pub fn method_name(&self) -> &'static str {
504        match *self {
505            DeviceRequest::GetPowerWatts { .. } => "get_power_watts",
506            DeviceRequest::GetVoltageVolts { .. } => "get_voltage_volts",
507            DeviceRequest::GetSensorName { .. } => "get_sensor_name",
508        }
509    }
510}
511
512#[derive(Debug, Clone)]
513pub struct DeviceControlHandle {
514    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
515}
516
517impl fidl::endpoints::ControlHandle for DeviceControlHandle {
518    fn shutdown(&self) {
519        self.inner.shutdown()
520    }
521    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
522        self.inner.shutdown_with_epitaph(status)
523    }
524
525    fn is_closed(&self) -> bool {
526        self.inner.channel().is_closed()
527    }
528    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
529        self.inner.channel().on_closed()
530    }
531
532    #[cfg(target_os = "fuchsia")]
533    fn signal_peer(
534        &self,
535        clear_mask: zx::Signals,
536        set_mask: zx::Signals,
537    ) -> Result<(), zx_status::Status> {
538        use fidl::Peered;
539        self.inner.channel().signal_peer(clear_mask, set_mask)
540    }
541}
542
543impl DeviceControlHandle {}
544
545#[must_use = "FIDL methods require a response to be sent"]
546#[derive(Debug)]
547pub struct DeviceGetPowerWattsResponder {
548    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
549    tx_id: u32,
550}
551
552/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
553/// if the responder is dropped without sending a response, so that the client
554/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
555impl std::ops::Drop for DeviceGetPowerWattsResponder {
556    fn drop(&mut self) {
557        self.control_handle.shutdown();
558        // Safety: drops once, never accessed again
559        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
560    }
561}
562
563impl fidl::endpoints::Responder for DeviceGetPowerWattsResponder {
564    type ControlHandle = DeviceControlHandle;
565
566    fn control_handle(&self) -> &DeviceControlHandle {
567        &self.control_handle
568    }
569
570    fn drop_without_shutdown(mut self) {
571        // Safety: drops once, never accessed again due to mem::forget
572        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
573        // Prevent Drop from running (which would shut down the channel)
574        std::mem::forget(self);
575    }
576}
577
578impl DeviceGetPowerWattsResponder {
579    /// Sends a response to the FIDL transaction.
580    ///
581    /// Sets the channel to shutdown if an error occurs.
582    pub fn send(self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
583        let _result = self.send_raw(result);
584        if _result.is_err() {
585            self.control_handle.shutdown();
586        }
587        self.drop_without_shutdown();
588        _result
589    }
590
591    /// Similar to "send" but does not shutdown the channel if an error occurs.
592    pub fn send_no_shutdown_on_err(self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
593        let _result = self.send_raw(result);
594        self.drop_without_shutdown();
595        _result
596    }
597
598    fn send_raw(&self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
599        self.control_handle
600            .inner
601            .send::<fidl::encoding::ResultType<DeviceGetPowerWattsResponse, i32>>(
602                result.map(|power| (power,)),
603                self.tx_id,
604                0x552bb46982c1957b,
605                fidl::encoding::DynamicFlags::empty(),
606            )
607    }
608}
609
610#[must_use = "FIDL methods require a response to be sent"]
611#[derive(Debug)]
612pub struct DeviceGetVoltageVoltsResponder {
613    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
614    tx_id: u32,
615}
616
617/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
618/// if the responder is dropped without sending a response, so that the client
619/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
620impl std::ops::Drop for DeviceGetVoltageVoltsResponder {
621    fn drop(&mut self) {
622        self.control_handle.shutdown();
623        // Safety: drops once, never accessed again
624        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
625    }
626}
627
628impl fidl::endpoints::Responder for DeviceGetVoltageVoltsResponder {
629    type ControlHandle = DeviceControlHandle;
630
631    fn control_handle(&self) -> &DeviceControlHandle {
632        &self.control_handle
633    }
634
635    fn drop_without_shutdown(mut self) {
636        // Safety: drops once, never accessed again due to mem::forget
637        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
638        // Prevent Drop from running (which would shut down the channel)
639        std::mem::forget(self);
640    }
641}
642
643impl DeviceGetVoltageVoltsResponder {
644    /// Sends a response to the FIDL transaction.
645    ///
646    /// Sets the channel to shutdown if an error occurs.
647    pub fn send(self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
648        let _result = self.send_raw(result);
649        if _result.is_err() {
650            self.control_handle.shutdown();
651        }
652        self.drop_without_shutdown();
653        _result
654    }
655
656    /// Similar to "send" but does not shutdown the channel if an error occurs.
657    pub fn send_no_shutdown_on_err(self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
658        let _result = self.send_raw(result);
659        self.drop_without_shutdown();
660        _result
661    }
662
663    fn send_raw(&self, mut result: Result<f32, i32>) -> Result<(), fidl::Error> {
664        self.control_handle
665            .inner
666            .send::<fidl::encoding::ResultType<DeviceGetVoltageVoltsResponse, i32>>(
667                result.map(|voltage| (voltage,)),
668                self.tx_id,
669                0x4b0d0841e3445c37,
670                fidl::encoding::DynamicFlags::empty(),
671            )
672    }
673}
674
675#[must_use = "FIDL methods require a response to be sent"]
676#[derive(Debug)]
677pub struct DeviceGetSensorNameResponder {
678    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
679    tx_id: u32,
680}
681
682/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
683/// if the responder is dropped without sending a response, so that the client
684/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
685impl std::ops::Drop for DeviceGetSensorNameResponder {
686    fn drop(&mut self) {
687        self.control_handle.shutdown();
688        // Safety: drops once, never accessed again
689        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
690    }
691}
692
693impl fidl::endpoints::Responder for DeviceGetSensorNameResponder {
694    type ControlHandle = DeviceControlHandle;
695
696    fn control_handle(&self) -> &DeviceControlHandle {
697        &self.control_handle
698    }
699
700    fn drop_without_shutdown(mut self) {
701        // Safety: drops once, never accessed again due to mem::forget
702        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
703        // Prevent Drop from running (which would shut down the channel)
704        std::mem::forget(self);
705    }
706}
707
708impl DeviceGetSensorNameResponder {
709    /// Sends a response to the FIDL transaction.
710    ///
711    /// Sets the channel to shutdown if an error occurs.
712    pub fn send(self, mut name: &str) -> Result<(), fidl::Error> {
713        let _result = self.send_raw(name);
714        if _result.is_err() {
715            self.control_handle.shutdown();
716        }
717        self.drop_without_shutdown();
718        _result
719    }
720
721    /// Similar to "send" but does not shutdown the channel if an error occurs.
722    pub fn send_no_shutdown_on_err(self, mut name: &str) -> Result<(), fidl::Error> {
723        let _result = self.send_raw(name);
724        self.drop_without_shutdown();
725        _result
726    }
727
728    fn send_raw(&self, mut name: &str) -> Result<(), fidl::Error> {
729        self.control_handle.inner.send::<DeviceGetSensorNameResponse>(
730            (name,),
731            self.tx_id,
732            0x3cf646dfaf29b21a,
733            fidl::encoding::DynamicFlags::empty(),
734        )
735    }
736}
737
738#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
739pub struct ServiceMarker;
740
741#[cfg(target_os = "fuchsia")]
742impl fidl::endpoints::ServiceMarker for ServiceMarker {
743    type Proxy = ServiceProxy;
744    type Request = ServiceRequest;
745    const SERVICE_NAME: &'static str = "fuchsia.hardware.power.sensor.Service";
746}
747
748/// A request for one of the member protocols of Service.
749///
750#[cfg(target_os = "fuchsia")]
751pub enum ServiceRequest {
752    Device(DeviceRequestStream),
753}
754
755#[cfg(target_os = "fuchsia")]
756impl fidl::endpoints::ServiceRequest for ServiceRequest {
757    type Service = ServiceMarker;
758
759    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
760        match name {
761            "device" => Self::Device(
762                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
763            ),
764            _ => panic!("no such member protocol name for service Service"),
765        }
766    }
767
768    fn member_names() -> &'static [&'static str] {
769        &["device"]
770    }
771}
772#[cfg(target_os = "fuchsia")]
773pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
774
775#[cfg(target_os = "fuchsia")]
776impl fidl::endpoints::ServiceProxy for ServiceProxy {
777    type Service = ServiceMarker;
778
779    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
780        Self(opener)
781    }
782}
783
784#[cfg(target_os = "fuchsia")]
785impl ServiceProxy {
786    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
787        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
788        self.connect_channel_to_device(server_end)?;
789        Ok(proxy)
790    }
791
792    /// Like `connect_to_device`, but returns a sync proxy.
793    /// See [`Self::connect_to_device`] for more details.
794    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
795        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
796        self.connect_channel_to_device(server_end)?;
797        Ok(proxy)
798    }
799
800    /// Like `connect_to_device`, but accepts a server end.
801    /// See [`Self::connect_to_device`] for more details.
802    pub fn connect_channel_to_device(
803        &self,
804        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
805    ) -> Result<(), fidl::Error> {
806        self.0.open_member("device", server_end.into_channel())
807    }
808
809    pub fn instance_name(&self) -> &str {
810        self.0.instance_name()
811    }
812}
813
814mod internal {
815    use super::*;
816}