Skip to main content

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