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