fidl_fuchsia_lightsensor/
fidl_fuchsia_lightsensor.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_lightsensor__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct CalibratorMarker;
16
17impl fidl::endpoints::ProtocolMarker for CalibratorMarker {
18    type Proxy = CalibratorProxy;
19    type RequestStream = CalibratorRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = CalibratorSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.lightsensor.Calibrator";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for CalibratorMarker {}
26pub type CalibratorCalibrateResult = Result<Rgbc, Error>;
27
28pub trait CalibratorProxyInterface: Send + Sync {
29    type CalibrateResponseFut: std::future::Future<Output = Result<CalibratorCalibrateResult, fidl::Error>>
30        + Send;
31    fn r#calibrate(&self, data: &Rgbc) -> Self::CalibrateResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct CalibratorSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for CalibratorSynchronousProxy {
41    type Proxy = CalibratorProxy;
42    type Protocol = CalibratorMarker;
43
44    fn from_channel(inner: fidl::Channel) -> Self {
45        Self::new(inner)
46    }
47
48    fn into_channel(self) -> fidl::Channel {
49        self.client.into_channel()
50    }
51
52    fn as_channel(&self) -> &fidl::Channel {
53        self.client.as_channel()
54    }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl CalibratorSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name = <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(
71        &self,
72        deadline: zx::MonotonicInstant,
73    ) -> Result<CalibratorEvent, fidl::Error> {
74        CalibratorEvent::decode(self.client.wait_for_event(deadline)?)
75    }
76
77    /// Calibrates the supplied raw [Rgbc] and returns calibrated [Rgbc].
78    pub fn r#calibrate(
79        &self,
80        mut data: &Rgbc,
81        ___deadline: zx::MonotonicInstant,
82    ) -> Result<CalibratorCalibrateResult, fidl::Error> {
83        let _response = self.client.send_query::<
84            CalibratorCalibrateRequest,
85            fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>,
86        >(
87            (data,),
88            0x7ddb7eaf88039b02,
89            fidl::encoding::DynamicFlags::empty(),
90            ___deadline,
91        )?;
92        Ok(_response.map(|x| x.data))
93    }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<CalibratorSynchronousProxy> for zx::Handle {
98    fn from(value: CalibratorSynchronousProxy) -> Self {
99        value.into_channel().into()
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for CalibratorSynchronousProxy {
105    fn from(value: fidl::Channel) -> Self {
106        Self::new(value)
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for CalibratorSynchronousProxy {
112    type Protocol = CalibratorMarker;
113
114    fn from_client(value: fidl::endpoints::ClientEnd<CalibratorMarker>) -> Self {
115        Self::new(value.into_channel())
116    }
117}
118
119#[derive(Debug, Clone)]
120pub struct CalibratorProxy {
121    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for CalibratorProxy {
125    type Protocol = CalibratorMarker;
126
127    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128        Self::new(inner)
129    }
130
131    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132        self.client.into_channel().map_err(|client| Self { client })
133    }
134
135    fn as_channel(&self) -> &::fidl::AsyncChannel {
136        self.client.as_channel()
137    }
138}
139
140impl CalibratorProxy {
141    /// Create a new Proxy for fuchsia.lightsensor/Calibrator.
142    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143        let protocol_name = <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
144        Self { client: fidl::client::Client::new(channel, protocol_name) }
145    }
146
147    /// Get a Stream of events from the remote end of the protocol.
148    ///
149    /// # Panics
150    ///
151    /// Panics if the event stream was already taken.
152    pub fn take_event_stream(&self) -> CalibratorEventStream {
153        CalibratorEventStream { event_receiver: self.client.take_event_receiver() }
154    }
155
156    /// Calibrates the supplied raw [Rgbc] and returns calibrated [Rgbc].
157    pub fn r#calibrate(
158        &self,
159        mut data: &Rgbc,
160    ) -> fidl::client::QueryResponseFut<
161        CalibratorCalibrateResult,
162        fidl::encoding::DefaultFuchsiaResourceDialect,
163    > {
164        CalibratorProxyInterface::r#calibrate(self, data)
165    }
166}
167
168impl CalibratorProxyInterface for CalibratorProxy {
169    type CalibrateResponseFut = fidl::client::QueryResponseFut<
170        CalibratorCalibrateResult,
171        fidl::encoding::DefaultFuchsiaResourceDialect,
172    >;
173    fn r#calibrate(&self, mut data: &Rgbc) -> Self::CalibrateResponseFut {
174        fn _decode(
175            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
176        ) -> Result<CalibratorCalibrateResult, fidl::Error> {
177            let _response = fidl::client::decode_transaction_body::<
178                fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>,
179                fidl::encoding::DefaultFuchsiaResourceDialect,
180                0x7ddb7eaf88039b02,
181            >(_buf?)?;
182            Ok(_response.map(|x| x.data))
183        }
184        self.client.send_query_and_decode::<CalibratorCalibrateRequest, CalibratorCalibrateResult>(
185            (data,),
186            0x7ddb7eaf88039b02,
187            fidl::encoding::DynamicFlags::empty(),
188            _decode,
189        )
190    }
191}
192
193pub struct CalibratorEventStream {
194    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
195}
196
197impl std::marker::Unpin for CalibratorEventStream {}
198
199impl futures::stream::FusedStream for CalibratorEventStream {
200    fn is_terminated(&self) -> bool {
201        self.event_receiver.is_terminated()
202    }
203}
204
205impl futures::Stream for CalibratorEventStream {
206    type Item = Result<CalibratorEvent, fidl::Error>;
207
208    fn poll_next(
209        mut self: std::pin::Pin<&mut Self>,
210        cx: &mut std::task::Context<'_>,
211    ) -> std::task::Poll<Option<Self::Item>> {
212        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
213            &mut self.event_receiver,
214            cx
215        )?) {
216            Some(buf) => std::task::Poll::Ready(Some(CalibratorEvent::decode(buf))),
217            None => std::task::Poll::Ready(None),
218        }
219    }
220}
221
222#[derive(Debug)]
223pub enum CalibratorEvent {}
224
225impl CalibratorEvent {
226    /// Decodes a message buffer as a [`CalibratorEvent`].
227    fn decode(
228        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
229    ) -> Result<CalibratorEvent, fidl::Error> {
230        let (bytes, _handles) = buf.split_mut();
231        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
232        debug_assert_eq!(tx_header.tx_id, 0);
233        match tx_header.ordinal {
234            _ => Err(fidl::Error::UnknownOrdinal {
235                ordinal: tx_header.ordinal,
236                protocol_name: <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
237            }),
238        }
239    }
240}
241
242/// A Stream of incoming requests for fuchsia.lightsensor/Calibrator.
243pub struct CalibratorRequestStream {
244    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
245    is_terminated: bool,
246}
247
248impl std::marker::Unpin for CalibratorRequestStream {}
249
250impl futures::stream::FusedStream for CalibratorRequestStream {
251    fn is_terminated(&self) -> bool {
252        self.is_terminated
253    }
254}
255
256impl fidl::endpoints::RequestStream for CalibratorRequestStream {
257    type Protocol = CalibratorMarker;
258    type ControlHandle = CalibratorControlHandle;
259
260    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
261        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
262    }
263
264    fn control_handle(&self) -> Self::ControlHandle {
265        CalibratorControlHandle { inner: self.inner.clone() }
266    }
267
268    fn into_inner(
269        self,
270    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
271    {
272        (self.inner, self.is_terminated)
273    }
274
275    fn from_inner(
276        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
277        is_terminated: bool,
278    ) -> Self {
279        Self { inner, is_terminated }
280    }
281}
282
283impl futures::Stream for CalibratorRequestStream {
284    type Item = Result<CalibratorRequest, fidl::Error>;
285
286    fn poll_next(
287        mut self: std::pin::Pin<&mut Self>,
288        cx: &mut std::task::Context<'_>,
289    ) -> std::task::Poll<Option<Self::Item>> {
290        let this = &mut *self;
291        if this.inner.check_shutdown(cx) {
292            this.is_terminated = true;
293            return std::task::Poll::Ready(None);
294        }
295        if this.is_terminated {
296            panic!("polled CalibratorRequestStream after completion");
297        }
298        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
299            |bytes, handles| {
300                match this.inner.channel().read_etc(cx, bytes, handles) {
301                    std::task::Poll::Ready(Ok(())) => {}
302                    std::task::Poll::Pending => return std::task::Poll::Pending,
303                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
304                        this.is_terminated = true;
305                        return std::task::Poll::Ready(None);
306                    }
307                    std::task::Poll::Ready(Err(e)) => {
308                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
309                            e.into(),
310                        ))))
311                    }
312                }
313
314                // A message has been received from the channel
315                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
316
317                std::task::Poll::Ready(Some(match header.ordinal {
318                    0x7ddb7eaf88039b02 => {
319                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
320                        let mut req = fidl::new_empty!(
321                            CalibratorCalibrateRequest,
322                            fidl::encoding::DefaultFuchsiaResourceDialect
323                        );
324                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalibratorCalibrateRequest>(&header, _body_bytes, handles, &mut req)?;
325                        let control_handle = CalibratorControlHandle { inner: this.inner.clone() };
326                        Ok(CalibratorRequest::Calibrate {
327                            data: req.data,
328
329                            responder: CalibratorCalibrateResponder {
330                                control_handle: std::mem::ManuallyDrop::new(control_handle),
331                                tx_id: header.tx_id,
332                            },
333                        })
334                    }
335                    _ => Err(fidl::Error::UnknownOrdinal {
336                        ordinal: header.ordinal,
337                        protocol_name:
338                            <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
339                    }),
340                }))
341            },
342        )
343    }
344}
345
346/// `Calibrator` is responsible for calibrating the raw data that comes from the
347/// product-configured light sensor. It is only intended to be used internally.
348#[derive(Debug)]
349pub enum CalibratorRequest {
350    /// Calibrates the supplied raw [Rgbc] and returns calibrated [Rgbc].
351    Calibrate { data: Rgbc, responder: CalibratorCalibrateResponder },
352}
353
354impl CalibratorRequest {
355    #[allow(irrefutable_let_patterns)]
356    pub fn into_calibrate(self) -> Option<(Rgbc, CalibratorCalibrateResponder)> {
357        if let CalibratorRequest::Calibrate { data, responder } = self {
358            Some((data, responder))
359        } else {
360            None
361        }
362    }
363
364    /// Name of the method defined in FIDL
365    pub fn method_name(&self) -> &'static str {
366        match *self {
367            CalibratorRequest::Calibrate { .. } => "calibrate",
368        }
369    }
370}
371
372#[derive(Debug, Clone)]
373pub struct CalibratorControlHandle {
374    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
375}
376
377impl fidl::endpoints::ControlHandle for CalibratorControlHandle {
378    fn shutdown(&self) {
379        self.inner.shutdown()
380    }
381    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
382        self.inner.shutdown_with_epitaph(status)
383    }
384
385    fn is_closed(&self) -> bool {
386        self.inner.channel().is_closed()
387    }
388    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
389        self.inner.channel().on_closed()
390    }
391
392    #[cfg(target_os = "fuchsia")]
393    fn signal_peer(
394        &self,
395        clear_mask: zx::Signals,
396        set_mask: zx::Signals,
397    ) -> Result<(), zx_status::Status> {
398        use fidl::Peered;
399        self.inner.channel().signal_peer(clear_mask, set_mask)
400    }
401}
402
403impl CalibratorControlHandle {}
404
405#[must_use = "FIDL methods require a response to be sent"]
406#[derive(Debug)]
407pub struct CalibratorCalibrateResponder {
408    control_handle: std::mem::ManuallyDrop<CalibratorControlHandle>,
409    tx_id: u32,
410}
411
412/// Set the the channel to be shutdown (see [`CalibratorControlHandle::shutdown`])
413/// if the responder is dropped without sending a response, so that the client
414/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
415impl std::ops::Drop for CalibratorCalibrateResponder {
416    fn drop(&mut self) {
417        self.control_handle.shutdown();
418        // Safety: drops once, never accessed again
419        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
420    }
421}
422
423impl fidl::endpoints::Responder for CalibratorCalibrateResponder {
424    type ControlHandle = CalibratorControlHandle;
425
426    fn control_handle(&self) -> &CalibratorControlHandle {
427        &self.control_handle
428    }
429
430    fn drop_without_shutdown(mut self) {
431        // Safety: drops once, never accessed again due to mem::forget
432        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
433        // Prevent Drop from running (which would shut down the channel)
434        std::mem::forget(self);
435    }
436}
437
438impl CalibratorCalibrateResponder {
439    /// Sends a response to the FIDL transaction.
440    ///
441    /// Sets the channel to shutdown if an error occurs.
442    pub fn send(self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
443        let _result = self.send_raw(result);
444        if _result.is_err() {
445            self.control_handle.shutdown();
446        }
447        self.drop_without_shutdown();
448        _result
449    }
450
451    /// Similar to "send" but does not shutdown the channel if an error occurs.
452    pub fn send_no_shutdown_on_err(
453        self,
454        mut result: Result<&Rgbc, Error>,
455    ) -> Result<(), fidl::Error> {
456        let _result = self.send_raw(result);
457        self.drop_without_shutdown();
458        _result
459    }
460
461    fn send_raw(&self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
462        self.control_handle
463            .inner
464            .send::<fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>>(
465                result.map(|data| (data,)),
466                self.tx_id,
467                0x7ddb7eaf88039b02,
468                fidl::encoding::DynamicFlags::empty(),
469            )
470    }
471}
472
473#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
474pub struct SensorMarker;
475
476impl fidl::endpoints::ProtocolMarker for SensorMarker {
477    type Proxy = SensorProxy;
478    type RequestStream = SensorRequestStream;
479    #[cfg(target_os = "fuchsia")]
480    type SynchronousProxy = SensorSynchronousProxy;
481
482    const DEBUG_NAME: &'static str = "fuchsia.lightsensor.Sensor";
483}
484impl fidl::endpoints::DiscoverableProtocolMarker for SensorMarker {}
485
486pub trait SensorProxyInterface: Send + Sync {
487    type WatchResponseFut: std::future::Future<Output = Result<LightSensorData, fidl::Error>> + Send;
488    fn r#watch(&self) -> Self::WatchResponseFut;
489}
490#[derive(Debug)]
491#[cfg(target_os = "fuchsia")]
492pub struct SensorSynchronousProxy {
493    client: fidl::client::sync::Client,
494}
495
496#[cfg(target_os = "fuchsia")]
497impl fidl::endpoints::SynchronousProxy for SensorSynchronousProxy {
498    type Proxy = SensorProxy;
499    type Protocol = SensorMarker;
500
501    fn from_channel(inner: fidl::Channel) -> Self {
502        Self::new(inner)
503    }
504
505    fn into_channel(self) -> fidl::Channel {
506        self.client.into_channel()
507    }
508
509    fn as_channel(&self) -> &fidl::Channel {
510        self.client.as_channel()
511    }
512}
513
514#[cfg(target_os = "fuchsia")]
515impl SensorSynchronousProxy {
516    pub fn new(channel: fidl::Channel) -> Self {
517        let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
518        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
519    }
520
521    pub fn into_channel(self) -> fidl::Channel {
522        self.client.into_channel()
523    }
524
525    /// Waits until an event arrives and returns it. It is safe for other
526    /// threads to make concurrent requests while waiting for an event.
527    pub fn wait_for_event(
528        &self,
529        deadline: zx::MonotonicInstant,
530    ) -> Result<SensorEvent, fidl::Error> {
531        SensorEvent::decode(self.client.wait_for_event(deadline)?)
532    }
533
534    /// Gets the current [LightSensorData]. Returns immediately on first call;
535    /// subsequent calls return when the value changes.
536    pub fn r#watch(
537        &self,
538        ___deadline: zx::MonotonicInstant,
539    ) -> Result<LightSensorData, fidl::Error> {
540        let _response =
541            self.client.send_query::<fidl::encoding::EmptyPayload, SensorWatchResponse>(
542                (),
543                0x3afa37aef7dc24ff,
544                fidl::encoding::DynamicFlags::empty(),
545                ___deadline,
546            )?;
547        Ok(_response.data)
548    }
549}
550
551#[cfg(target_os = "fuchsia")]
552impl From<SensorSynchronousProxy> for zx::Handle {
553    fn from(value: SensorSynchronousProxy) -> Self {
554        value.into_channel().into()
555    }
556}
557
558#[cfg(target_os = "fuchsia")]
559impl From<fidl::Channel> for SensorSynchronousProxy {
560    fn from(value: fidl::Channel) -> Self {
561        Self::new(value)
562    }
563}
564
565#[cfg(target_os = "fuchsia")]
566impl fidl::endpoints::FromClient for SensorSynchronousProxy {
567    type Protocol = SensorMarker;
568
569    fn from_client(value: fidl::endpoints::ClientEnd<SensorMarker>) -> Self {
570        Self::new(value.into_channel())
571    }
572}
573
574#[derive(Debug, Clone)]
575pub struct SensorProxy {
576    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
577}
578
579impl fidl::endpoints::Proxy for SensorProxy {
580    type Protocol = SensorMarker;
581
582    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
583        Self::new(inner)
584    }
585
586    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
587        self.client.into_channel().map_err(|client| Self { client })
588    }
589
590    fn as_channel(&self) -> &::fidl::AsyncChannel {
591        self.client.as_channel()
592    }
593}
594
595impl SensorProxy {
596    /// Create a new Proxy for fuchsia.lightsensor/Sensor.
597    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
598        let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
599        Self { client: fidl::client::Client::new(channel, protocol_name) }
600    }
601
602    /// Get a Stream of events from the remote end of the protocol.
603    ///
604    /// # Panics
605    ///
606    /// Panics if the event stream was already taken.
607    pub fn take_event_stream(&self) -> SensorEventStream {
608        SensorEventStream { event_receiver: self.client.take_event_receiver() }
609    }
610
611    /// Gets the current [LightSensorData]. Returns immediately on first call;
612    /// subsequent calls return when the value changes.
613    pub fn r#watch(
614        &self,
615    ) -> fidl::client::QueryResponseFut<
616        LightSensorData,
617        fidl::encoding::DefaultFuchsiaResourceDialect,
618    > {
619        SensorProxyInterface::r#watch(self)
620    }
621}
622
623impl SensorProxyInterface for SensorProxy {
624    type WatchResponseFut = fidl::client::QueryResponseFut<
625        LightSensorData,
626        fidl::encoding::DefaultFuchsiaResourceDialect,
627    >;
628    fn r#watch(&self) -> Self::WatchResponseFut {
629        fn _decode(
630            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
631        ) -> Result<LightSensorData, fidl::Error> {
632            let _response = fidl::client::decode_transaction_body::<
633                SensorWatchResponse,
634                fidl::encoding::DefaultFuchsiaResourceDialect,
635                0x3afa37aef7dc24ff,
636            >(_buf?)?;
637            Ok(_response.data)
638        }
639        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, LightSensorData>(
640            (),
641            0x3afa37aef7dc24ff,
642            fidl::encoding::DynamicFlags::empty(),
643            _decode,
644        )
645    }
646}
647
648pub struct SensorEventStream {
649    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
650}
651
652impl std::marker::Unpin for SensorEventStream {}
653
654impl futures::stream::FusedStream for SensorEventStream {
655    fn is_terminated(&self) -> bool {
656        self.event_receiver.is_terminated()
657    }
658}
659
660impl futures::Stream for SensorEventStream {
661    type Item = Result<SensorEvent, fidl::Error>;
662
663    fn poll_next(
664        mut self: std::pin::Pin<&mut Self>,
665        cx: &mut std::task::Context<'_>,
666    ) -> std::task::Poll<Option<Self::Item>> {
667        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
668            &mut self.event_receiver,
669            cx
670        )?) {
671            Some(buf) => std::task::Poll::Ready(Some(SensorEvent::decode(buf))),
672            None => std::task::Poll::Ready(None),
673        }
674    }
675}
676
677#[derive(Debug)]
678pub enum SensorEvent {}
679
680impl SensorEvent {
681    /// Decodes a message buffer as a [`SensorEvent`].
682    fn decode(
683        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
684    ) -> Result<SensorEvent, fidl::Error> {
685        let (bytes, _handles) = buf.split_mut();
686        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
687        debug_assert_eq!(tx_header.tx_id, 0);
688        match tx_header.ordinal {
689            _ => Err(fidl::Error::UnknownOrdinal {
690                ordinal: tx_header.ordinal,
691                protocol_name: <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
692            }),
693        }
694    }
695}
696
697/// A Stream of incoming requests for fuchsia.lightsensor/Sensor.
698pub struct SensorRequestStream {
699    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
700    is_terminated: bool,
701}
702
703impl std::marker::Unpin for SensorRequestStream {}
704
705impl futures::stream::FusedStream for SensorRequestStream {
706    fn is_terminated(&self) -> bool {
707        self.is_terminated
708    }
709}
710
711impl fidl::endpoints::RequestStream for SensorRequestStream {
712    type Protocol = SensorMarker;
713    type ControlHandle = SensorControlHandle;
714
715    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
716        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
717    }
718
719    fn control_handle(&self) -> Self::ControlHandle {
720        SensorControlHandle { inner: self.inner.clone() }
721    }
722
723    fn into_inner(
724        self,
725    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
726    {
727        (self.inner, self.is_terminated)
728    }
729
730    fn from_inner(
731        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
732        is_terminated: bool,
733    ) -> Self {
734        Self { inner, is_terminated }
735    }
736}
737
738impl futures::Stream for SensorRequestStream {
739    type Item = Result<SensorRequest, fidl::Error>;
740
741    fn poll_next(
742        mut self: std::pin::Pin<&mut Self>,
743        cx: &mut std::task::Context<'_>,
744    ) -> std::task::Poll<Option<Self::Item>> {
745        let this = &mut *self;
746        if this.inner.check_shutdown(cx) {
747            this.is_terminated = true;
748            return std::task::Poll::Ready(None);
749        }
750        if this.is_terminated {
751            panic!("polled SensorRequestStream after completion");
752        }
753        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
754            |bytes, handles| {
755                match this.inner.channel().read_etc(cx, bytes, handles) {
756                    std::task::Poll::Ready(Ok(())) => {}
757                    std::task::Poll::Pending => return std::task::Poll::Pending,
758                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
759                        this.is_terminated = true;
760                        return std::task::Poll::Ready(None);
761                    }
762                    std::task::Poll::Ready(Err(e)) => {
763                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
764                            e.into(),
765                        ))))
766                    }
767                }
768
769                // A message has been received from the channel
770                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
771
772                std::task::Poll::Ready(Some(match header.ordinal {
773                    0x3afa37aef7dc24ff => {
774                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
775                        let mut req = fidl::new_empty!(
776                            fidl::encoding::EmptyPayload,
777                            fidl::encoding::DefaultFuchsiaResourceDialect
778                        );
779                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
780                        let control_handle = SensorControlHandle { inner: this.inner.clone() };
781                        Ok(SensorRequest::Watch {
782                            responder: SensorWatchResponder {
783                                control_handle: std::mem::ManuallyDrop::new(control_handle),
784                                tx_id: header.tx_id,
785                            },
786                        })
787                    }
788                    _ => Err(fidl::Error::UnknownOrdinal {
789                        ordinal: header.ordinal,
790                        protocol_name:
791                            <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
792                    }),
793                }))
794            },
795        )
796    }
797}
798
799/// `Sensor` will return calibrated readings from a product-configured light
800/// sensor.
801#[derive(Debug)]
802pub enum SensorRequest {
803    /// Gets the current [LightSensorData]. Returns immediately on first call;
804    /// subsequent calls return when the value changes.
805    Watch { responder: SensorWatchResponder },
806}
807
808impl SensorRequest {
809    #[allow(irrefutable_let_patterns)]
810    pub fn into_watch(self) -> Option<(SensorWatchResponder)> {
811        if let SensorRequest::Watch { responder } = self {
812            Some((responder))
813        } else {
814            None
815        }
816    }
817
818    /// Name of the method defined in FIDL
819    pub fn method_name(&self) -> &'static str {
820        match *self {
821            SensorRequest::Watch { .. } => "watch",
822        }
823    }
824}
825
826#[derive(Debug, Clone)]
827pub struct SensorControlHandle {
828    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
829}
830
831impl fidl::endpoints::ControlHandle for SensorControlHandle {
832    fn shutdown(&self) {
833        self.inner.shutdown()
834    }
835    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
836        self.inner.shutdown_with_epitaph(status)
837    }
838
839    fn is_closed(&self) -> bool {
840        self.inner.channel().is_closed()
841    }
842    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
843        self.inner.channel().on_closed()
844    }
845
846    #[cfg(target_os = "fuchsia")]
847    fn signal_peer(
848        &self,
849        clear_mask: zx::Signals,
850        set_mask: zx::Signals,
851    ) -> Result<(), zx_status::Status> {
852        use fidl::Peered;
853        self.inner.channel().signal_peer(clear_mask, set_mask)
854    }
855}
856
857impl SensorControlHandle {}
858
859#[must_use = "FIDL methods require a response to be sent"]
860#[derive(Debug)]
861pub struct SensorWatchResponder {
862    control_handle: std::mem::ManuallyDrop<SensorControlHandle>,
863    tx_id: u32,
864}
865
866/// Set the the channel to be shutdown (see [`SensorControlHandle::shutdown`])
867/// if the responder is dropped without sending a response, so that the client
868/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
869impl std::ops::Drop for SensorWatchResponder {
870    fn drop(&mut self) {
871        self.control_handle.shutdown();
872        // Safety: drops once, never accessed again
873        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
874    }
875}
876
877impl fidl::endpoints::Responder for SensorWatchResponder {
878    type ControlHandle = SensorControlHandle;
879
880    fn control_handle(&self) -> &SensorControlHandle {
881        &self.control_handle
882    }
883
884    fn drop_without_shutdown(mut self) {
885        // Safety: drops once, never accessed again due to mem::forget
886        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
887        // Prevent Drop from running (which would shut down the channel)
888        std::mem::forget(self);
889    }
890}
891
892impl SensorWatchResponder {
893    /// Sends a response to the FIDL transaction.
894    ///
895    /// Sets the channel to shutdown if an error occurs.
896    pub fn send(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
897        let _result = self.send_raw(data);
898        if _result.is_err() {
899            self.control_handle.shutdown();
900        }
901        self.drop_without_shutdown();
902        _result
903    }
904
905    /// Similar to "send" but does not shutdown the channel if an error occurs.
906    pub fn send_no_shutdown_on_err(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
907        let _result = self.send_raw(data);
908        self.drop_without_shutdown();
909        _result
910    }
911
912    fn send_raw(&self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
913        self.control_handle.inner.send::<SensorWatchResponse>(
914            (data,),
915            self.tx_id,
916            0x3afa37aef7dc24ff,
917            fidl::encoding::DynamicFlags::empty(),
918        )
919    }
920}
921
922mod internal {
923    use super::*;
924}