Skip to main content

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