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