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#[cfg(target_os = "fuchsia")]
97impl From<CalibratorSynchronousProxy> for zx::NullableHandle {
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 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 pub fn take_event_stream(&self) -> CalibratorEventStream {
153 CalibratorEventStream { event_receiver: self.client.take_event_receiver() }
154 }
155
156 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 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
242pub 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 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#[derive(Debug)]
349pub enum CalibratorRequest {
350 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 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
382 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
383 self.inner.shutdown_with_epitaph(status)
384 }
385
386 fn is_closed(&self) -> bool {
387 self.inner.channel().is_closed()
388 }
389 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
390 self.inner.channel().on_closed()
391 }
392
393 #[cfg(target_os = "fuchsia")]
394 fn signal_peer(
395 &self,
396 clear_mask: zx::Signals,
397 set_mask: zx::Signals,
398 ) -> Result<(), zx_status::Status> {
399 use fidl::Peered;
400 self.inner.channel().signal_peer(clear_mask, set_mask)
401 }
402}
403
404impl CalibratorControlHandle {}
405
406#[must_use = "FIDL methods require a response to be sent"]
407#[derive(Debug)]
408pub struct CalibratorCalibrateResponder {
409 control_handle: std::mem::ManuallyDrop<CalibratorControlHandle>,
410 tx_id: u32,
411}
412
413impl std::ops::Drop for CalibratorCalibrateResponder {
417 fn drop(&mut self) {
418 self.control_handle.shutdown();
419 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
421 }
422}
423
424impl fidl::endpoints::Responder for CalibratorCalibrateResponder {
425 type ControlHandle = CalibratorControlHandle;
426
427 fn control_handle(&self) -> &CalibratorControlHandle {
428 &self.control_handle
429 }
430
431 fn drop_without_shutdown(mut self) {
432 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
434 std::mem::forget(self);
436 }
437}
438
439impl CalibratorCalibrateResponder {
440 pub fn send(self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
444 let _result = self.send_raw(result);
445 if _result.is_err() {
446 self.control_handle.shutdown();
447 }
448 self.drop_without_shutdown();
449 _result
450 }
451
452 pub fn send_no_shutdown_on_err(
454 self,
455 mut result: Result<&Rgbc, Error>,
456 ) -> Result<(), fidl::Error> {
457 let _result = self.send_raw(result);
458 self.drop_without_shutdown();
459 _result
460 }
461
462 fn send_raw(&self, mut result: Result<&Rgbc, Error>) -> Result<(), fidl::Error> {
463 self.control_handle
464 .inner
465 .send::<fidl::encoding::ResultType<CalibratorCalibrateResponse, Error>>(
466 result.map(|data| (data,)),
467 self.tx_id,
468 0x7ddb7eaf88039b02,
469 fidl::encoding::DynamicFlags::empty(),
470 )
471 }
472}
473
474#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
475pub struct SensorMarker;
476
477impl fidl::endpoints::ProtocolMarker for SensorMarker {
478 type Proxy = SensorProxy;
479 type RequestStream = SensorRequestStream;
480 #[cfg(target_os = "fuchsia")]
481 type SynchronousProxy = SensorSynchronousProxy;
482
483 const DEBUG_NAME: &'static str = "fuchsia.lightsensor.Sensor";
484}
485impl fidl::endpoints::DiscoverableProtocolMarker for SensorMarker {}
486
487pub trait SensorProxyInterface: Send + Sync {
488 type WatchResponseFut: std::future::Future<Output = Result<LightSensorData, fidl::Error>> + Send;
489 fn r#watch(&self) -> Self::WatchResponseFut;
490}
491#[derive(Debug)]
492#[cfg(target_os = "fuchsia")]
493pub struct SensorSynchronousProxy {
494 client: fidl::client::sync::Client,
495}
496
497#[cfg(target_os = "fuchsia")]
498impl fidl::endpoints::SynchronousProxy for SensorSynchronousProxy {
499 type Proxy = SensorProxy;
500 type Protocol = SensorMarker;
501
502 fn from_channel(inner: fidl::Channel) -> Self {
503 Self::new(inner)
504 }
505
506 fn into_channel(self) -> fidl::Channel {
507 self.client.into_channel()
508 }
509
510 fn as_channel(&self) -> &fidl::Channel {
511 self.client.as_channel()
512 }
513}
514
515#[cfg(target_os = "fuchsia")]
516impl SensorSynchronousProxy {
517 pub fn new(channel: fidl::Channel) -> Self {
518 let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
519 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
520 }
521
522 pub fn into_channel(self) -> fidl::Channel {
523 self.client.into_channel()
524 }
525
526 pub fn wait_for_event(
529 &self,
530 deadline: zx::MonotonicInstant,
531 ) -> Result<SensorEvent, fidl::Error> {
532 SensorEvent::decode(self.client.wait_for_event(deadline)?)
533 }
534
535 pub fn r#watch(
538 &self,
539 ___deadline: zx::MonotonicInstant,
540 ) -> Result<LightSensorData, fidl::Error> {
541 let _response =
542 self.client.send_query::<fidl::encoding::EmptyPayload, SensorWatchResponse>(
543 (),
544 0x3afa37aef7dc24ff,
545 fidl::encoding::DynamicFlags::empty(),
546 ___deadline,
547 )?;
548 Ok(_response.data)
549 }
550}
551
552#[cfg(target_os = "fuchsia")]
553impl From<SensorSynchronousProxy> for zx::NullableHandle {
554 fn from(value: SensorSynchronousProxy) -> Self {
555 value.into_channel().into()
556 }
557}
558
559#[cfg(target_os = "fuchsia")]
560impl From<fidl::Channel> for SensorSynchronousProxy {
561 fn from(value: fidl::Channel) -> Self {
562 Self::new(value)
563 }
564}
565
566#[cfg(target_os = "fuchsia")]
567impl fidl::endpoints::FromClient for SensorSynchronousProxy {
568 type Protocol = SensorMarker;
569
570 fn from_client(value: fidl::endpoints::ClientEnd<SensorMarker>) -> Self {
571 Self::new(value.into_channel())
572 }
573}
574
575#[derive(Debug, Clone)]
576pub struct SensorProxy {
577 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
578}
579
580impl fidl::endpoints::Proxy for SensorProxy {
581 type Protocol = SensorMarker;
582
583 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
584 Self::new(inner)
585 }
586
587 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
588 self.client.into_channel().map_err(|client| Self { client })
589 }
590
591 fn as_channel(&self) -> &::fidl::AsyncChannel {
592 self.client.as_channel()
593 }
594}
595
596impl SensorProxy {
597 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
599 let protocol_name = <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
600 Self { client: fidl::client::Client::new(channel, protocol_name) }
601 }
602
603 pub fn take_event_stream(&self) -> SensorEventStream {
609 SensorEventStream { event_receiver: self.client.take_event_receiver() }
610 }
611
612 pub fn r#watch(
615 &self,
616 ) -> fidl::client::QueryResponseFut<
617 LightSensorData,
618 fidl::encoding::DefaultFuchsiaResourceDialect,
619 > {
620 SensorProxyInterface::r#watch(self)
621 }
622}
623
624impl SensorProxyInterface for SensorProxy {
625 type WatchResponseFut = fidl::client::QueryResponseFut<
626 LightSensorData,
627 fidl::encoding::DefaultFuchsiaResourceDialect,
628 >;
629 fn r#watch(&self) -> Self::WatchResponseFut {
630 fn _decode(
631 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
632 ) -> Result<LightSensorData, fidl::Error> {
633 let _response = fidl::client::decode_transaction_body::<
634 SensorWatchResponse,
635 fidl::encoding::DefaultFuchsiaResourceDialect,
636 0x3afa37aef7dc24ff,
637 >(_buf?)?;
638 Ok(_response.data)
639 }
640 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, LightSensorData>(
641 (),
642 0x3afa37aef7dc24ff,
643 fidl::encoding::DynamicFlags::empty(),
644 _decode,
645 )
646 }
647}
648
649pub struct SensorEventStream {
650 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
651}
652
653impl std::marker::Unpin for SensorEventStream {}
654
655impl futures::stream::FusedStream for SensorEventStream {
656 fn is_terminated(&self) -> bool {
657 self.event_receiver.is_terminated()
658 }
659}
660
661impl futures::Stream for SensorEventStream {
662 type Item = Result<SensorEvent, fidl::Error>;
663
664 fn poll_next(
665 mut self: std::pin::Pin<&mut Self>,
666 cx: &mut std::task::Context<'_>,
667 ) -> std::task::Poll<Option<Self::Item>> {
668 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
669 &mut self.event_receiver,
670 cx
671 )?) {
672 Some(buf) => std::task::Poll::Ready(Some(SensorEvent::decode(buf))),
673 None => std::task::Poll::Ready(None),
674 }
675 }
676}
677
678#[derive(Debug)]
679pub enum SensorEvent {}
680
681impl SensorEvent {
682 fn decode(
684 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
685 ) -> Result<SensorEvent, fidl::Error> {
686 let (bytes, _handles) = buf.split_mut();
687 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
688 debug_assert_eq!(tx_header.tx_id, 0);
689 match tx_header.ordinal {
690 _ => Err(fidl::Error::UnknownOrdinal {
691 ordinal: tx_header.ordinal,
692 protocol_name: <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
693 }),
694 }
695 }
696}
697
698pub struct SensorRequestStream {
700 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
701 is_terminated: bool,
702}
703
704impl std::marker::Unpin for SensorRequestStream {}
705
706impl futures::stream::FusedStream for SensorRequestStream {
707 fn is_terminated(&self) -> bool {
708 self.is_terminated
709 }
710}
711
712impl fidl::endpoints::RequestStream for SensorRequestStream {
713 type Protocol = SensorMarker;
714 type ControlHandle = SensorControlHandle;
715
716 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
717 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
718 }
719
720 fn control_handle(&self) -> Self::ControlHandle {
721 SensorControlHandle { inner: self.inner.clone() }
722 }
723
724 fn into_inner(
725 self,
726 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
727 {
728 (self.inner, self.is_terminated)
729 }
730
731 fn from_inner(
732 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
733 is_terminated: bool,
734 ) -> Self {
735 Self { inner, is_terminated }
736 }
737}
738
739impl futures::Stream for SensorRequestStream {
740 type Item = Result<SensorRequest, fidl::Error>;
741
742 fn poll_next(
743 mut self: std::pin::Pin<&mut Self>,
744 cx: &mut std::task::Context<'_>,
745 ) -> std::task::Poll<Option<Self::Item>> {
746 let this = &mut *self;
747 if this.inner.check_shutdown(cx) {
748 this.is_terminated = true;
749 return std::task::Poll::Ready(None);
750 }
751 if this.is_terminated {
752 panic!("polled SensorRequestStream after completion");
753 }
754 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
755 |bytes, handles| {
756 match this.inner.channel().read_etc(cx, bytes, handles) {
757 std::task::Poll::Ready(Ok(())) => {}
758 std::task::Poll::Pending => return std::task::Poll::Pending,
759 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
760 this.is_terminated = true;
761 return std::task::Poll::Ready(None);
762 }
763 std::task::Poll::Ready(Err(e)) => {
764 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
765 e.into(),
766 ))));
767 }
768 }
769
770 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
772
773 std::task::Poll::Ready(Some(match header.ordinal {
774 0x3afa37aef7dc24ff => {
775 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
776 let mut req = fidl::new_empty!(
777 fidl::encoding::EmptyPayload,
778 fidl::encoding::DefaultFuchsiaResourceDialect
779 );
780 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
781 let control_handle = SensorControlHandle { inner: this.inner.clone() };
782 Ok(SensorRequest::Watch {
783 responder: SensorWatchResponder {
784 control_handle: std::mem::ManuallyDrop::new(control_handle),
785 tx_id: header.tx_id,
786 },
787 })
788 }
789 _ => Err(fidl::Error::UnknownOrdinal {
790 ordinal: header.ordinal,
791 protocol_name:
792 <SensorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
793 }),
794 }))
795 },
796 )
797 }
798}
799
800#[derive(Debug)]
803pub enum SensorRequest {
804 Watch { responder: SensorWatchResponder },
807}
808
809impl SensorRequest {
810 #[allow(irrefutable_let_patterns)]
811 pub fn into_watch(self) -> Option<(SensorWatchResponder)> {
812 if let SensorRequest::Watch { responder } = self { Some((responder)) } else { None }
813 }
814
815 pub fn method_name(&self) -> &'static str {
817 match *self {
818 SensorRequest::Watch { .. } => "watch",
819 }
820 }
821}
822
823#[derive(Debug, Clone)]
824pub struct SensorControlHandle {
825 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
826}
827
828impl fidl::endpoints::ControlHandle for SensorControlHandle {
829 fn shutdown(&self) {
830 self.inner.shutdown()
831 }
832
833 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
834 self.inner.shutdown_with_epitaph(status)
835 }
836
837 fn is_closed(&self) -> bool {
838 self.inner.channel().is_closed()
839 }
840 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
841 self.inner.channel().on_closed()
842 }
843
844 #[cfg(target_os = "fuchsia")]
845 fn signal_peer(
846 &self,
847 clear_mask: zx::Signals,
848 set_mask: zx::Signals,
849 ) -> Result<(), zx_status::Status> {
850 use fidl::Peered;
851 self.inner.channel().signal_peer(clear_mask, set_mask)
852 }
853}
854
855impl SensorControlHandle {}
856
857#[must_use = "FIDL methods require a response to be sent"]
858#[derive(Debug)]
859pub struct SensorWatchResponder {
860 control_handle: std::mem::ManuallyDrop<SensorControlHandle>,
861 tx_id: u32,
862}
863
864impl std::ops::Drop for SensorWatchResponder {
868 fn drop(&mut self) {
869 self.control_handle.shutdown();
870 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
872 }
873}
874
875impl fidl::endpoints::Responder for SensorWatchResponder {
876 type ControlHandle = SensorControlHandle;
877
878 fn control_handle(&self) -> &SensorControlHandle {
879 &self.control_handle
880 }
881
882 fn drop_without_shutdown(mut self) {
883 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
885 std::mem::forget(self);
887 }
888}
889
890impl SensorWatchResponder {
891 pub fn send(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
895 let _result = self.send_raw(data);
896 if _result.is_err() {
897 self.control_handle.shutdown();
898 }
899 self.drop_without_shutdown();
900 _result
901 }
902
903 pub fn send_no_shutdown_on_err(self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
905 let _result = self.send_raw(data);
906 self.drop_without_shutdown();
907 _result
908 }
909
910 fn send_raw(&self, mut data: &LightSensorData) -> Result<(), fidl::Error> {
911 self.control_handle.inner.send::<SensorWatchResponse>(
912 (data,),
913 self.tx_id,
914 0x3afa37aef7dc24ff,
915 fidl::encoding::DynamicFlags::empty(),
916 )
917 }
918}
919
920mod internal {
921 use super::*;
922}