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