1#![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 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 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#[derive(Debug, Clone)]
97pub struct CalibratorProxy {
98 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
99}
100
101impl fidl::endpoints::Proxy for CalibratorProxy {
102 type Protocol = CalibratorMarker;
103
104 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
105 Self::new(inner)
106 }
107
108 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
109 self.client.into_channel().map_err(|client| Self { client })
110 }
111
112 fn as_channel(&self) -> &::fidl::AsyncChannel {
113 self.client.as_channel()
114 }
115}
116
117impl CalibratorProxy {
118 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
120 let protocol_name = <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
121 Self { client: fidl::client::Client::new(channel, protocol_name) }
122 }
123
124 pub fn take_event_stream(&self) -> CalibratorEventStream {
130 CalibratorEventStream { event_receiver: self.client.take_event_receiver() }
131 }
132
133 pub fn r#calibrate(
135 &self,
136 mut data: &Rgbc,
137 ) -> fidl::client::QueryResponseFut<
138 CalibratorCalibrateResult,
139 fidl::encoding::DefaultFuchsiaResourceDialect,
140 > {
141 CalibratorProxyInterface::r#calibrate(self, data)
142 }
143}
144
145impl CalibratorProxyInterface for CalibratorProxy {
146 type CalibrateResponseFut = fidl::client::QueryResponseFut<
147 CalibratorCalibrateResult,
148 fidl::encoding::DefaultFuchsiaResourceDialect,
149 >;
150 fn r#calibrate(&self, mut data: &Rgbc) -> Self::CalibrateResponseFut {
151 fn _decode(
152 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
153 ) -> Result<CalibratorCalibrateResult, fidl::Error> {
154 let _response = fidl::client::decode_transaction_body::<
155 fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>,
156 fidl::encoding::DefaultFuchsiaResourceDialect,
157 0x7ddb7eaf88039b02,
158 >(_buf?)?;
159 Ok(_response.map(|x| x.data))
160 }
161 self.client.send_query_and_decode::<CalibratorCalibrateRequest, CalibratorCalibrateResult>(
162 (data,),
163 0x7ddb7eaf88039b02,
164 fidl::encoding::DynamicFlags::empty(),
165 _decode,
166 )
167 }
168}
169
170pub struct CalibratorEventStream {
171 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
172}
173
174impl std::marker::Unpin for CalibratorEventStream {}
175
176impl futures::stream::FusedStream for CalibratorEventStream {
177 fn is_terminated(&self) -> bool {
178 self.event_receiver.is_terminated()
179 }
180}
181
182impl futures::Stream for CalibratorEventStream {
183 type Item = Result<CalibratorEvent, fidl::Error>;
184
185 fn poll_next(
186 mut self: std::pin::Pin<&mut Self>,
187 cx: &mut std::task::Context<'_>,
188 ) -> std::task::Poll<Option<Self::Item>> {
189 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
190 &mut self.event_receiver,
191 cx
192 )?) {
193 Some(buf) => std::task::Poll::Ready(Some(CalibratorEvent::decode(buf))),
194 None => std::task::Poll::Ready(None),
195 }
196 }
197}
198
199#[derive(Debug)]
200pub enum CalibratorEvent {}
201
202impl CalibratorEvent {
203 fn decode(
205 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
206 ) -> Result<CalibratorEvent, fidl::Error> {
207 let (bytes, _handles) = buf.split_mut();
208 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
209 debug_assert_eq!(tx_header.tx_id, 0);
210 match tx_header.ordinal {
211 _ => Err(fidl::Error::UnknownOrdinal {
212 ordinal: tx_header.ordinal,
213 protocol_name: <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
214 }),
215 }
216 }
217}
218
219pub struct CalibratorRequestStream {
221 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
222 is_terminated: bool,
223}
224
225impl std::marker::Unpin for CalibratorRequestStream {}
226
227impl futures::stream::FusedStream for CalibratorRequestStream {
228 fn is_terminated(&self) -> bool {
229 self.is_terminated
230 }
231}
232
233impl fidl::endpoints::RequestStream for CalibratorRequestStream {
234 type Protocol = CalibratorMarker;
235 type ControlHandle = CalibratorControlHandle;
236
237 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
238 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
239 }
240
241 fn control_handle(&self) -> Self::ControlHandle {
242 CalibratorControlHandle { inner: self.inner.clone() }
243 }
244
245 fn into_inner(
246 self,
247 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
248 {
249 (self.inner, self.is_terminated)
250 }
251
252 fn from_inner(
253 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
254 is_terminated: bool,
255 ) -> Self {
256 Self { inner, is_terminated }
257 }
258}
259
260impl futures::Stream for CalibratorRequestStream {
261 type Item = Result<CalibratorRequest, fidl::Error>;
262
263 fn poll_next(
264 mut self: std::pin::Pin<&mut Self>,
265 cx: &mut std::task::Context<'_>,
266 ) -> std::task::Poll<Option<Self::Item>> {
267 let this = &mut *self;
268 if this.inner.check_shutdown(cx) {
269 this.is_terminated = true;
270 return std::task::Poll::Ready(None);
271 }
272 if this.is_terminated {
273 panic!("polled CalibratorRequestStream after completion");
274 }
275 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
276 |bytes, handles| {
277 match this.inner.channel().read_etc(cx, bytes, handles) {
278 std::task::Poll::Ready(Ok(())) => {}
279 std::task::Poll::Pending => return std::task::Poll::Pending,
280 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
281 this.is_terminated = true;
282 return std::task::Poll::Ready(None);
283 }
284 std::task::Poll::Ready(Err(e)) => {
285 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
286 e.into(),
287 ))))
288 }
289 }
290
291 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
293
294 std::task::Poll::Ready(Some(match header.ordinal {
295 0x7ddb7eaf88039b02 => {
296 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
297 let mut req = fidl::new_empty!(
298 CalibratorCalibrateRequest,
299 fidl::encoding::DefaultFuchsiaResourceDialect
300 );
301 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<CalibratorCalibrateRequest>(&header, _body_bytes, handles, &mut req)?;
302 let control_handle = CalibratorControlHandle { inner: this.inner.clone() };
303 Ok(CalibratorRequest::Calibrate {
304 data: req.data,
305
306 responder: CalibratorCalibrateResponder {
307 control_handle: std::mem::ManuallyDrop::new(control_handle),
308 tx_id: header.tx_id,
309 },
310 })
311 }
312 _ => Err(fidl::Error::UnknownOrdinal {
313 ordinal: header.ordinal,
314 protocol_name:
315 <CalibratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
316 }),
317 }))
318 },
319 )
320 }
321}
322
323#[derive(Debug)]
326pub enum CalibratorRequest {
327 Calibrate { data: Rgbc, responder: CalibratorCalibrateResponder },
329}
330
331impl CalibratorRequest {
332 #[allow(irrefutable_let_patterns)]
333 pub fn into_calibrate(self) -> Option<(Rgbc, CalibratorCalibrateResponder)> {
334 if let CalibratorRequest::Calibrate { data, responder } = self {
335 Some((data, responder))
336 } else {
337 None
338 }
339 }
340
341 pub fn method_name(&self) -> &'static str {
343 match *self {
344 CalibratorRequest::Calibrate { .. } => "calibrate",
345 }
346 }
347}
348
349#[derive(Debug, Clone)]
350pub struct CalibratorControlHandle {
351 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
352}
353
354impl fidl::endpoints::ControlHandle for CalibratorControlHandle {
355 fn shutdown(&self) {
356 self.inner.shutdown()
357 }
358 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
359 self.inner.shutdown_with_epitaph(status)
360 }
361
362 fn is_closed(&self) -> bool {
363 self.inner.channel().is_closed()
364 }
365 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
366 self.inner.channel().on_closed()
367 }
368
369 #[cfg(target_os = "fuchsia")]
370 fn signal_peer(
371 &self,
372 clear_mask: zx::Signals,
373 set_mask: zx::Signals,
374 ) -> Result<(), zx_status::Status> {
375 use fidl::Peered;
376 self.inner.channel().signal_peer(clear_mask, set_mask)
377 }
378}
379
380impl CalibratorControlHandle {}
381
382#[must_use = "FIDL methods require a response to be sent"]
383#[derive(Debug)]
384pub struct CalibratorCalibrateResponder {
385 control_handle: std::mem::ManuallyDrop<CalibratorControlHandle>,
386 tx_id: u32,
387}
388
389impl std::ops::Drop for CalibratorCalibrateResponder {
393 fn drop(&mut self) {
394 self.control_handle.shutdown();
395 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
397 }
398}
399
400impl fidl::endpoints::Responder for CalibratorCalibrateResponder {
401 type ControlHandle = CalibratorControlHandle;
402
403 fn control_handle(&self) -> &CalibratorControlHandle {
404 &self.control_handle
405 }
406
407 fn drop_without_shutdown(mut self) {
408 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
410 std::mem::forget(self);
412 }
413}
414
415impl CalibratorCalibrateResponder {
416 pub fn send(self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
420 let _result = self.send_raw(result);
421 if _result.is_err() {
422 self.control_handle.shutdown();
423 }
424 self.drop_without_shutdown();
425 _result
426 }
427
428 pub fn send_no_shutdown_on_err(
430 self,
431 mut result: Result<&Rgbc, Error>,
432 ) -> Result<(), fidl::Error> {
433 let _result = self.send_raw(result);
434 self.drop_without_shutdown();
435 _result
436 }
437
438 fn send_raw(&self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
439 self.control_handle
440 .inner
441 .send::<fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>>(
442 result.map(|data| (data,)),
443 self.tx_id,
444 0x7ddb7eaf88039b02,
445 fidl::encoding::DynamicFlags::empty(),
446 )
447 }
448}
449
450#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
451pub struct SensorMarker;
452
453impl fidl::endpoints::ProtocolMarker for SensorMarker {
454 type Proxy = SensorProxy;
455 type RequestStream = SensorRequestStream;
456 #[cfg(target_os = "fuchsia")]
457 type SynchronousProxy = SensorSynchronousProxy;
458
459 const DEBUG_NAME: &'static str = "fuchsia.lightsensor.Sensor";
460}
461impl fidl::endpoints::DiscoverableProtocolMarker for SensorMarker {}
462
463pub trait SensorProxyInterface: Send + Sync {
464 type WatchResponseFut: std::future::Future<Output = Result<LightSensorData, fidl::Error>> + Send;
465 fn r#watch(&self) -> Self::WatchResponseFut;
466}
467#[derive(Debug)]
468#[cfg(target_os = "fuchsia")]
469pub struct SensorSynchronousProxy {
470 client: fidl::client::sync::Client,
471}
472
473#[cfg(target_os = "fuchsia")]
474impl fidl::endpoints::SynchronousProxy for SensorSynchronousProxy {
475 type Proxy = SensorProxy;
476 type Protocol = SensorMarker;
477
478 fn from_channel(inner: fidl::Channel) -> Self {
479 Self::new(inner)
480 }
481
482 fn into_channel(self) -> fidl::Channel {
483 self.client.into_channel()
484 }
485
486 fn as_channel(&self) -> &fidl::Channel {
487 self.client.as_channel()
488 }
489}
490
491#[cfg(target_os = "fuchsia")]
492impl SensorSynchronousProxy {
493 pub fn new(channel: fidl::Channel) -> Self {
494 let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
495 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
496 }
497
498 pub fn into_channel(self) -> fidl::Channel {
499 self.client.into_channel()
500 }
501
502 pub fn wait_for_event(
505 &self,
506 deadline: zx::MonotonicInstant,
507 ) -> Result<SensorEvent, fidl::Error> {
508 SensorEvent::decode(self.client.wait_for_event(deadline)?)
509 }
510
511 pub fn r#watch(
514 &self,
515 ___deadline: zx::MonotonicInstant,
516 ) -> Result<LightSensorData, fidl::Error> {
517 let _response =
518 self.client.send_query::<fidl::encoding::EmptyPayload, SensorWatchResponse>(
519 (),
520 0x3afa37aef7dc24ff,
521 fidl::encoding::DynamicFlags::empty(),
522 ___deadline,
523 )?;
524 Ok(_response.data)
525 }
526}
527
528#[derive(Debug, Clone)]
529pub struct SensorProxy {
530 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
531}
532
533impl fidl::endpoints::Proxy for SensorProxy {
534 type Protocol = SensorMarker;
535
536 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
537 Self::new(inner)
538 }
539
540 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
541 self.client.into_channel().map_err(|client| Self { client })
542 }
543
544 fn as_channel(&self) -> &::fidl::AsyncChannel {
545 self.client.as_channel()
546 }
547}
548
549impl SensorProxy {
550 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
552 let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
553 Self { client: fidl::client::Client::new(channel, protocol_name) }
554 }
555
556 pub fn take_event_stream(&self) -> SensorEventStream {
562 SensorEventStream { event_receiver: self.client.take_event_receiver() }
563 }
564
565 pub fn r#watch(
568 &self,
569 ) -> fidl::client::QueryResponseFut<
570 LightSensorData,
571 fidl::encoding::DefaultFuchsiaResourceDialect,
572 > {
573 SensorProxyInterface::r#watch(self)
574 }
575}
576
577impl SensorProxyInterface for SensorProxy {
578 type WatchResponseFut = fidl::client::QueryResponseFut<
579 LightSensorData,
580 fidl::encoding::DefaultFuchsiaResourceDialect,
581 >;
582 fn r#watch(&self) -> Self::WatchResponseFut {
583 fn _decode(
584 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
585 ) -> Result<LightSensorData, fidl::Error> {
586 let _response = fidl::client::decode_transaction_body::<
587 SensorWatchResponse,
588 fidl::encoding::DefaultFuchsiaResourceDialect,
589 0x3afa37aef7dc24ff,
590 >(_buf?)?;
591 Ok(_response.data)
592 }
593 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, LightSensorData>(
594 (),
595 0x3afa37aef7dc24ff,
596 fidl::encoding::DynamicFlags::empty(),
597 _decode,
598 )
599 }
600}
601
602pub struct SensorEventStream {
603 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
604}
605
606impl std::marker::Unpin for SensorEventStream {}
607
608impl futures::stream::FusedStream for SensorEventStream {
609 fn is_terminated(&self) -> bool {
610 self.event_receiver.is_terminated()
611 }
612}
613
614impl futures::Stream for SensorEventStream {
615 type Item = Result<SensorEvent, fidl::Error>;
616
617 fn poll_next(
618 mut self: std::pin::Pin<&mut Self>,
619 cx: &mut std::task::Context<'_>,
620 ) -> std::task::Poll<Option<Self::Item>> {
621 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
622 &mut self.event_receiver,
623 cx
624 )?) {
625 Some(buf) => std::task::Poll::Ready(Some(SensorEvent::decode(buf))),
626 None => std::task::Poll::Ready(None),
627 }
628 }
629}
630
631#[derive(Debug)]
632pub enum SensorEvent {}
633
634impl SensorEvent {
635 fn decode(
637 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
638 ) -> Result<SensorEvent, fidl::Error> {
639 let (bytes, _handles) = buf.split_mut();
640 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
641 debug_assert_eq!(tx_header.tx_id, 0);
642 match tx_header.ordinal {
643 _ => Err(fidl::Error::UnknownOrdinal {
644 ordinal: tx_header.ordinal,
645 protocol_name: <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
646 }),
647 }
648 }
649}
650
651pub struct SensorRequestStream {
653 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
654 is_terminated: bool,
655}
656
657impl std::marker::Unpin for SensorRequestStream {}
658
659impl futures::stream::FusedStream for SensorRequestStream {
660 fn is_terminated(&self) -> bool {
661 self.is_terminated
662 }
663}
664
665impl fidl::endpoints::RequestStream for SensorRequestStream {
666 type Protocol = SensorMarker;
667 type ControlHandle = SensorControlHandle;
668
669 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
670 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
671 }
672
673 fn control_handle(&self) -> Self::ControlHandle {
674 SensorControlHandle { inner: self.inner.clone() }
675 }
676
677 fn into_inner(
678 self,
679 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
680 {
681 (self.inner, self.is_terminated)
682 }
683
684 fn from_inner(
685 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
686 is_terminated: bool,
687 ) -> Self {
688 Self { inner, is_terminated }
689 }
690}
691
692impl futures::Stream for SensorRequestStream {
693 type Item = Result<SensorRequest, fidl::Error>;
694
695 fn poll_next(
696 mut self: std::pin::Pin<&mut Self>,
697 cx: &mut std::task::Context<'_>,
698 ) -> std::task::Poll<Option<Self::Item>> {
699 let this = &mut *self;
700 if this.inner.check_shutdown(cx) {
701 this.is_terminated = true;
702 return std::task::Poll::Ready(None);
703 }
704 if this.is_terminated {
705 panic!("polled SensorRequestStream after completion");
706 }
707 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
708 |bytes, handles| {
709 match this.inner.channel().read_etc(cx, bytes, handles) {
710 std::task::Poll::Ready(Ok(())) => {}
711 std::task::Poll::Pending => return std::task::Poll::Pending,
712 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
713 this.is_terminated = true;
714 return std::task::Poll::Ready(None);
715 }
716 std::task::Poll::Ready(Err(e)) => {
717 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
718 e.into(),
719 ))))
720 }
721 }
722
723 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
725
726 std::task::Poll::Ready(Some(match header.ordinal {
727 0x3afa37aef7dc24ff => {
728 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
729 let mut req = fidl::new_empty!(
730 fidl::encoding::EmptyPayload,
731 fidl::encoding::DefaultFuchsiaResourceDialect
732 );
733 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
734 let control_handle = SensorControlHandle { inner: this.inner.clone() };
735 Ok(SensorRequest::Watch {
736 responder: SensorWatchResponder {
737 control_handle: std::mem::ManuallyDrop::new(control_handle),
738 tx_id: header.tx_id,
739 },
740 })
741 }
742 _ => Err(fidl::Error::UnknownOrdinal {
743 ordinal: header.ordinal,
744 protocol_name:
745 <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
746 }),
747 }))
748 },
749 )
750 }
751}
752
753#[derive(Debug)]
756pub enum SensorRequest {
757 Watch { responder: SensorWatchResponder },
760}
761
762impl SensorRequest {
763 #[allow(irrefutable_let_patterns)]
764 pub fn into_watch(self) -> Option<(SensorWatchResponder)> {
765 if let SensorRequest::Watch { responder } = self {
766 Some((responder))
767 } else {
768 None
769 }
770 }
771
772 pub fn method_name(&self) -> &'static str {
774 match *self {
775 SensorRequest::Watch { .. } => "watch",
776 }
777 }
778}
779
780#[derive(Debug, Clone)]
781pub struct SensorControlHandle {
782 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
783}
784
785impl fidl::endpoints::ControlHandle for SensorControlHandle {
786 fn shutdown(&self) {
787 self.inner.shutdown()
788 }
789 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
790 self.inner.shutdown_with_epitaph(status)
791 }
792
793 fn is_closed(&self) -> bool {
794 self.inner.channel().is_closed()
795 }
796 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
797 self.inner.channel().on_closed()
798 }
799
800 #[cfg(target_os = "fuchsia")]
801 fn signal_peer(
802 &self,
803 clear_mask: zx::Signals,
804 set_mask: zx::Signals,
805 ) -> Result<(), zx_status::Status> {
806 use fidl::Peered;
807 self.inner.channel().signal_peer(clear_mask, set_mask)
808 }
809}
810
811impl SensorControlHandle {}
812
813#[must_use = "FIDL methods require a response to be sent"]
814#[derive(Debug)]
815pub struct SensorWatchResponder {
816 control_handle: std::mem::ManuallyDrop<SensorControlHandle>,
817 tx_id: u32,
818}
819
820impl std::ops::Drop for SensorWatchResponder {
824 fn drop(&mut self) {
825 self.control_handle.shutdown();
826 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
828 }
829}
830
831impl fidl::endpoints::Responder for SensorWatchResponder {
832 type ControlHandle = SensorControlHandle;
833
834 fn control_handle(&self) -> &SensorControlHandle {
835 &self.control_handle
836 }
837
838 fn drop_without_shutdown(mut self) {
839 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
841 std::mem::forget(self);
843 }
844}
845
846impl SensorWatchResponder {
847 pub fn send(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
851 let _result = self.send_raw(data);
852 if _result.is_err() {
853 self.control_handle.shutdown();
854 }
855 self.drop_without_shutdown();
856 _result
857 }
858
859 pub fn send_no_shutdown_on_err(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
861 let _result = self.send_raw(data);
862 self.drop_without_shutdown();
863 _result
864 }
865
866 fn send_raw(&self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
867 self.control_handle.inner.send::<SensorWatchResponse>(
868 (data,),
869 self.tx_id,
870 0x3afa37aef7dc24ff,
871 fidl::encoding::DynamicFlags::empty(),
872 )
873 }
874}
875
876mod internal {
877 use super::*;
878}