fidl_fuchsia_hardware_backlight/
fidl_fuchsia_hardware_backlight.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_backlight__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.backlight.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26pub type DeviceGetStateNormalizedResult = Result<State, i32>;
27pub type DeviceSetStateNormalizedResult = Result<(), i32>;
28pub type DeviceGetStateAbsoluteResult = Result<State, i32>;
29pub type DeviceSetStateAbsoluteResult = Result<(), i32>;
30pub type DeviceGetMaxAbsoluteBrightnessResult = Result<f64, i32>;
31
32pub trait DeviceProxyInterface: Send + Sync {
33    type GetStateNormalizedResponseFut: std::future::Future<Output = Result<DeviceGetStateNormalizedResult, fidl::Error>>
34        + Send;
35    fn r#get_state_normalized(&self) -> Self::GetStateNormalizedResponseFut;
36    type SetStateNormalizedResponseFut: std::future::Future<Output = Result<DeviceSetStateNormalizedResult, fidl::Error>>
37        + Send;
38    fn r#set_state_normalized(&self, state: &State) -> Self::SetStateNormalizedResponseFut;
39    type GetStateAbsoluteResponseFut: std::future::Future<Output = Result<DeviceGetStateAbsoluteResult, fidl::Error>>
40        + Send;
41    fn r#get_state_absolute(&self) -> Self::GetStateAbsoluteResponseFut;
42    type SetStateAbsoluteResponseFut: std::future::Future<Output = Result<DeviceSetStateAbsoluteResult, fidl::Error>>
43        + Send;
44    fn r#set_state_absolute(&self, state: &State) -> Self::SetStateAbsoluteResponseFut;
45    type GetMaxAbsoluteBrightnessResponseFut: std::future::Future<Output = Result<DeviceGetMaxAbsoluteBrightnessResult, fidl::Error>>
46        + Send;
47    fn r#get_max_absolute_brightness(&self) -> Self::GetMaxAbsoluteBrightnessResponseFut;
48}
49#[derive(Debug)]
50#[cfg(target_os = "fuchsia")]
51pub struct DeviceSynchronousProxy {
52    client: fidl::client::sync::Client,
53}
54
55#[cfg(target_os = "fuchsia")]
56impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
57    type Proxy = DeviceProxy;
58    type Protocol = DeviceMarker;
59
60    fn from_channel(inner: fidl::Channel) -> Self {
61        Self::new(inner)
62    }
63
64    fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    fn as_channel(&self) -> &fidl::Channel {
69        self.client.as_channel()
70    }
71}
72
73#[cfg(target_os = "fuchsia")]
74impl DeviceSynchronousProxy {
75    pub fn new(channel: fidl::Channel) -> Self {
76        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
77        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
78    }
79
80    pub fn into_channel(self) -> fidl::Channel {
81        self.client.into_channel()
82    }
83
84    /// Waits until an event arrives and returns it. It is safe for other
85    /// threads to make concurrent requests while waiting for an event.
86    pub fn wait_for_event(
87        &self,
88        deadline: zx::MonotonicInstant,
89    ) -> Result<DeviceEvent, fidl::Error> {
90        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
91    }
92
93    /// Gets the current backlight brightness as a percentage value between 0.0
94    /// and 1.0
95    pub fn r#get_state_normalized(
96        &self,
97        ___deadline: zx::MonotonicInstant,
98    ) -> Result<DeviceGetStateNormalizedResult, fidl::Error> {
99        let _response = self.client.send_query::<
100            fidl::encoding::EmptyPayload,
101            fidl::encoding::ResultType<DeviceGetStateNormalizedResponse, i32>,
102        >(
103            (),
104            0x2506201b5999b9b7,
105            fidl::encoding::DynamicFlags::empty(),
106            ___deadline,
107        )?;
108        Ok(_response.map(|x| x.state))
109    }
110
111    /// Sets the current backlight brightness as a percentage value between 0.0
112    /// and 1.0
113    pub fn r#set_state_normalized(
114        &self,
115        mut state: &State,
116        ___deadline: zx::MonotonicInstant,
117    ) -> Result<DeviceSetStateNormalizedResult, fidl::Error> {
118        let _response = self.client.send_query::<
119            DeviceSetStateNormalizedRequest,
120            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
121        >(
122            (state,),
123            0x554ac5cb4f9f5b62,
124            fidl::encoding::DynamicFlags::empty(),
125            ___deadline,
126        )?;
127        Ok(_response.map(|x| x))
128    }
129
130    /// Gets the current backlight brightness in nits
131    pub fn r#get_state_absolute(
132        &self,
133        ___deadline: zx::MonotonicInstant,
134    ) -> Result<DeviceGetStateAbsoluteResult, fidl::Error> {
135        let _response = self.client.send_query::<
136            fidl::encoding::EmptyPayload,
137            fidl::encoding::ResultType<DeviceGetStateAbsoluteResponse, i32>,
138        >(
139            (),
140            0x1f8ccf01cf526a2b,
141            fidl::encoding::DynamicFlags::empty(),
142            ___deadline,
143        )?;
144        Ok(_response.map(|x| x.state))
145    }
146
147    /// Sets the current backlight brightness in nits.
148    pub fn r#set_state_absolute(
149        &self,
150        mut state: &State,
151        ___deadline: zx::MonotonicInstant,
152    ) -> Result<DeviceSetStateAbsoluteResult, fidl::Error> {
153        let _response = self.client.send_query::<
154            DeviceSetStateAbsoluteRequest,
155            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
156        >(
157            (state,),
158            0x19c100c43faaa178,
159            fidl::encoding::DynamicFlags::empty(),
160            ___deadline,
161        )?;
162        Ok(_response.map(|x| x))
163    }
164
165    /// Gets the maximum supported backlight brightness in nits, if known.
166    /// Otherwise returns error ZX_ERR_NOT_SUPPORTED.
167    pub fn r#get_max_absolute_brightness(
168        &self,
169        ___deadline: zx::MonotonicInstant,
170    ) -> Result<DeviceGetMaxAbsoluteBrightnessResult, fidl::Error> {
171        let _response = self.client.send_query::<
172            fidl::encoding::EmptyPayload,
173            fidl::encoding::ResultType<DeviceGetMaxAbsoluteBrightnessResponse, i32>,
174        >(
175            (),
176            0x2aa0699313d4160d,
177            fidl::encoding::DynamicFlags::empty(),
178            ___deadline,
179        )?;
180        Ok(_response.map(|x| x.max_brightness))
181    }
182}
183
184#[cfg(target_os = "fuchsia")]
185impl From<DeviceSynchronousProxy> for zx::NullableHandle {
186    fn from(value: DeviceSynchronousProxy) -> Self {
187        value.into_channel().into()
188    }
189}
190
191#[cfg(target_os = "fuchsia")]
192impl From<fidl::Channel> for DeviceSynchronousProxy {
193    fn from(value: fidl::Channel) -> Self {
194        Self::new(value)
195    }
196}
197
198#[cfg(target_os = "fuchsia")]
199impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
200    type Protocol = DeviceMarker;
201
202    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
203        Self::new(value.into_channel())
204    }
205}
206
207#[derive(Debug, Clone)]
208pub struct DeviceProxy {
209    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
210}
211
212impl fidl::endpoints::Proxy for DeviceProxy {
213    type Protocol = DeviceMarker;
214
215    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
216        Self::new(inner)
217    }
218
219    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
220        self.client.into_channel().map_err(|client| Self { client })
221    }
222
223    fn as_channel(&self) -> &::fidl::AsyncChannel {
224        self.client.as_channel()
225    }
226}
227
228impl DeviceProxy {
229    /// Create a new Proxy for fuchsia.hardware.backlight/Device.
230    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
231        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
232        Self { client: fidl::client::Client::new(channel, protocol_name) }
233    }
234
235    /// Get a Stream of events from the remote end of the protocol.
236    ///
237    /// # Panics
238    ///
239    /// Panics if the event stream was already taken.
240    pub fn take_event_stream(&self) -> DeviceEventStream {
241        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
242    }
243
244    /// Gets the current backlight brightness as a percentage value between 0.0
245    /// and 1.0
246    pub fn r#get_state_normalized(
247        &self,
248    ) -> fidl::client::QueryResponseFut<
249        DeviceGetStateNormalizedResult,
250        fidl::encoding::DefaultFuchsiaResourceDialect,
251    > {
252        DeviceProxyInterface::r#get_state_normalized(self)
253    }
254
255    /// Sets the current backlight brightness as a percentage value between 0.0
256    /// and 1.0
257    pub fn r#set_state_normalized(
258        &self,
259        mut state: &State,
260    ) -> fidl::client::QueryResponseFut<
261        DeviceSetStateNormalizedResult,
262        fidl::encoding::DefaultFuchsiaResourceDialect,
263    > {
264        DeviceProxyInterface::r#set_state_normalized(self, state)
265    }
266
267    /// Gets the current backlight brightness in nits
268    pub fn r#get_state_absolute(
269        &self,
270    ) -> fidl::client::QueryResponseFut<
271        DeviceGetStateAbsoluteResult,
272        fidl::encoding::DefaultFuchsiaResourceDialect,
273    > {
274        DeviceProxyInterface::r#get_state_absolute(self)
275    }
276
277    /// Sets the current backlight brightness in nits.
278    pub fn r#set_state_absolute(
279        &self,
280        mut state: &State,
281    ) -> fidl::client::QueryResponseFut<
282        DeviceSetStateAbsoluteResult,
283        fidl::encoding::DefaultFuchsiaResourceDialect,
284    > {
285        DeviceProxyInterface::r#set_state_absolute(self, state)
286    }
287
288    /// Gets the maximum supported backlight brightness in nits, if known.
289    /// Otherwise returns error ZX_ERR_NOT_SUPPORTED.
290    pub fn r#get_max_absolute_brightness(
291        &self,
292    ) -> fidl::client::QueryResponseFut<
293        DeviceGetMaxAbsoluteBrightnessResult,
294        fidl::encoding::DefaultFuchsiaResourceDialect,
295    > {
296        DeviceProxyInterface::r#get_max_absolute_brightness(self)
297    }
298}
299
300impl DeviceProxyInterface for DeviceProxy {
301    type GetStateNormalizedResponseFut = fidl::client::QueryResponseFut<
302        DeviceGetStateNormalizedResult,
303        fidl::encoding::DefaultFuchsiaResourceDialect,
304    >;
305    fn r#get_state_normalized(&self) -> Self::GetStateNormalizedResponseFut {
306        fn _decode(
307            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
308        ) -> Result<DeviceGetStateNormalizedResult, fidl::Error> {
309            let _response = fidl::client::decode_transaction_body::<
310                fidl::encoding::ResultType<DeviceGetStateNormalizedResponse, i32>,
311                fidl::encoding::DefaultFuchsiaResourceDialect,
312                0x2506201b5999b9b7,
313            >(_buf?)?;
314            Ok(_response.map(|x| x.state))
315        }
316        self.client
317            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetStateNormalizedResult>(
318                (),
319                0x2506201b5999b9b7,
320                fidl::encoding::DynamicFlags::empty(),
321                _decode,
322            )
323    }
324
325    type SetStateNormalizedResponseFut = fidl::client::QueryResponseFut<
326        DeviceSetStateNormalizedResult,
327        fidl::encoding::DefaultFuchsiaResourceDialect,
328    >;
329    fn r#set_state_normalized(&self, mut state: &State) -> Self::SetStateNormalizedResponseFut {
330        fn _decode(
331            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
332        ) -> Result<DeviceSetStateNormalizedResult, fidl::Error> {
333            let _response = fidl::client::decode_transaction_body::<
334                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
335                fidl::encoding::DefaultFuchsiaResourceDialect,
336                0x554ac5cb4f9f5b62,
337            >(_buf?)?;
338            Ok(_response.map(|x| x))
339        }
340        self.client.send_query_and_decode::<
341            DeviceSetStateNormalizedRequest,
342            DeviceSetStateNormalizedResult,
343        >(
344            (state,),
345            0x554ac5cb4f9f5b62,
346            fidl::encoding::DynamicFlags::empty(),
347            _decode,
348        )
349    }
350
351    type GetStateAbsoluteResponseFut = fidl::client::QueryResponseFut<
352        DeviceGetStateAbsoluteResult,
353        fidl::encoding::DefaultFuchsiaResourceDialect,
354    >;
355    fn r#get_state_absolute(&self) -> Self::GetStateAbsoluteResponseFut {
356        fn _decode(
357            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
358        ) -> Result<DeviceGetStateAbsoluteResult, fidl::Error> {
359            let _response = fidl::client::decode_transaction_body::<
360                fidl::encoding::ResultType<DeviceGetStateAbsoluteResponse, i32>,
361                fidl::encoding::DefaultFuchsiaResourceDialect,
362                0x1f8ccf01cf526a2b,
363            >(_buf?)?;
364            Ok(_response.map(|x| x.state))
365        }
366        self.client
367            .send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetStateAbsoluteResult>(
368                (),
369                0x1f8ccf01cf526a2b,
370                fidl::encoding::DynamicFlags::empty(),
371                _decode,
372            )
373    }
374
375    type SetStateAbsoluteResponseFut = fidl::client::QueryResponseFut<
376        DeviceSetStateAbsoluteResult,
377        fidl::encoding::DefaultFuchsiaResourceDialect,
378    >;
379    fn r#set_state_absolute(&self, mut state: &State) -> Self::SetStateAbsoluteResponseFut {
380        fn _decode(
381            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
382        ) -> Result<DeviceSetStateAbsoluteResult, fidl::Error> {
383            let _response = fidl::client::decode_transaction_body::<
384                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
385                fidl::encoding::DefaultFuchsiaResourceDialect,
386                0x19c100c43faaa178,
387            >(_buf?)?;
388            Ok(_response.map(|x| x))
389        }
390        self.client
391            .send_query_and_decode::<DeviceSetStateAbsoluteRequest, DeviceSetStateAbsoluteResult>(
392                (state,),
393                0x19c100c43faaa178,
394                fidl::encoding::DynamicFlags::empty(),
395                _decode,
396            )
397    }
398
399    type GetMaxAbsoluteBrightnessResponseFut = fidl::client::QueryResponseFut<
400        DeviceGetMaxAbsoluteBrightnessResult,
401        fidl::encoding::DefaultFuchsiaResourceDialect,
402    >;
403    fn r#get_max_absolute_brightness(&self) -> Self::GetMaxAbsoluteBrightnessResponseFut {
404        fn _decode(
405            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
406        ) -> Result<DeviceGetMaxAbsoluteBrightnessResult, fidl::Error> {
407            let _response = fidl::client::decode_transaction_body::<
408                fidl::encoding::ResultType<DeviceGetMaxAbsoluteBrightnessResponse, i32>,
409                fidl::encoding::DefaultFuchsiaResourceDialect,
410                0x2aa0699313d4160d,
411            >(_buf?)?;
412            Ok(_response.map(|x| x.max_brightness))
413        }
414        self.client.send_query_and_decode::<
415            fidl::encoding::EmptyPayload,
416            DeviceGetMaxAbsoluteBrightnessResult,
417        >(
418            (),
419            0x2aa0699313d4160d,
420            fidl::encoding::DynamicFlags::empty(),
421            _decode,
422        )
423    }
424}
425
426pub struct DeviceEventStream {
427    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
428}
429
430impl std::marker::Unpin for DeviceEventStream {}
431
432impl futures::stream::FusedStream for DeviceEventStream {
433    fn is_terminated(&self) -> bool {
434        self.event_receiver.is_terminated()
435    }
436}
437
438impl futures::Stream for DeviceEventStream {
439    type Item = Result<DeviceEvent, fidl::Error>;
440
441    fn poll_next(
442        mut self: std::pin::Pin<&mut Self>,
443        cx: &mut std::task::Context<'_>,
444    ) -> std::task::Poll<Option<Self::Item>> {
445        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
446            &mut self.event_receiver,
447            cx
448        )?) {
449            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
450            None => std::task::Poll::Ready(None),
451        }
452    }
453}
454
455#[derive(Debug)]
456pub enum DeviceEvent {}
457
458impl DeviceEvent {
459    /// Decodes a message buffer as a [`DeviceEvent`].
460    fn decode(
461        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
462    ) -> Result<DeviceEvent, fidl::Error> {
463        let (bytes, _handles) = buf.split_mut();
464        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
465        debug_assert_eq!(tx_header.tx_id, 0);
466        match tx_header.ordinal {
467            _ => Err(fidl::Error::UnknownOrdinal {
468                ordinal: tx_header.ordinal,
469                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
470            }),
471        }
472    }
473}
474
475/// A Stream of incoming requests for fuchsia.hardware.backlight/Device.
476pub struct DeviceRequestStream {
477    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
478    is_terminated: bool,
479}
480
481impl std::marker::Unpin for DeviceRequestStream {}
482
483impl futures::stream::FusedStream for DeviceRequestStream {
484    fn is_terminated(&self) -> bool {
485        self.is_terminated
486    }
487}
488
489impl fidl::endpoints::RequestStream for DeviceRequestStream {
490    type Protocol = DeviceMarker;
491    type ControlHandle = DeviceControlHandle;
492
493    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
494        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
495    }
496
497    fn control_handle(&self) -> Self::ControlHandle {
498        DeviceControlHandle { inner: self.inner.clone() }
499    }
500
501    fn into_inner(
502        self,
503    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
504    {
505        (self.inner, self.is_terminated)
506    }
507
508    fn from_inner(
509        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
510        is_terminated: bool,
511    ) -> Self {
512        Self { inner, is_terminated }
513    }
514}
515
516impl futures::Stream for DeviceRequestStream {
517    type Item = Result<DeviceRequest, fidl::Error>;
518
519    fn poll_next(
520        mut self: std::pin::Pin<&mut Self>,
521        cx: &mut std::task::Context<'_>,
522    ) -> std::task::Poll<Option<Self::Item>> {
523        let this = &mut *self;
524        if this.inner.check_shutdown(cx) {
525            this.is_terminated = true;
526            return std::task::Poll::Ready(None);
527        }
528        if this.is_terminated {
529            panic!("polled DeviceRequestStream after completion");
530        }
531        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
532            |bytes, handles| {
533                match this.inner.channel().read_etc(cx, bytes, handles) {
534                    std::task::Poll::Ready(Ok(())) => {}
535                    std::task::Poll::Pending => return std::task::Poll::Pending,
536                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
537                        this.is_terminated = true;
538                        return std::task::Poll::Ready(None);
539                    }
540                    std::task::Poll::Ready(Err(e)) => {
541                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
542                            e.into(),
543                        ))));
544                    }
545                }
546
547                // A message has been received from the channel
548                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
549
550                std::task::Poll::Ready(Some(match header.ordinal {
551                    0x2506201b5999b9b7 => {
552                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
553                        let mut req = fidl::new_empty!(
554                            fidl::encoding::EmptyPayload,
555                            fidl::encoding::DefaultFuchsiaResourceDialect
556                        );
557                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
558                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
559                        Ok(DeviceRequest::GetStateNormalized {
560                            responder: DeviceGetStateNormalizedResponder {
561                                control_handle: std::mem::ManuallyDrop::new(control_handle),
562                                tx_id: header.tx_id,
563                            },
564                        })
565                    }
566                    0x554ac5cb4f9f5b62 => {
567                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
568                        let mut req = fidl::new_empty!(
569                            DeviceSetStateNormalizedRequest,
570                            fidl::encoding::DefaultFuchsiaResourceDialect
571                        );
572                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetStateNormalizedRequest>(&header, _body_bytes, handles, &mut req)?;
573                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
574                        Ok(DeviceRequest::SetStateNormalized {
575                            state: req.state,
576
577                            responder: DeviceSetStateNormalizedResponder {
578                                control_handle: std::mem::ManuallyDrop::new(control_handle),
579                                tx_id: header.tx_id,
580                            },
581                        })
582                    }
583                    0x1f8ccf01cf526a2b => {
584                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
585                        let mut req = fidl::new_empty!(
586                            fidl::encoding::EmptyPayload,
587                            fidl::encoding::DefaultFuchsiaResourceDialect
588                        );
589                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
590                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
591                        Ok(DeviceRequest::GetStateAbsolute {
592                            responder: DeviceGetStateAbsoluteResponder {
593                                control_handle: std::mem::ManuallyDrop::new(control_handle),
594                                tx_id: header.tx_id,
595                            },
596                        })
597                    }
598                    0x19c100c43faaa178 => {
599                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
600                        let mut req = fidl::new_empty!(
601                            DeviceSetStateAbsoluteRequest,
602                            fidl::encoding::DefaultFuchsiaResourceDialect
603                        );
604                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetStateAbsoluteRequest>(&header, _body_bytes, handles, &mut req)?;
605                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
606                        Ok(DeviceRequest::SetStateAbsolute {
607                            state: req.state,
608
609                            responder: DeviceSetStateAbsoluteResponder {
610                                control_handle: std::mem::ManuallyDrop::new(control_handle),
611                                tx_id: header.tx_id,
612                            },
613                        })
614                    }
615                    0x2aa0699313d4160d => {
616                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
617                        let mut req = fidl::new_empty!(
618                            fidl::encoding::EmptyPayload,
619                            fidl::encoding::DefaultFuchsiaResourceDialect
620                        );
621                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
622                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
623                        Ok(DeviceRequest::GetMaxAbsoluteBrightness {
624                            responder: DeviceGetMaxAbsoluteBrightnessResponder {
625                                control_handle: std::mem::ManuallyDrop::new(control_handle),
626                                tx_id: header.tx_id,
627                            },
628                        })
629                    }
630                    _ => Err(fidl::Error::UnknownOrdinal {
631                        ordinal: header.ordinal,
632                        protocol_name:
633                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
634                    }),
635                }))
636            },
637        )
638    }
639}
640
641#[derive(Debug)]
642pub enum DeviceRequest {
643    /// Gets the current backlight brightness as a percentage value between 0.0
644    /// and 1.0
645    GetStateNormalized { responder: DeviceGetStateNormalizedResponder },
646    /// Sets the current backlight brightness as a percentage value between 0.0
647    /// and 1.0
648    SetStateNormalized { state: State, responder: DeviceSetStateNormalizedResponder },
649    /// Gets the current backlight brightness in nits
650    GetStateAbsolute { responder: DeviceGetStateAbsoluteResponder },
651    /// Sets the current backlight brightness in nits.
652    SetStateAbsolute { state: State, responder: DeviceSetStateAbsoluteResponder },
653    /// Gets the maximum supported backlight brightness in nits, if known.
654    /// Otherwise returns error ZX_ERR_NOT_SUPPORTED.
655    GetMaxAbsoluteBrightness { responder: DeviceGetMaxAbsoluteBrightnessResponder },
656}
657
658impl DeviceRequest {
659    #[allow(irrefutable_let_patterns)]
660    pub fn into_get_state_normalized(self) -> Option<(DeviceGetStateNormalizedResponder)> {
661        if let DeviceRequest::GetStateNormalized { responder } = self {
662            Some((responder))
663        } else {
664            None
665        }
666    }
667
668    #[allow(irrefutable_let_patterns)]
669    pub fn into_set_state_normalized(self) -> Option<(State, DeviceSetStateNormalizedResponder)> {
670        if let DeviceRequest::SetStateNormalized { state, responder } = self {
671            Some((state, responder))
672        } else {
673            None
674        }
675    }
676
677    #[allow(irrefutable_let_patterns)]
678    pub fn into_get_state_absolute(self) -> Option<(DeviceGetStateAbsoluteResponder)> {
679        if let DeviceRequest::GetStateAbsolute { responder } = self {
680            Some((responder))
681        } else {
682            None
683        }
684    }
685
686    #[allow(irrefutable_let_patterns)]
687    pub fn into_set_state_absolute(self) -> Option<(State, DeviceSetStateAbsoluteResponder)> {
688        if let DeviceRequest::SetStateAbsolute { state, responder } = self {
689            Some((state, responder))
690        } else {
691            None
692        }
693    }
694
695    #[allow(irrefutable_let_patterns)]
696    pub fn into_get_max_absolute_brightness(
697        self,
698    ) -> Option<(DeviceGetMaxAbsoluteBrightnessResponder)> {
699        if let DeviceRequest::GetMaxAbsoluteBrightness { responder } = self {
700            Some((responder))
701        } else {
702            None
703        }
704    }
705
706    /// Name of the method defined in FIDL
707    pub fn method_name(&self) -> &'static str {
708        match *self {
709            DeviceRequest::GetStateNormalized { .. } => "get_state_normalized",
710            DeviceRequest::SetStateNormalized { .. } => "set_state_normalized",
711            DeviceRequest::GetStateAbsolute { .. } => "get_state_absolute",
712            DeviceRequest::SetStateAbsolute { .. } => "set_state_absolute",
713            DeviceRequest::GetMaxAbsoluteBrightness { .. } => "get_max_absolute_brightness",
714        }
715    }
716}
717
718#[derive(Debug, Clone)]
719pub struct DeviceControlHandle {
720    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
721}
722
723impl fidl::endpoints::ControlHandle for DeviceControlHandle {
724    fn shutdown(&self) {
725        self.inner.shutdown()
726    }
727
728    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
729        self.inner.shutdown_with_epitaph(status)
730    }
731
732    fn is_closed(&self) -> bool {
733        self.inner.channel().is_closed()
734    }
735    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
736        self.inner.channel().on_closed()
737    }
738
739    #[cfg(target_os = "fuchsia")]
740    fn signal_peer(
741        &self,
742        clear_mask: zx::Signals,
743        set_mask: zx::Signals,
744    ) -> Result<(), zx_status::Status> {
745        use fidl::Peered;
746        self.inner.channel().signal_peer(clear_mask, set_mask)
747    }
748}
749
750impl DeviceControlHandle {}
751
752#[must_use = "FIDL methods require a response to be sent"]
753#[derive(Debug)]
754pub struct DeviceGetStateNormalizedResponder {
755    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
756    tx_id: u32,
757}
758
759/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
760/// if the responder is dropped without sending a response, so that the client
761/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
762impl std::ops::Drop for DeviceGetStateNormalizedResponder {
763    fn drop(&mut self) {
764        self.control_handle.shutdown();
765        // Safety: drops once, never accessed again
766        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
767    }
768}
769
770impl fidl::endpoints::Responder for DeviceGetStateNormalizedResponder {
771    type ControlHandle = DeviceControlHandle;
772
773    fn control_handle(&self) -> &DeviceControlHandle {
774        &self.control_handle
775    }
776
777    fn drop_without_shutdown(mut self) {
778        // Safety: drops once, never accessed again due to mem::forget
779        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
780        // Prevent Drop from running (which would shut down the channel)
781        std::mem::forget(self);
782    }
783}
784
785impl DeviceGetStateNormalizedResponder {
786    /// Sends a response to the FIDL transaction.
787    ///
788    /// Sets the channel to shutdown if an error occurs.
789    pub fn send(self, mut result: Result<&State, i32>) -> Result<(), fidl::Error> {
790        let _result = self.send_raw(result);
791        if _result.is_err() {
792            self.control_handle.shutdown();
793        }
794        self.drop_without_shutdown();
795        _result
796    }
797
798    /// Similar to "send" but does not shutdown the channel if an error occurs.
799    pub fn send_no_shutdown_on_err(
800        self,
801        mut result: Result<&State, i32>,
802    ) -> Result<(), fidl::Error> {
803        let _result = self.send_raw(result);
804        self.drop_without_shutdown();
805        _result
806    }
807
808    fn send_raw(&self, mut result: Result<&State, i32>) -> Result<(), fidl::Error> {
809        self.control_handle
810            .inner
811            .send::<fidl::encoding::ResultType<DeviceGetStateNormalizedResponse, i32>>(
812                result.map(|state| (state,)),
813                self.tx_id,
814                0x2506201b5999b9b7,
815                fidl::encoding::DynamicFlags::empty(),
816            )
817    }
818}
819
820#[must_use = "FIDL methods require a response to be sent"]
821#[derive(Debug)]
822pub struct DeviceSetStateNormalizedResponder {
823    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
824    tx_id: u32,
825}
826
827/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
828/// if the responder is dropped without sending a response, so that the client
829/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
830impl std::ops::Drop for DeviceSetStateNormalizedResponder {
831    fn drop(&mut self) {
832        self.control_handle.shutdown();
833        // Safety: drops once, never accessed again
834        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
835    }
836}
837
838impl fidl::endpoints::Responder for DeviceSetStateNormalizedResponder {
839    type ControlHandle = DeviceControlHandle;
840
841    fn control_handle(&self) -> &DeviceControlHandle {
842        &self.control_handle
843    }
844
845    fn drop_without_shutdown(mut self) {
846        // Safety: drops once, never accessed again due to mem::forget
847        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
848        // Prevent Drop from running (which would shut down the channel)
849        std::mem::forget(self);
850    }
851}
852
853impl DeviceSetStateNormalizedResponder {
854    /// Sends a response to the FIDL transaction.
855    ///
856    /// Sets the channel to shutdown if an error occurs.
857    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
858        let _result = self.send_raw(result);
859        if _result.is_err() {
860            self.control_handle.shutdown();
861        }
862        self.drop_without_shutdown();
863        _result
864    }
865
866    /// Similar to "send" but does not shutdown the channel if an error occurs.
867    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
868        let _result = self.send_raw(result);
869        self.drop_without_shutdown();
870        _result
871    }
872
873    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
874        self.control_handle
875            .inner
876            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
877                result,
878                self.tx_id,
879                0x554ac5cb4f9f5b62,
880                fidl::encoding::DynamicFlags::empty(),
881            )
882    }
883}
884
885#[must_use = "FIDL methods require a response to be sent"]
886#[derive(Debug)]
887pub struct DeviceGetStateAbsoluteResponder {
888    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
889    tx_id: u32,
890}
891
892/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
893/// if the responder is dropped without sending a response, so that the client
894/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
895impl std::ops::Drop for DeviceGetStateAbsoluteResponder {
896    fn drop(&mut self) {
897        self.control_handle.shutdown();
898        // Safety: drops once, never accessed again
899        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
900    }
901}
902
903impl fidl::endpoints::Responder for DeviceGetStateAbsoluteResponder {
904    type ControlHandle = DeviceControlHandle;
905
906    fn control_handle(&self) -> &DeviceControlHandle {
907        &self.control_handle
908    }
909
910    fn drop_without_shutdown(mut self) {
911        // Safety: drops once, never accessed again due to mem::forget
912        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
913        // Prevent Drop from running (which would shut down the channel)
914        std::mem::forget(self);
915    }
916}
917
918impl DeviceGetStateAbsoluteResponder {
919    /// Sends a response to the FIDL transaction.
920    ///
921    /// Sets the channel to shutdown if an error occurs.
922    pub fn send(self, mut result: Result<&State, i32>) -> Result<(), fidl::Error> {
923        let _result = self.send_raw(result);
924        if _result.is_err() {
925            self.control_handle.shutdown();
926        }
927        self.drop_without_shutdown();
928        _result
929    }
930
931    /// Similar to "send" but does not shutdown the channel if an error occurs.
932    pub fn send_no_shutdown_on_err(
933        self,
934        mut result: Result<&State, i32>,
935    ) -> Result<(), fidl::Error> {
936        let _result = self.send_raw(result);
937        self.drop_without_shutdown();
938        _result
939    }
940
941    fn send_raw(&self, mut result: Result<&State, i32>) -> Result<(), fidl::Error> {
942        self.control_handle
943            .inner
944            .send::<fidl::encoding::ResultType<DeviceGetStateAbsoluteResponse, i32>>(
945                result.map(|state| (state,)),
946                self.tx_id,
947                0x1f8ccf01cf526a2b,
948                fidl::encoding::DynamicFlags::empty(),
949            )
950    }
951}
952
953#[must_use = "FIDL methods require a response to be sent"]
954#[derive(Debug)]
955pub struct DeviceSetStateAbsoluteResponder {
956    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
957    tx_id: u32,
958}
959
960/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
961/// if the responder is dropped without sending a response, so that the client
962/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
963impl std::ops::Drop for DeviceSetStateAbsoluteResponder {
964    fn drop(&mut self) {
965        self.control_handle.shutdown();
966        // Safety: drops once, never accessed again
967        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
968    }
969}
970
971impl fidl::endpoints::Responder for DeviceSetStateAbsoluteResponder {
972    type ControlHandle = DeviceControlHandle;
973
974    fn control_handle(&self) -> &DeviceControlHandle {
975        &self.control_handle
976    }
977
978    fn drop_without_shutdown(mut self) {
979        // Safety: drops once, never accessed again due to mem::forget
980        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
981        // Prevent Drop from running (which would shut down the channel)
982        std::mem::forget(self);
983    }
984}
985
986impl DeviceSetStateAbsoluteResponder {
987    /// Sends a response to the FIDL transaction.
988    ///
989    /// Sets the channel to shutdown if an error occurs.
990    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
991        let _result = self.send_raw(result);
992        if _result.is_err() {
993            self.control_handle.shutdown();
994        }
995        self.drop_without_shutdown();
996        _result
997    }
998
999    /// Similar to "send" but does not shutdown the channel if an error occurs.
1000    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1001        let _result = self.send_raw(result);
1002        self.drop_without_shutdown();
1003        _result
1004    }
1005
1006    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1007        self.control_handle
1008            .inner
1009            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1010                result,
1011                self.tx_id,
1012                0x19c100c43faaa178,
1013                fidl::encoding::DynamicFlags::empty(),
1014            )
1015    }
1016}
1017
1018#[must_use = "FIDL methods require a response to be sent"]
1019#[derive(Debug)]
1020pub struct DeviceGetMaxAbsoluteBrightnessResponder {
1021    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1022    tx_id: u32,
1023}
1024
1025/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1026/// if the responder is dropped without sending a response, so that the client
1027/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1028impl std::ops::Drop for DeviceGetMaxAbsoluteBrightnessResponder {
1029    fn drop(&mut self) {
1030        self.control_handle.shutdown();
1031        // Safety: drops once, never accessed again
1032        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1033    }
1034}
1035
1036impl fidl::endpoints::Responder for DeviceGetMaxAbsoluteBrightnessResponder {
1037    type ControlHandle = DeviceControlHandle;
1038
1039    fn control_handle(&self) -> &DeviceControlHandle {
1040        &self.control_handle
1041    }
1042
1043    fn drop_without_shutdown(mut self) {
1044        // Safety: drops once, never accessed again due to mem::forget
1045        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1046        // Prevent Drop from running (which would shut down the channel)
1047        std::mem::forget(self);
1048    }
1049}
1050
1051impl DeviceGetMaxAbsoluteBrightnessResponder {
1052    /// Sends a response to the FIDL transaction.
1053    ///
1054    /// Sets the channel to shutdown if an error occurs.
1055    pub fn send(self, mut result: Result<f64, i32>) -> Result<(), fidl::Error> {
1056        let _result = self.send_raw(result);
1057        if _result.is_err() {
1058            self.control_handle.shutdown();
1059        }
1060        self.drop_without_shutdown();
1061        _result
1062    }
1063
1064    /// Similar to "send" but does not shutdown the channel if an error occurs.
1065    pub fn send_no_shutdown_on_err(self, mut result: Result<f64, i32>) -> Result<(), fidl::Error> {
1066        let _result = self.send_raw(result);
1067        self.drop_without_shutdown();
1068        _result
1069    }
1070
1071    fn send_raw(&self, mut result: Result<f64, i32>) -> Result<(), fidl::Error> {
1072        self.control_handle.inner.send::<fidl::encoding::ResultType<
1073            DeviceGetMaxAbsoluteBrightnessResponse,
1074            i32,
1075        >>(
1076            result.map(|max_brightness| (max_brightness,)),
1077            self.tx_id,
1078            0x2aa0699313d4160d,
1079            fidl::encoding::DynamicFlags::empty(),
1080        )
1081    }
1082}
1083
1084#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1085pub struct ServiceMarker;
1086
1087#[cfg(target_os = "fuchsia")]
1088impl fidl::endpoints::ServiceMarker for ServiceMarker {
1089    type Proxy = ServiceProxy;
1090    type Request = ServiceRequest;
1091    const SERVICE_NAME: &'static str = "fuchsia.hardware.backlight.Service";
1092}
1093
1094/// A request for one of the member protocols of Service.
1095///
1096#[cfg(target_os = "fuchsia")]
1097pub enum ServiceRequest {
1098    Backlight(DeviceRequestStream),
1099}
1100
1101#[cfg(target_os = "fuchsia")]
1102impl fidl::endpoints::ServiceRequest for ServiceRequest {
1103    type Service = ServiceMarker;
1104
1105    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1106        match name {
1107            "backlight" => Self::Backlight(
1108                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1109            ),
1110            _ => panic!("no such member protocol name for service Service"),
1111        }
1112    }
1113
1114    fn member_names() -> &'static [&'static str] {
1115        &["backlight"]
1116    }
1117}
1118#[cfg(target_os = "fuchsia")]
1119pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1120
1121#[cfg(target_os = "fuchsia")]
1122impl fidl::endpoints::ServiceProxy for ServiceProxy {
1123    type Service = ServiceMarker;
1124
1125    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1126        Self(opener)
1127    }
1128}
1129
1130#[cfg(target_os = "fuchsia")]
1131impl ServiceProxy {
1132    pub fn connect_to_backlight(&self) -> Result<DeviceProxy, fidl::Error> {
1133        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
1134        self.connect_channel_to_backlight(server_end)?;
1135        Ok(proxy)
1136    }
1137
1138    /// Like `connect_to_backlight`, but returns a sync proxy.
1139    /// See [`Self::connect_to_backlight`] for more details.
1140    pub fn connect_to_backlight_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
1141        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
1142        self.connect_channel_to_backlight(server_end)?;
1143        Ok(proxy)
1144    }
1145
1146    /// Like `connect_to_backlight`, but accepts a server end.
1147    /// See [`Self::connect_to_backlight`] for more details.
1148    pub fn connect_channel_to_backlight(
1149        &self,
1150        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
1151    ) -> Result<(), fidl::Error> {
1152        self.0.open_member("backlight", server_end.into_channel())
1153    }
1154
1155    pub fn instance_name(&self) -> &str {
1156        self.0.instance_name()
1157    }
1158}
1159
1160mod internal {
1161    use super::*;
1162}