fidl_fuchsia_hardware_sensors/
fidl_fuchsia_hardware_sensors.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_hardware_sensors__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DriverMarker;
16
17impl fidl::endpoints::ProtocolMarker for DriverMarker {
18    type Proxy = DriverProxy;
19    type RequestStream = DriverRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DriverSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.hardware.sensors.Driver";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DriverMarker {}
26pub type DriverActivateSensorResult = Result<(), ActivateSensorError>;
27pub type DriverDeactivateSensorResult = Result<(), DeactivateSensorError>;
28pub type DriverConfigureSensorRateResult = Result<(), ConfigureSensorRateError>;
29
30pub trait DriverProxyInterface: Send + Sync {
31    type GetSensorsListResponseFut: std::future::Future<
32            Output = Result<Vec<fidl_fuchsia_sensors_types::SensorInfo>, fidl::Error>,
33        > + Send;
34    fn r#get_sensors_list(&self) -> Self::GetSensorsListResponseFut;
35    type ActivateSensorResponseFut: std::future::Future<Output = Result<DriverActivateSensorResult, fidl::Error>>
36        + Send;
37    fn r#activate_sensor(&self, sensor_id: i32) -> Self::ActivateSensorResponseFut;
38    type DeactivateSensorResponseFut: std::future::Future<Output = Result<DriverDeactivateSensorResult, fidl::Error>>
39        + Send;
40    fn r#deactivate_sensor(&self, sensor_id: i32) -> Self::DeactivateSensorResponseFut;
41    type ConfigureSensorRateResponseFut: std::future::Future<Output = Result<DriverConfigureSensorRateResult, fidl::Error>>
42        + Send;
43    fn r#configure_sensor_rate(
44        &self,
45        sensor_id: i32,
46        sensor_rate_config: &fidl_fuchsia_sensors_types::SensorRateConfig,
47    ) -> Self::ConfigureSensorRateResponseFut;
48}
49#[derive(Debug)]
50#[cfg(target_os = "fuchsia")]
51pub struct DriverSynchronousProxy {
52    client: fidl::client::sync::Client,
53}
54
55#[cfg(target_os = "fuchsia")]
56impl fidl::endpoints::SynchronousProxy for DriverSynchronousProxy {
57    type Proxy = DriverProxy;
58    type Protocol = DriverMarker;
59
60    fn from_channel(inner: fidl::Channel) -> Self {
61        Self::new(inner)
62    }
63
64    fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    fn as_channel(&self) -> &fidl::Channel {
69        self.client.as_channel()
70    }
71}
72
73#[cfg(target_os = "fuchsia")]
74impl DriverSynchronousProxy {
75    pub fn new(channel: fidl::Channel) -> Self {
76        let protocol_name = <DriverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
77        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
78    }
79
80    pub fn into_channel(self) -> fidl::Channel {
81        self.client.into_channel()
82    }
83
84    /// Waits until an event arrives and returns it. It is safe for other
85    /// threads to make concurrent requests while waiting for an event.
86    pub fn wait_for_event(
87        &self,
88        deadline: zx::MonotonicInstant,
89    ) -> Result<DriverEvent, fidl::Error> {
90        DriverEvent::decode(self.client.wait_for_event(deadline)?)
91    }
92
93    /// Retrieve the details of all the sensors managed by this driver.
94    pub fn r#get_sensors_list(
95        &self,
96        ___deadline: zx::MonotonicInstant,
97    ) -> Result<Vec<fidl_fuchsia_sensors_types::SensorInfo>, fidl::Error> {
98        let _response = self.client.send_query::<
99            fidl::encoding::EmptyPayload,
100            fidl::encoding::FlexibleType<DriverGetSensorsListResponse>,
101        >(
102            (),
103            0x6a30da06929d426b,
104            fidl::encoding::DynamicFlags::FLEXIBLE,
105            ___deadline,
106        )?
107        .into_result::<DriverMarker>("get_sensors_list")?;
108        Ok(_response.sensor_list)
109    }
110
111    /// Activate the specified sensor.
112    pub fn r#activate_sensor(
113        &self,
114        mut sensor_id: i32,
115        ___deadline: zx::MonotonicInstant,
116    ) -> Result<DriverActivateSensorResult, fidl::Error> {
117        let _response =
118            self.client
119                .send_query::<DriverActivateSensorRequest, fidl::encoding::FlexibleResultType<
120                    fidl::encoding::EmptyStruct,
121                    ActivateSensorError,
122                >>(
123                    (sensor_id,),
124                    0x6ff16c620f9f3c5b,
125                    fidl::encoding::DynamicFlags::FLEXIBLE,
126                    ___deadline,
127                )?
128                .into_result::<DriverMarker>("activate_sensor")?;
129        Ok(_response.map(|x| x))
130    }
131
132    /// Deactivate the specified sensor.
133    pub fn r#deactivate_sensor(
134        &self,
135        mut sensor_id: i32,
136        ___deadline: zx::MonotonicInstant,
137    ) -> Result<DriverDeactivateSensorResult, fidl::Error> {
138        let _response =
139            self.client
140                .send_query::<DriverDeactivateSensorRequest, fidl::encoding::FlexibleResultType<
141                    fidl::encoding::EmptyStruct,
142                    DeactivateSensorError,
143                >>(
144                    (sensor_id,),
145                    0x64f003527d44ec55,
146                    fidl::encoding::DynamicFlags::FLEXIBLE,
147                    ___deadline,
148                )?
149                .into_result::<DriverMarker>("deactivate_sensor")?;
150        Ok(_response.map(|x| x))
151    }
152
153    /// Set the output rate for the specified sensor.
154    pub fn r#configure_sensor_rate(
155        &self,
156        mut sensor_id: i32,
157        mut sensor_rate_config: &fidl_fuchsia_sensors_types::SensorRateConfig,
158        ___deadline: zx::MonotonicInstant,
159    ) -> Result<DriverConfigureSensorRateResult, fidl::Error> {
160        let _response = self
161            .client
162            .send_query::<DriverConfigureSensorRateRequest, fidl::encoding::FlexibleResultType<
163                fidl::encoding::EmptyStruct,
164                ConfigureSensorRateError,
165            >>(
166                (sensor_id, sensor_rate_config),
167                0x78a264bc9c645045,
168                fidl::encoding::DynamicFlags::FLEXIBLE,
169                ___deadline,
170            )?
171            .into_result::<DriverMarker>("configure_sensor_rate")?;
172        Ok(_response.map(|x| x))
173    }
174}
175
176#[cfg(target_os = "fuchsia")]
177impl From<DriverSynchronousProxy> for zx::NullableHandle {
178    fn from(value: DriverSynchronousProxy) -> Self {
179        value.into_channel().into()
180    }
181}
182
183#[cfg(target_os = "fuchsia")]
184impl From<fidl::Channel> for DriverSynchronousProxy {
185    fn from(value: fidl::Channel) -> Self {
186        Self::new(value)
187    }
188}
189
190#[cfg(target_os = "fuchsia")]
191impl fidl::endpoints::FromClient for DriverSynchronousProxy {
192    type Protocol = DriverMarker;
193
194    fn from_client(value: fidl::endpoints::ClientEnd<DriverMarker>) -> Self {
195        Self::new(value.into_channel())
196    }
197}
198
199#[derive(Debug, Clone)]
200pub struct DriverProxy {
201    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
202}
203
204impl fidl::endpoints::Proxy for DriverProxy {
205    type Protocol = DriverMarker;
206
207    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
208        Self::new(inner)
209    }
210
211    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
212        self.client.into_channel().map_err(|client| Self { client })
213    }
214
215    fn as_channel(&self) -> &::fidl::AsyncChannel {
216        self.client.as_channel()
217    }
218}
219
220impl DriverProxy {
221    /// Create a new Proxy for fuchsia.hardware.sensors/Driver.
222    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
223        let protocol_name = <DriverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
224        Self { client: fidl::client::Client::new(channel, protocol_name) }
225    }
226
227    /// Get a Stream of events from the remote end of the protocol.
228    ///
229    /// # Panics
230    ///
231    /// Panics if the event stream was already taken.
232    pub fn take_event_stream(&self) -> DriverEventStream {
233        DriverEventStream { event_receiver: self.client.take_event_receiver() }
234    }
235
236    /// Retrieve the details of all the sensors managed by this driver.
237    pub fn r#get_sensors_list(
238        &self,
239    ) -> fidl::client::QueryResponseFut<
240        Vec<fidl_fuchsia_sensors_types::SensorInfo>,
241        fidl::encoding::DefaultFuchsiaResourceDialect,
242    > {
243        DriverProxyInterface::r#get_sensors_list(self)
244    }
245
246    /// Activate the specified sensor.
247    pub fn r#activate_sensor(
248        &self,
249        mut sensor_id: i32,
250    ) -> fidl::client::QueryResponseFut<
251        DriverActivateSensorResult,
252        fidl::encoding::DefaultFuchsiaResourceDialect,
253    > {
254        DriverProxyInterface::r#activate_sensor(self, sensor_id)
255    }
256
257    /// Deactivate the specified sensor.
258    pub fn r#deactivate_sensor(
259        &self,
260        mut sensor_id: i32,
261    ) -> fidl::client::QueryResponseFut<
262        DriverDeactivateSensorResult,
263        fidl::encoding::DefaultFuchsiaResourceDialect,
264    > {
265        DriverProxyInterface::r#deactivate_sensor(self, sensor_id)
266    }
267
268    /// Set the output rate for the specified sensor.
269    pub fn r#configure_sensor_rate(
270        &self,
271        mut sensor_id: i32,
272        mut sensor_rate_config: &fidl_fuchsia_sensors_types::SensorRateConfig,
273    ) -> fidl::client::QueryResponseFut<
274        DriverConfigureSensorRateResult,
275        fidl::encoding::DefaultFuchsiaResourceDialect,
276    > {
277        DriverProxyInterface::r#configure_sensor_rate(self, sensor_id, sensor_rate_config)
278    }
279}
280
281impl DriverProxyInterface for DriverProxy {
282    type GetSensorsListResponseFut = fidl::client::QueryResponseFut<
283        Vec<fidl_fuchsia_sensors_types::SensorInfo>,
284        fidl::encoding::DefaultFuchsiaResourceDialect,
285    >;
286    fn r#get_sensors_list(&self) -> Self::GetSensorsListResponseFut {
287        fn _decode(
288            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
289        ) -> Result<Vec<fidl_fuchsia_sensors_types::SensorInfo>, fidl::Error> {
290            let _response = fidl::client::decode_transaction_body::<
291                fidl::encoding::FlexibleType<DriverGetSensorsListResponse>,
292                fidl::encoding::DefaultFuchsiaResourceDialect,
293                0x6a30da06929d426b,
294            >(_buf?)?
295            .into_result::<DriverMarker>("get_sensors_list")?;
296            Ok(_response.sensor_list)
297        }
298        self.client.send_query_and_decode::<
299            fidl::encoding::EmptyPayload,
300            Vec<fidl_fuchsia_sensors_types::SensorInfo>,
301        >(
302            (),
303            0x6a30da06929d426b,
304            fidl::encoding::DynamicFlags::FLEXIBLE,
305            _decode,
306        )
307    }
308
309    type ActivateSensorResponseFut = fidl::client::QueryResponseFut<
310        DriverActivateSensorResult,
311        fidl::encoding::DefaultFuchsiaResourceDialect,
312    >;
313    fn r#activate_sensor(&self, mut sensor_id: i32) -> Self::ActivateSensorResponseFut {
314        fn _decode(
315            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
316        ) -> Result<DriverActivateSensorResult, fidl::Error> {
317            let _response = fidl::client::decode_transaction_body::<
318                fidl::encoding::FlexibleResultType<
319                    fidl::encoding::EmptyStruct,
320                    ActivateSensorError,
321                >,
322                fidl::encoding::DefaultFuchsiaResourceDialect,
323                0x6ff16c620f9f3c5b,
324            >(_buf?)?
325            .into_result::<DriverMarker>("activate_sensor")?;
326            Ok(_response.map(|x| x))
327        }
328        self.client
329            .send_query_and_decode::<DriverActivateSensorRequest, DriverActivateSensorResult>(
330                (sensor_id,),
331                0x6ff16c620f9f3c5b,
332                fidl::encoding::DynamicFlags::FLEXIBLE,
333                _decode,
334            )
335    }
336
337    type DeactivateSensorResponseFut = fidl::client::QueryResponseFut<
338        DriverDeactivateSensorResult,
339        fidl::encoding::DefaultFuchsiaResourceDialect,
340    >;
341    fn r#deactivate_sensor(&self, mut sensor_id: i32) -> Self::DeactivateSensorResponseFut {
342        fn _decode(
343            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
344        ) -> Result<DriverDeactivateSensorResult, fidl::Error> {
345            let _response = fidl::client::decode_transaction_body::<
346                fidl::encoding::FlexibleResultType<
347                    fidl::encoding::EmptyStruct,
348                    DeactivateSensorError,
349                >,
350                fidl::encoding::DefaultFuchsiaResourceDialect,
351                0x64f003527d44ec55,
352            >(_buf?)?
353            .into_result::<DriverMarker>("deactivate_sensor")?;
354            Ok(_response.map(|x| x))
355        }
356        self.client
357            .send_query_and_decode::<DriverDeactivateSensorRequest, DriverDeactivateSensorResult>(
358                (sensor_id,),
359                0x64f003527d44ec55,
360                fidl::encoding::DynamicFlags::FLEXIBLE,
361                _decode,
362            )
363    }
364
365    type ConfigureSensorRateResponseFut = fidl::client::QueryResponseFut<
366        DriverConfigureSensorRateResult,
367        fidl::encoding::DefaultFuchsiaResourceDialect,
368    >;
369    fn r#configure_sensor_rate(
370        &self,
371        mut sensor_id: i32,
372        mut sensor_rate_config: &fidl_fuchsia_sensors_types::SensorRateConfig,
373    ) -> Self::ConfigureSensorRateResponseFut {
374        fn _decode(
375            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
376        ) -> Result<DriverConfigureSensorRateResult, fidl::Error> {
377            let _response = fidl::client::decode_transaction_body::<
378                fidl::encoding::FlexibleResultType<
379                    fidl::encoding::EmptyStruct,
380                    ConfigureSensorRateError,
381                >,
382                fidl::encoding::DefaultFuchsiaResourceDialect,
383                0x78a264bc9c645045,
384            >(_buf?)?
385            .into_result::<DriverMarker>("configure_sensor_rate")?;
386            Ok(_response.map(|x| x))
387        }
388        self.client.send_query_and_decode::<
389            DriverConfigureSensorRateRequest,
390            DriverConfigureSensorRateResult,
391        >(
392            (sensor_id, sensor_rate_config,),
393            0x78a264bc9c645045,
394            fidl::encoding::DynamicFlags::FLEXIBLE,
395            _decode,
396        )
397    }
398}
399
400pub struct DriverEventStream {
401    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
402}
403
404impl std::marker::Unpin for DriverEventStream {}
405
406impl futures::stream::FusedStream for DriverEventStream {
407    fn is_terminated(&self) -> bool {
408        self.event_receiver.is_terminated()
409    }
410}
411
412impl futures::Stream for DriverEventStream {
413    type Item = Result<DriverEvent, fidl::Error>;
414
415    fn poll_next(
416        mut self: std::pin::Pin<&mut Self>,
417        cx: &mut std::task::Context<'_>,
418    ) -> std::task::Poll<Option<Self::Item>> {
419        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
420            &mut self.event_receiver,
421            cx
422        )?) {
423            Some(buf) => std::task::Poll::Ready(Some(DriverEvent::decode(buf))),
424            None => std::task::Poll::Ready(None),
425        }
426    }
427}
428
429#[derive(Debug)]
430pub enum DriverEvent {
431    OnSensorEvent {
432        event: fidl_fuchsia_sensors_types::SensorEvent,
433    },
434    #[non_exhaustive]
435    _UnknownEvent {
436        /// Ordinal of the event that was sent.
437        ordinal: u64,
438    },
439}
440
441impl DriverEvent {
442    #[allow(irrefutable_let_patterns)]
443    pub fn into_on_sensor_event(self) -> Option<fidl_fuchsia_sensors_types::SensorEvent> {
444        if let DriverEvent::OnSensorEvent { event } = self { Some((event)) } else { None }
445    }
446
447    /// Decodes a message buffer as a [`DriverEvent`].
448    fn decode(
449        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
450    ) -> Result<DriverEvent, fidl::Error> {
451        let (bytes, _handles) = buf.split_mut();
452        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
453        debug_assert_eq!(tx_header.tx_id, 0);
454        match tx_header.ordinal {
455            0x2aaf0636bb3e1df9 => {
456                let mut out = fidl::new_empty!(
457                    DriverOnSensorEventRequest,
458                    fidl::encoding::DefaultFuchsiaResourceDialect
459                );
460                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DriverOnSensorEventRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
461                Ok((DriverEvent::OnSensorEvent { event: out.event }))
462            }
463            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
464                Ok(DriverEvent::_UnknownEvent { ordinal: tx_header.ordinal })
465            }
466            _ => Err(fidl::Error::UnknownOrdinal {
467                ordinal: tx_header.ordinal,
468                protocol_name: <DriverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
469            }),
470        }
471    }
472}
473
474/// A Stream of incoming requests for fuchsia.hardware.sensors/Driver.
475pub struct DriverRequestStream {
476    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
477    is_terminated: bool,
478}
479
480impl std::marker::Unpin for DriverRequestStream {}
481
482impl futures::stream::FusedStream for DriverRequestStream {
483    fn is_terminated(&self) -> bool {
484        self.is_terminated
485    }
486}
487
488impl fidl::endpoints::RequestStream for DriverRequestStream {
489    type Protocol = DriverMarker;
490    type ControlHandle = DriverControlHandle;
491
492    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
493        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
494    }
495
496    fn control_handle(&self) -> Self::ControlHandle {
497        DriverControlHandle { inner: self.inner.clone() }
498    }
499
500    fn into_inner(
501        self,
502    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
503    {
504        (self.inner, self.is_terminated)
505    }
506
507    fn from_inner(
508        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
509        is_terminated: bool,
510    ) -> Self {
511        Self { inner, is_terminated }
512    }
513}
514
515impl futures::Stream for DriverRequestStream {
516    type Item = Result<DriverRequest, fidl::Error>;
517
518    fn poll_next(
519        mut self: std::pin::Pin<&mut Self>,
520        cx: &mut std::task::Context<'_>,
521    ) -> std::task::Poll<Option<Self::Item>> {
522        let this = &mut *self;
523        if this.inner.check_shutdown(cx) {
524            this.is_terminated = true;
525            return std::task::Poll::Ready(None);
526        }
527        if this.is_terminated {
528            panic!("polled DriverRequestStream after completion");
529        }
530        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
531            |bytes, handles| {
532                match this.inner.channel().read_etc(cx, bytes, handles) {
533                    std::task::Poll::Ready(Ok(())) => {}
534                    std::task::Poll::Pending => return std::task::Poll::Pending,
535                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
536                        this.is_terminated = true;
537                        return std::task::Poll::Ready(None);
538                    }
539                    std::task::Poll::Ready(Err(e)) => {
540                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
541                            e.into(),
542                        ))));
543                    }
544                }
545
546                // A message has been received from the channel
547                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
548
549                std::task::Poll::Ready(Some(match header.ordinal {
550                    0x6a30da06929d426b => {
551                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
552                        let mut req = fidl::new_empty!(
553                            fidl::encoding::EmptyPayload,
554                            fidl::encoding::DefaultFuchsiaResourceDialect
555                        );
556                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
557                        let control_handle = DriverControlHandle { inner: this.inner.clone() };
558                        Ok(DriverRequest::GetSensorsList {
559                            responder: DriverGetSensorsListResponder {
560                                control_handle: std::mem::ManuallyDrop::new(control_handle),
561                                tx_id: header.tx_id,
562                            },
563                        })
564                    }
565                    0x6ff16c620f9f3c5b => {
566                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
567                        let mut req = fidl::new_empty!(
568                            DriverActivateSensorRequest,
569                            fidl::encoding::DefaultFuchsiaResourceDialect
570                        );
571                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DriverActivateSensorRequest>(&header, _body_bytes, handles, &mut req)?;
572                        let control_handle = DriverControlHandle { inner: this.inner.clone() };
573                        Ok(DriverRequest::ActivateSensor {
574                            sensor_id: req.sensor_id,
575
576                            responder: DriverActivateSensorResponder {
577                                control_handle: std::mem::ManuallyDrop::new(control_handle),
578                                tx_id: header.tx_id,
579                            },
580                        })
581                    }
582                    0x64f003527d44ec55 => {
583                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
584                        let mut req = fidl::new_empty!(
585                            DriverDeactivateSensorRequest,
586                            fidl::encoding::DefaultFuchsiaResourceDialect
587                        );
588                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DriverDeactivateSensorRequest>(&header, _body_bytes, handles, &mut req)?;
589                        let control_handle = DriverControlHandle { inner: this.inner.clone() };
590                        Ok(DriverRequest::DeactivateSensor {
591                            sensor_id: req.sensor_id,
592
593                            responder: DriverDeactivateSensorResponder {
594                                control_handle: std::mem::ManuallyDrop::new(control_handle),
595                                tx_id: header.tx_id,
596                            },
597                        })
598                    }
599                    0x78a264bc9c645045 => {
600                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
601                        let mut req = fidl::new_empty!(
602                            DriverConfigureSensorRateRequest,
603                            fidl::encoding::DefaultFuchsiaResourceDialect
604                        );
605                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DriverConfigureSensorRateRequest>(&header, _body_bytes, handles, &mut req)?;
606                        let control_handle = DriverControlHandle { inner: this.inner.clone() };
607                        Ok(DriverRequest::ConfigureSensorRate {
608                            sensor_id: req.sensor_id,
609                            sensor_rate_config: req.sensor_rate_config,
610
611                            responder: DriverConfigureSensorRateResponder {
612                                control_handle: std::mem::ManuallyDrop::new(control_handle),
613                                tx_id: header.tx_id,
614                            },
615                        })
616                    }
617                    _ if header.tx_id == 0
618                        && header
619                            .dynamic_flags()
620                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
621                    {
622                        Ok(DriverRequest::_UnknownMethod {
623                            ordinal: header.ordinal,
624                            control_handle: DriverControlHandle { inner: this.inner.clone() },
625                            method_type: fidl::MethodType::OneWay,
626                        })
627                    }
628                    _ if header
629                        .dynamic_flags()
630                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
631                    {
632                        this.inner.send_framework_err(
633                            fidl::encoding::FrameworkErr::UnknownMethod,
634                            header.tx_id,
635                            header.ordinal,
636                            header.dynamic_flags(),
637                            (bytes, handles),
638                        )?;
639                        Ok(DriverRequest::_UnknownMethod {
640                            ordinal: header.ordinal,
641                            control_handle: DriverControlHandle { inner: this.inner.clone() },
642                            method_type: fidl::MethodType::TwoWay,
643                        })
644                    }
645                    _ => Err(fidl::Error::UnknownOrdinal {
646                        ordinal: header.ordinal,
647                        protocol_name:
648                            <DriverMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
649                    }),
650                }))
651            },
652        )
653    }
654}
655
656/// Implemented by drivers which talk to one or more pieces of sensor hardware.
657#[derive(Debug)]
658pub enum DriverRequest {
659    /// Retrieve the details of all the sensors managed by this driver.
660    GetSensorsList { responder: DriverGetSensorsListResponder },
661    /// Activate the specified sensor.
662    ActivateSensor { sensor_id: i32, responder: DriverActivateSensorResponder },
663    /// Deactivate the specified sensor.
664    DeactivateSensor { sensor_id: i32, responder: DriverDeactivateSensorResponder },
665    /// Set the output rate for the specified sensor.
666    ConfigureSensorRate {
667        sensor_id: i32,
668        sensor_rate_config: fidl_fuchsia_sensors_types::SensorRateConfig,
669        responder: DriverConfigureSensorRateResponder,
670    },
671    /// An interaction was received which does not match any known method.
672    #[non_exhaustive]
673    _UnknownMethod {
674        /// Ordinal of the method that was called.
675        ordinal: u64,
676        control_handle: DriverControlHandle,
677        method_type: fidl::MethodType,
678    },
679}
680
681impl DriverRequest {
682    #[allow(irrefutable_let_patterns)]
683    pub fn into_get_sensors_list(self) -> Option<(DriverGetSensorsListResponder)> {
684        if let DriverRequest::GetSensorsList { responder } = self {
685            Some((responder))
686        } else {
687            None
688        }
689    }
690
691    #[allow(irrefutable_let_patterns)]
692    pub fn into_activate_sensor(self) -> Option<(i32, DriverActivateSensorResponder)> {
693        if let DriverRequest::ActivateSensor { sensor_id, responder } = self {
694            Some((sensor_id, responder))
695        } else {
696            None
697        }
698    }
699
700    #[allow(irrefutable_let_patterns)]
701    pub fn into_deactivate_sensor(self) -> Option<(i32, DriverDeactivateSensorResponder)> {
702        if let DriverRequest::DeactivateSensor { sensor_id, responder } = self {
703            Some((sensor_id, responder))
704        } else {
705            None
706        }
707    }
708
709    #[allow(irrefutable_let_patterns)]
710    pub fn into_configure_sensor_rate(
711        self,
712    ) -> Option<(
713        i32,
714        fidl_fuchsia_sensors_types::SensorRateConfig,
715        DriverConfigureSensorRateResponder,
716    )> {
717        if let DriverRequest::ConfigureSensorRate { sensor_id, sensor_rate_config, responder } =
718            self
719        {
720            Some((sensor_id, sensor_rate_config, responder))
721        } else {
722            None
723        }
724    }
725
726    /// Name of the method defined in FIDL
727    pub fn method_name(&self) -> &'static str {
728        match *self {
729            DriverRequest::GetSensorsList { .. } => "get_sensors_list",
730            DriverRequest::ActivateSensor { .. } => "activate_sensor",
731            DriverRequest::DeactivateSensor { .. } => "deactivate_sensor",
732            DriverRequest::ConfigureSensorRate { .. } => "configure_sensor_rate",
733            DriverRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
734                "unknown one-way method"
735            }
736            DriverRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
737                "unknown two-way method"
738            }
739        }
740    }
741}
742
743#[derive(Debug, Clone)]
744pub struct DriverControlHandle {
745    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
746}
747
748impl fidl::endpoints::ControlHandle for DriverControlHandle {
749    fn shutdown(&self) {
750        self.inner.shutdown()
751    }
752
753    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
754        self.inner.shutdown_with_epitaph(status)
755    }
756
757    fn is_closed(&self) -> bool {
758        self.inner.channel().is_closed()
759    }
760    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
761        self.inner.channel().on_closed()
762    }
763
764    #[cfg(target_os = "fuchsia")]
765    fn signal_peer(
766        &self,
767        clear_mask: zx::Signals,
768        set_mask: zx::Signals,
769    ) -> Result<(), zx_status::Status> {
770        use fidl::Peered;
771        self.inner.channel().signal_peer(clear_mask, set_mask)
772    }
773}
774
775impl DriverControlHandle {
776    pub fn send_on_sensor_event(
777        &self,
778        mut event: &fidl_fuchsia_sensors_types::SensorEvent,
779    ) -> Result<(), fidl::Error> {
780        self.inner.send::<DriverOnSensorEventRequest>(
781            (event,),
782            0,
783            0x2aaf0636bb3e1df9,
784            fidl::encoding::DynamicFlags::FLEXIBLE,
785        )
786    }
787}
788
789#[must_use = "FIDL methods require a response to be sent"]
790#[derive(Debug)]
791pub struct DriverGetSensorsListResponder {
792    control_handle: std::mem::ManuallyDrop<DriverControlHandle>,
793    tx_id: u32,
794}
795
796/// Set the the channel to be shutdown (see [`DriverControlHandle::shutdown`])
797/// if the responder is dropped without sending a response, so that the client
798/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
799impl std::ops::Drop for DriverGetSensorsListResponder {
800    fn drop(&mut self) {
801        self.control_handle.shutdown();
802        // Safety: drops once, never accessed again
803        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
804    }
805}
806
807impl fidl::endpoints::Responder for DriverGetSensorsListResponder {
808    type ControlHandle = DriverControlHandle;
809
810    fn control_handle(&self) -> &DriverControlHandle {
811        &self.control_handle
812    }
813
814    fn drop_without_shutdown(mut self) {
815        // Safety: drops once, never accessed again due to mem::forget
816        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
817        // Prevent Drop from running (which would shut down the channel)
818        std::mem::forget(self);
819    }
820}
821
822impl DriverGetSensorsListResponder {
823    /// Sends a response to the FIDL transaction.
824    ///
825    /// Sets the channel to shutdown if an error occurs.
826    pub fn send(
827        self,
828        mut sensor_list: &[fidl_fuchsia_sensors_types::SensorInfo],
829    ) -> Result<(), fidl::Error> {
830        let _result = self.send_raw(sensor_list);
831        if _result.is_err() {
832            self.control_handle.shutdown();
833        }
834        self.drop_without_shutdown();
835        _result
836    }
837
838    /// Similar to "send" but does not shutdown the channel if an error occurs.
839    pub fn send_no_shutdown_on_err(
840        self,
841        mut sensor_list: &[fidl_fuchsia_sensors_types::SensorInfo],
842    ) -> Result<(), fidl::Error> {
843        let _result = self.send_raw(sensor_list);
844        self.drop_without_shutdown();
845        _result
846    }
847
848    fn send_raw(
849        &self,
850        mut sensor_list: &[fidl_fuchsia_sensors_types::SensorInfo],
851    ) -> Result<(), fidl::Error> {
852        self.control_handle
853            .inner
854            .send::<fidl::encoding::FlexibleType<DriverGetSensorsListResponse>>(
855                fidl::encoding::Flexible::new((sensor_list,)),
856                self.tx_id,
857                0x6a30da06929d426b,
858                fidl::encoding::DynamicFlags::FLEXIBLE,
859            )
860    }
861}
862
863#[must_use = "FIDL methods require a response to be sent"]
864#[derive(Debug)]
865pub struct DriverActivateSensorResponder {
866    control_handle: std::mem::ManuallyDrop<DriverControlHandle>,
867    tx_id: u32,
868}
869
870/// Set the the channel to be shutdown (see [`DriverControlHandle::shutdown`])
871/// if the responder is dropped without sending a response, so that the client
872/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
873impl std::ops::Drop for DriverActivateSensorResponder {
874    fn drop(&mut self) {
875        self.control_handle.shutdown();
876        // Safety: drops once, never accessed again
877        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
878    }
879}
880
881impl fidl::endpoints::Responder for DriverActivateSensorResponder {
882    type ControlHandle = DriverControlHandle;
883
884    fn control_handle(&self) -> &DriverControlHandle {
885        &self.control_handle
886    }
887
888    fn drop_without_shutdown(mut self) {
889        // Safety: drops once, never accessed again due to mem::forget
890        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
891        // Prevent Drop from running (which would shut down the channel)
892        std::mem::forget(self);
893    }
894}
895
896impl DriverActivateSensorResponder {
897    /// Sends a response to the FIDL transaction.
898    ///
899    /// Sets the channel to shutdown if an error occurs.
900    pub fn send(self, mut result: Result<(), ActivateSensorError>) -> Result<(), fidl::Error> {
901        let _result = self.send_raw(result);
902        if _result.is_err() {
903            self.control_handle.shutdown();
904        }
905        self.drop_without_shutdown();
906        _result
907    }
908
909    /// Similar to "send" but does not shutdown the channel if an error occurs.
910    pub fn send_no_shutdown_on_err(
911        self,
912        mut result: Result<(), ActivateSensorError>,
913    ) -> Result<(), fidl::Error> {
914        let _result = self.send_raw(result);
915        self.drop_without_shutdown();
916        _result
917    }
918
919    fn send_raw(&self, mut result: Result<(), ActivateSensorError>) -> Result<(), fidl::Error> {
920        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
921            fidl::encoding::EmptyStruct,
922            ActivateSensorError,
923        >>(
924            fidl::encoding::FlexibleResult::new(result),
925            self.tx_id,
926            0x6ff16c620f9f3c5b,
927            fidl::encoding::DynamicFlags::FLEXIBLE,
928        )
929    }
930}
931
932#[must_use = "FIDL methods require a response to be sent"]
933#[derive(Debug)]
934pub struct DriverDeactivateSensorResponder {
935    control_handle: std::mem::ManuallyDrop<DriverControlHandle>,
936    tx_id: u32,
937}
938
939/// Set the the channel to be shutdown (see [`DriverControlHandle::shutdown`])
940/// if the responder is dropped without sending a response, so that the client
941/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
942impl std::ops::Drop for DriverDeactivateSensorResponder {
943    fn drop(&mut self) {
944        self.control_handle.shutdown();
945        // Safety: drops once, never accessed again
946        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
947    }
948}
949
950impl fidl::endpoints::Responder for DriverDeactivateSensorResponder {
951    type ControlHandle = DriverControlHandle;
952
953    fn control_handle(&self) -> &DriverControlHandle {
954        &self.control_handle
955    }
956
957    fn drop_without_shutdown(mut self) {
958        // Safety: drops once, never accessed again due to mem::forget
959        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
960        // Prevent Drop from running (which would shut down the channel)
961        std::mem::forget(self);
962    }
963}
964
965impl DriverDeactivateSensorResponder {
966    /// Sends a response to the FIDL transaction.
967    ///
968    /// Sets the channel to shutdown if an error occurs.
969    pub fn send(self, mut result: Result<(), DeactivateSensorError>) -> Result<(), fidl::Error> {
970        let _result = self.send_raw(result);
971        if _result.is_err() {
972            self.control_handle.shutdown();
973        }
974        self.drop_without_shutdown();
975        _result
976    }
977
978    /// Similar to "send" but does not shutdown the channel if an error occurs.
979    pub fn send_no_shutdown_on_err(
980        self,
981        mut result: Result<(), DeactivateSensorError>,
982    ) -> Result<(), fidl::Error> {
983        let _result = self.send_raw(result);
984        self.drop_without_shutdown();
985        _result
986    }
987
988    fn send_raw(&self, mut result: Result<(), DeactivateSensorError>) -> Result<(), fidl::Error> {
989        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
990            fidl::encoding::EmptyStruct,
991            DeactivateSensorError,
992        >>(
993            fidl::encoding::FlexibleResult::new(result),
994            self.tx_id,
995            0x64f003527d44ec55,
996            fidl::encoding::DynamicFlags::FLEXIBLE,
997        )
998    }
999}
1000
1001#[must_use = "FIDL methods require a response to be sent"]
1002#[derive(Debug)]
1003pub struct DriverConfigureSensorRateResponder {
1004    control_handle: std::mem::ManuallyDrop<DriverControlHandle>,
1005    tx_id: u32,
1006}
1007
1008/// Set the the channel to be shutdown (see [`DriverControlHandle::shutdown`])
1009/// if the responder is dropped without sending a response, so that the client
1010/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1011impl std::ops::Drop for DriverConfigureSensorRateResponder {
1012    fn drop(&mut self) {
1013        self.control_handle.shutdown();
1014        // Safety: drops once, never accessed again
1015        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1016    }
1017}
1018
1019impl fidl::endpoints::Responder for DriverConfigureSensorRateResponder {
1020    type ControlHandle = DriverControlHandle;
1021
1022    fn control_handle(&self) -> &DriverControlHandle {
1023        &self.control_handle
1024    }
1025
1026    fn drop_without_shutdown(mut self) {
1027        // Safety: drops once, never accessed again due to mem::forget
1028        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1029        // Prevent Drop from running (which would shut down the channel)
1030        std::mem::forget(self);
1031    }
1032}
1033
1034impl DriverConfigureSensorRateResponder {
1035    /// Sends a response to the FIDL transaction.
1036    ///
1037    /// Sets the channel to shutdown if an error occurs.
1038    pub fn send(self, mut result: Result<(), ConfigureSensorRateError>) -> Result<(), fidl::Error> {
1039        let _result = self.send_raw(result);
1040        if _result.is_err() {
1041            self.control_handle.shutdown();
1042        }
1043        self.drop_without_shutdown();
1044        _result
1045    }
1046
1047    /// Similar to "send" but does not shutdown the channel if an error occurs.
1048    pub fn send_no_shutdown_on_err(
1049        self,
1050        mut result: Result<(), ConfigureSensorRateError>,
1051    ) -> Result<(), fidl::Error> {
1052        let _result = self.send_raw(result);
1053        self.drop_without_shutdown();
1054        _result
1055    }
1056
1057    fn send_raw(
1058        &self,
1059        mut result: Result<(), ConfigureSensorRateError>,
1060    ) -> Result<(), fidl::Error> {
1061        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1062            fidl::encoding::EmptyStruct,
1063            ConfigureSensorRateError,
1064        >>(
1065            fidl::encoding::FlexibleResult::new(result),
1066            self.tx_id,
1067            0x78a264bc9c645045,
1068            fidl::encoding::DynamicFlags::FLEXIBLE,
1069        )
1070    }
1071}
1072
1073#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1074pub struct PlaybackMarker;
1075
1076impl fidl::endpoints::ProtocolMarker for PlaybackMarker {
1077    type Proxy = PlaybackProxy;
1078    type RequestStream = PlaybackRequestStream;
1079    #[cfg(target_os = "fuchsia")]
1080    type SynchronousProxy = PlaybackSynchronousProxy;
1081
1082    const DEBUG_NAME: &'static str = "fuchsia.hardware.sensors.Playback";
1083}
1084impl fidl::endpoints::DiscoverableProtocolMarker for PlaybackMarker {}
1085pub type PlaybackConfigurePlaybackResult = Result<(), ConfigurePlaybackError>;
1086
1087pub trait PlaybackProxyInterface: Send + Sync {
1088    type ConfigurePlaybackResponseFut: std::future::Future<Output = Result<PlaybackConfigurePlaybackResult, fidl::Error>>
1089        + Send;
1090    fn r#configure_playback(
1091        &self,
1092        source_config: &PlaybackSourceConfig,
1093    ) -> Self::ConfigurePlaybackResponseFut;
1094}
1095#[derive(Debug)]
1096#[cfg(target_os = "fuchsia")]
1097pub struct PlaybackSynchronousProxy {
1098    client: fidl::client::sync::Client,
1099}
1100
1101#[cfg(target_os = "fuchsia")]
1102impl fidl::endpoints::SynchronousProxy for PlaybackSynchronousProxy {
1103    type Proxy = PlaybackProxy;
1104    type Protocol = PlaybackMarker;
1105
1106    fn from_channel(inner: fidl::Channel) -> Self {
1107        Self::new(inner)
1108    }
1109
1110    fn into_channel(self) -> fidl::Channel {
1111        self.client.into_channel()
1112    }
1113
1114    fn as_channel(&self) -> &fidl::Channel {
1115        self.client.as_channel()
1116    }
1117}
1118
1119#[cfg(target_os = "fuchsia")]
1120impl PlaybackSynchronousProxy {
1121    pub fn new(channel: fidl::Channel) -> Self {
1122        let protocol_name = <PlaybackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1123        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1124    }
1125
1126    pub fn into_channel(self) -> fidl::Channel {
1127        self.client.into_channel()
1128    }
1129
1130    /// Waits until an event arrives and returns it. It is safe for other
1131    /// threads to make concurrent requests while waiting for an event.
1132    pub fn wait_for_event(
1133        &self,
1134        deadline: zx::MonotonicInstant,
1135    ) -> Result<PlaybackEvent, fidl::Error> {
1136        PlaybackEvent::decode(self.client.wait_for_event(deadline)?)
1137    }
1138
1139    pub fn r#configure_playback(
1140        &self,
1141        mut source_config: &PlaybackSourceConfig,
1142        ___deadline: zx::MonotonicInstant,
1143    ) -> Result<PlaybackConfigurePlaybackResult, fidl::Error> {
1144        let _response =
1145            self.client
1146                .send_query::<PlaybackConfigurePlaybackRequest, fidl::encoding::FlexibleResultType<
1147                    fidl::encoding::EmptyStruct,
1148                    ConfigurePlaybackError,
1149                >>(
1150                    (source_config,),
1151                    0x64327bb27c3d8742,
1152                    fidl::encoding::DynamicFlags::FLEXIBLE,
1153                    ___deadline,
1154                )?
1155                .into_result::<PlaybackMarker>("configure_playback")?;
1156        Ok(_response.map(|x| x))
1157    }
1158}
1159
1160#[cfg(target_os = "fuchsia")]
1161impl From<PlaybackSynchronousProxy> for zx::NullableHandle {
1162    fn from(value: PlaybackSynchronousProxy) -> Self {
1163        value.into_channel().into()
1164    }
1165}
1166
1167#[cfg(target_os = "fuchsia")]
1168impl From<fidl::Channel> for PlaybackSynchronousProxy {
1169    fn from(value: fidl::Channel) -> Self {
1170        Self::new(value)
1171    }
1172}
1173
1174#[cfg(target_os = "fuchsia")]
1175impl fidl::endpoints::FromClient for PlaybackSynchronousProxy {
1176    type Protocol = PlaybackMarker;
1177
1178    fn from_client(value: fidl::endpoints::ClientEnd<PlaybackMarker>) -> Self {
1179        Self::new(value.into_channel())
1180    }
1181}
1182
1183#[derive(Debug, Clone)]
1184pub struct PlaybackProxy {
1185    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1186}
1187
1188impl fidl::endpoints::Proxy for PlaybackProxy {
1189    type Protocol = PlaybackMarker;
1190
1191    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1192        Self::new(inner)
1193    }
1194
1195    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1196        self.client.into_channel().map_err(|client| Self { client })
1197    }
1198
1199    fn as_channel(&self) -> &::fidl::AsyncChannel {
1200        self.client.as_channel()
1201    }
1202}
1203
1204impl PlaybackProxy {
1205    /// Create a new Proxy for fuchsia.hardware.sensors/Playback.
1206    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1207        let protocol_name = <PlaybackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1208        Self { client: fidl::client::Client::new(channel, protocol_name) }
1209    }
1210
1211    /// Get a Stream of events from the remote end of the protocol.
1212    ///
1213    /// # Panics
1214    ///
1215    /// Panics if the event stream was already taken.
1216    pub fn take_event_stream(&self) -> PlaybackEventStream {
1217        PlaybackEventStream { event_receiver: self.client.take_event_receiver() }
1218    }
1219
1220    pub fn r#configure_playback(
1221        &self,
1222        mut source_config: &PlaybackSourceConfig,
1223    ) -> fidl::client::QueryResponseFut<
1224        PlaybackConfigurePlaybackResult,
1225        fidl::encoding::DefaultFuchsiaResourceDialect,
1226    > {
1227        PlaybackProxyInterface::r#configure_playback(self, source_config)
1228    }
1229}
1230
1231impl PlaybackProxyInterface for PlaybackProxy {
1232    type ConfigurePlaybackResponseFut = fidl::client::QueryResponseFut<
1233        PlaybackConfigurePlaybackResult,
1234        fidl::encoding::DefaultFuchsiaResourceDialect,
1235    >;
1236    fn r#configure_playback(
1237        &self,
1238        mut source_config: &PlaybackSourceConfig,
1239    ) -> Self::ConfigurePlaybackResponseFut {
1240        fn _decode(
1241            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1242        ) -> Result<PlaybackConfigurePlaybackResult, fidl::Error> {
1243            let _response = fidl::client::decode_transaction_body::<
1244                fidl::encoding::FlexibleResultType<
1245                    fidl::encoding::EmptyStruct,
1246                    ConfigurePlaybackError,
1247                >,
1248                fidl::encoding::DefaultFuchsiaResourceDialect,
1249                0x64327bb27c3d8742,
1250            >(_buf?)?
1251            .into_result::<PlaybackMarker>("configure_playback")?;
1252            Ok(_response.map(|x| x))
1253        }
1254        self.client.send_query_and_decode::<
1255            PlaybackConfigurePlaybackRequest,
1256            PlaybackConfigurePlaybackResult,
1257        >(
1258            (source_config,),
1259            0x64327bb27c3d8742,
1260            fidl::encoding::DynamicFlags::FLEXIBLE,
1261            _decode,
1262        )
1263    }
1264}
1265
1266pub struct PlaybackEventStream {
1267    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1268}
1269
1270impl std::marker::Unpin for PlaybackEventStream {}
1271
1272impl futures::stream::FusedStream for PlaybackEventStream {
1273    fn is_terminated(&self) -> bool {
1274        self.event_receiver.is_terminated()
1275    }
1276}
1277
1278impl futures::Stream for PlaybackEventStream {
1279    type Item = Result<PlaybackEvent, fidl::Error>;
1280
1281    fn poll_next(
1282        mut self: std::pin::Pin<&mut Self>,
1283        cx: &mut std::task::Context<'_>,
1284    ) -> std::task::Poll<Option<Self::Item>> {
1285        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1286            &mut self.event_receiver,
1287            cx
1288        )?) {
1289            Some(buf) => std::task::Poll::Ready(Some(PlaybackEvent::decode(buf))),
1290            None => std::task::Poll::Ready(None),
1291        }
1292    }
1293}
1294
1295#[derive(Debug)]
1296pub enum PlaybackEvent {
1297    #[non_exhaustive]
1298    _UnknownEvent {
1299        /// Ordinal of the event that was sent.
1300        ordinal: u64,
1301    },
1302}
1303
1304impl PlaybackEvent {
1305    /// Decodes a message buffer as a [`PlaybackEvent`].
1306    fn decode(
1307        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1308    ) -> Result<PlaybackEvent, fidl::Error> {
1309        let (bytes, _handles) = buf.split_mut();
1310        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1311        debug_assert_eq!(tx_header.tx_id, 0);
1312        match tx_header.ordinal {
1313            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1314                Ok(PlaybackEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1315            }
1316            _ => Err(fidl::Error::UnknownOrdinal {
1317                ordinal: tx_header.ordinal,
1318                protocol_name: <PlaybackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1319            }),
1320        }
1321    }
1322}
1323
1324/// A Stream of incoming requests for fuchsia.hardware.sensors/Playback.
1325pub struct PlaybackRequestStream {
1326    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1327    is_terminated: bool,
1328}
1329
1330impl std::marker::Unpin for PlaybackRequestStream {}
1331
1332impl futures::stream::FusedStream for PlaybackRequestStream {
1333    fn is_terminated(&self) -> bool {
1334        self.is_terminated
1335    }
1336}
1337
1338impl fidl::endpoints::RequestStream for PlaybackRequestStream {
1339    type Protocol = PlaybackMarker;
1340    type ControlHandle = PlaybackControlHandle;
1341
1342    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1343        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1344    }
1345
1346    fn control_handle(&self) -> Self::ControlHandle {
1347        PlaybackControlHandle { inner: self.inner.clone() }
1348    }
1349
1350    fn into_inner(
1351        self,
1352    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1353    {
1354        (self.inner, self.is_terminated)
1355    }
1356
1357    fn from_inner(
1358        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1359        is_terminated: bool,
1360    ) -> Self {
1361        Self { inner, is_terminated }
1362    }
1363}
1364
1365impl futures::Stream for PlaybackRequestStream {
1366    type Item = Result<PlaybackRequest, fidl::Error>;
1367
1368    fn poll_next(
1369        mut self: std::pin::Pin<&mut Self>,
1370        cx: &mut std::task::Context<'_>,
1371    ) -> std::task::Poll<Option<Self::Item>> {
1372        let this = &mut *self;
1373        if this.inner.check_shutdown(cx) {
1374            this.is_terminated = true;
1375            return std::task::Poll::Ready(None);
1376        }
1377        if this.is_terminated {
1378            panic!("polled PlaybackRequestStream after completion");
1379        }
1380        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1381            |bytes, handles| {
1382                match this.inner.channel().read_etc(cx, bytes, handles) {
1383                    std::task::Poll::Ready(Ok(())) => {}
1384                    std::task::Poll::Pending => return std::task::Poll::Pending,
1385                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1386                        this.is_terminated = true;
1387                        return std::task::Poll::Ready(None);
1388                    }
1389                    std::task::Poll::Ready(Err(e)) => {
1390                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1391                            e.into(),
1392                        ))));
1393                    }
1394                }
1395
1396                // A message has been received from the channel
1397                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1398
1399                std::task::Poll::Ready(Some(match header.ordinal {
1400                    0x64327bb27c3d8742 => {
1401                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1402                        let mut req = fidl::new_empty!(
1403                            PlaybackConfigurePlaybackRequest,
1404                            fidl::encoding::DefaultFuchsiaResourceDialect
1405                        );
1406                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PlaybackConfigurePlaybackRequest>(&header, _body_bytes, handles, &mut req)?;
1407                        let control_handle = PlaybackControlHandle { inner: this.inner.clone() };
1408                        Ok(PlaybackRequest::ConfigurePlayback {
1409                            source_config: req.source_config,
1410
1411                            responder: PlaybackConfigurePlaybackResponder {
1412                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1413                                tx_id: header.tx_id,
1414                            },
1415                        })
1416                    }
1417                    _ if header.tx_id == 0
1418                        && header
1419                            .dynamic_flags()
1420                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1421                    {
1422                        Ok(PlaybackRequest::_UnknownMethod {
1423                            ordinal: header.ordinal,
1424                            control_handle: PlaybackControlHandle { inner: this.inner.clone() },
1425                            method_type: fidl::MethodType::OneWay,
1426                        })
1427                    }
1428                    _ if header
1429                        .dynamic_flags()
1430                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1431                    {
1432                        this.inner.send_framework_err(
1433                            fidl::encoding::FrameworkErr::UnknownMethod,
1434                            header.tx_id,
1435                            header.ordinal,
1436                            header.dynamic_flags(),
1437                            (bytes, handles),
1438                        )?;
1439                        Ok(PlaybackRequest::_UnknownMethod {
1440                            ordinal: header.ordinal,
1441                            control_handle: PlaybackControlHandle { inner: this.inner.clone() },
1442                            method_type: fidl::MethodType::TwoWay,
1443                        })
1444                    }
1445                    _ => Err(fidl::Error::UnknownOrdinal {
1446                        ordinal: header.ordinal,
1447                        protocol_name:
1448                            <PlaybackMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1449                    }),
1450                }))
1451            },
1452        )
1453    }
1454}
1455
1456/// Implemented by components which pretend to be a sensor driver but instead
1457/// emit prerecorded or pregenerated data. Those components will also implement
1458/// the fuchsia.hardware.sensors.Driver protocol which will be used to actually
1459/// control the playback of data. This protocol is used to set up the playback
1460/// data source and playback specific parameters.
1461#[derive(Debug)]
1462pub enum PlaybackRequest {
1463    ConfigurePlayback {
1464        source_config: PlaybackSourceConfig,
1465        responder: PlaybackConfigurePlaybackResponder,
1466    },
1467    /// An interaction was received which does not match any known method.
1468    #[non_exhaustive]
1469    _UnknownMethod {
1470        /// Ordinal of the method that was called.
1471        ordinal: u64,
1472        control_handle: PlaybackControlHandle,
1473        method_type: fidl::MethodType,
1474    },
1475}
1476
1477impl PlaybackRequest {
1478    #[allow(irrefutable_let_patterns)]
1479    pub fn into_configure_playback(
1480        self,
1481    ) -> Option<(PlaybackSourceConfig, PlaybackConfigurePlaybackResponder)> {
1482        if let PlaybackRequest::ConfigurePlayback { source_config, responder } = self {
1483            Some((source_config, responder))
1484        } else {
1485            None
1486        }
1487    }
1488
1489    /// Name of the method defined in FIDL
1490    pub fn method_name(&self) -> &'static str {
1491        match *self {
1492            PlaybackRequest::ConfigurePlayback { .. } => "configure_playback",
1493            PlaybackRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1494                "unknown one-way method"
1495            }
1496            PlaybackRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1497                "unknown two-way method"
1498            }
1499        }
1500    }
1501}
1502
1503#[derive(Debug, Clone)]
1504pub struct PlaybackControlHandle {
1505    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1506}
1507
1508impl fidl::endpoints::ControlHandle for PlaybackControlHandle {
1509    fn shutdown(&self) {
1510        self.inner.shutdown()
1511    }
1512
1513    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1514        self.inner.shutdown_with_epitaph(status)
1515    }
1516
1517    fn is_closed(&self) -> bool {
1518        self.inner.channel().is_closed()
1519    }
1520    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1521        self.inner.channel().on_closed()
1522    }
1523
1524    #[cfg(target_os = "fuchsia")]
1525    fn signal_peer(
1526        &self,
1527        clear_mask: zx::Signals,
1528        set_mask: zx::Signals,
1529    ) -> Result<(), zx_status::Status> {
1530        use fidl::Peered;
1531        self.inner.channel().signal_peer(clear_mask, set_mask)
1532    }
1533}
1534
1535impl PlaybackControlHandle {}
1536
1537#[must_use = "FIDL methods require a response to be sent"]
1538#[derive(Debug)]
1539pub struct PlaybackConfigurePlaybackResponder {
1540    control_handle: std::mem::ManuallyDrop<PlaybackControlHandle>,
1541    tx_id: u32,
1542}
1543
1544/// Set the the channel to be shutdown (see [`PlaybackControlHandle::shutdown`])
1545/// if the responder is dropped without sending a response, so that the client
1546/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1547impl std::ops::Drop for PlaybackConfigurePlaybackResponder {
1548    fn drop(&mut self) {
1549        self.control_handle.shutdown();
1550        // Safety: drops once, never accessed again
1551        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1552    }
1553}
1554
1555impl fidl::endpoints::Responder for PlaybackConfigurePlaybackResponder {
1556    type ControlHandle = PlaybackControlHandle;
1557
1558    fn control_handle(&self) -> &PlaybackControlHandle {
1559        &self.control_handle
1560    }
1561
1562    fn drop_without_shutdown(mut self) {
1563        // Safety: drops once, never accessed again due to mem::forget
1564        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1565        // Prevent Drop from running (which would shut down the channel)
1566        std::mem::forget(self);
1567    }
1568}
1569
1570impl PlaybackConfigurePlaybackResponder {
1571    /// Sends a response to the FIDL transaction.
1572    ///
1573    /// Sets the channel to shutdown if an error occurs.
1574    pub fn send(self, mut result: Result<(), ConfigurePlaybackError>) -> Result<(), fidl::Error> {
1575        let _result = self.send_raw(result);
1576        if _result.is_err() {
1577            self.control_handle.shutdown();
1578        }
1579        self.drop_without_shutdown();
1580        _result
1581    }
1582
1583    /// Similar to "send" but does not shutdown the channel if an error occurs.
1584    pub fn send_no_shutdown_on_err(
1585        self,
1586        mut result: Result<(), ConfigurePlaybackError>,
1587    ) -> Result<(), fidl::Error> {
1588        let _result = self.send_raw(result);
1589        self.drop_without_shutdown();
1590        _result
1591    }
1592
1593    fn send_raw(&self, mut result: Result<(), ConfigurePlaybackError>) -> Result<(), fidl::Error> {
1594        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1595            fidl::encoding::EmptyStruct,
1596            ConfigurePlaybackError,
1597        >>(
1598            fidl::encoding::FlexibleResult::new(result),
1599            self.tx_id,
1600            0x64327bb27c3d8742,
1601            fidl::encoding::DynamicFlags::FLEXIBLE,
1602        )
1603    }
1604}
1605
1606#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1607pub struct ServiceMarker;
1608
1609#[cfg(target_os = "fuchsia")]
1610impl fidl::endpoints::ServiceMarker for ServiceMarker {
1611    type Proxy = ServiceProxy;
1612    type Request = ServiceRequest;
1613    const SERVICE_NAME: &'static str = "fuchsia.hardware.sensors.Service";
1614}
1615
1616/// A request for one of the member protocols of Service.
1617///
1618#[cfg(target_os = "fuchsia")]
1619pub enum ServiceRequest {
1620    Driver(DriverRequestStream),
1621}
1622
1623#[cfg(target_os = "fuchsia")]
1624impl fidl::endpoints::ServiceRequest for ServiceRequest {
1625    type Service = ServiceMarker;
1626
1627    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1628        match name {
1629            "driver" => Self::Driver(
1630                <DriverRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1631            ),
1632            _ => panic!("no such member protocol name for service Service"),
1633        }
1634    }
1635
1636    fn member_names() -> &'static [&'static str] {
1637        &["driver"]
1638    }
1639}
1640#[cfg(target_os = "fuchsia")]
1641pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1642
1643#[cfg(target_os = "fuchsia")]
1644impl fidl::endpoints::ServiceProxy for ServiceProxy {
1645    type Service = ServiceMarker;
1646
1647    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1648        Self(opener)
1649    }
1650}
1651
1652#[cfg(target_os = "fuchsia")]
1653impl ServiceProxy {
1654    pub fn connect_to_driver(&self) -> Result<DriverProxy, fidl::Error> {
1655        let (proxy, server_end) = fidl::endpoints::create_proxy::<DriverMarker>();
1656        self.connect_channel_to_driver(server_end)?;
1657        Ok(proxy)
1658    }
1659
1660    /// Like `connect_to_driver`, but returns a sync proxy.
1661    /// See [`Self::connect_to_driver`] for more details.
1662    pub fn connect_to_driver_sync(&self) -> Result<DriverSynchronousProxy, fidl::Error> {
1663        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DriverMarker>();
1664        self.connect_channel_to_driver(server_end)?;
1665        Ok(proxy)
1666    }
1667
1668    /// Like `connect_to_driver`, but accepts a server end.
1669    /// See [`Self::connect_to_driver`] for more details.
1670    pub fn connect_channel_to_driver(
1671        &self,
1672        server_end: fidl::endpoints::ServerEnd<DriverMarker>,
1673    ) -> Result<(), fidl::Error> {
1674        self.0.open_member("driver", server_end.into_channel())
1675    }
1676
1677    pub fn instance_name(&self) -> &str {
1678        self.0.instance_name()
1679    }
1680}
1681
1682mod internal {
1683    use super::*;
1684}