fidl_fuchsia_ui_display_singleton/
fidl_fuchsia_ui_display_singleton.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_ui_display_singleton__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DisplayPowerMarker;
16
17impl fidl::endpoints::ProtocolMarker for DisplayPowerMarker {
18    type Proxy = DisplayPowerProxy;
19    type RequestStream = DisplayPowerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DisplayPowerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.ui.display.singleton.DisplayPower";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DisplayPowerMarker {}
26pub type DisplayPowerSetPowerModeResult = Result<(), i32>;
27
28pub trait DisplayPowerProxyInterface: Send + Sync {
29    type SetPowerModeResponseFut: std::future::Future<Output = Result<DisplayPowerSetPowerModeResult, fidl::Error>>
30        + Send;
31    fn r#set_power_mode(&self, power_mode: PowerMode) -> Self::SetPowerModeResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct DisplayPowerSynchronousProxy {
36    client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for DisplayPowerSynchronousProxy {
41    type Proxy = DisplayPowerProxy;
42    type Protocol = DisplayPowerMarker;
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 DisplayPowerSynchronousProxy {
59    pub fn new(channel: fidl::Channel) -> Self {
60        let protocol_name = <DisplayPowerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62    }
63
64    pub fn into_channel(self) -> fidl::Channel {
65        self.client.into_channel()
66    }
67
68    /// Waits until an event arrives and returns it. It is safe for other
69    /// threads to make concurrent requests while waiting for an event.
70    pub fn wait_for_event(
71        &self,
72        deadline: zx::MonotonicInstant,
73    ) -> Result<DisplayPowerEvent, fidl::Error> {
74        DisplayPowerEvent::decode(self.client.wait_for_event(deadline)?)
75    }
76
77    /// Set the power state of the default connected display device to `power_mode`.
78    ///
79    /// Errors:
80    ///  - `ZX_ERR_NOT_FOUND`: There is no connected display.
81    ///  - `ZX_ERR_NOT_SUPPORTED`: The default connected display driver or hardware
82    ///    does not support the requested power mode.
83    ///  - `ZX_ERR_INTERNAL`: Operation failed for another reason.
84    pub fn r#set_power_mode(
85        &self,
86        mut power_mode: PowerMode,
87        ___deadline: zx::MonotonicInstant,
88    ) -> Result<DisplayPowerSetPowerModeResult, fidl::Error> {
89        let _response = self.client.send_query::<
90            DisplayPowerSetPowerModeRequest,
91            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
92        >(
93            (power_mode,),
94            0x420dcd07d68e1fbc,
95            fidl::encoding::DynamicFlags::FLEXIBLE,
96            ___deadline,
97        )?
98        .into_result::<DisplayPowerMarker>("set_power_mode")?;
99        Ok(_response.map(|x| x))
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<DisplayPowerSynchronousProxy> for zx::NullableHandle {
105    fn from(value: DisplayPowerSynchronousProxy) -> Self {
106        value.into_channel().into()
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl From<fidl::Channel> for DisplayPowerSynchronousProxy {
112    fn from(value: fidl::Channel) -> Self {
113        Self::new(value)
114    }
115}
116
117#[cfg(target_os = "fuchsia")]
118impl fidl::endpoints::FromClient for DisplayPowerSynchronousProxy {
119    type Protocol = DisplayPowerMarker;
120
121    fn from_client(value: fidl::endpoints::ClientEnd<DisplayPowerMarker>) -> Self {
122        Self::new(value.into_channel())
123    }
124}
125
126#[derive(Debug, Clone)]
127pub struct DisplayPowerProxy {
128    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
129}
130
131impl fidl::endpoints::Proxy for DisplayPowerProxy {
132    type Protocol = DisplayPowerMarker;
133
134    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
135        Self::new(inner)
136    }
137
138    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
139        self.client.into_channel().map_err(|client| Self { client })
140    }
141
142    fn as_channel(&self) -> &::fidl::AsyncChannel {
143        self.client.as_channel()
144    }
145}
146
147impl DisplayPowerProxy {
148    /// Create a new Proxy for fuchsia.ui.display.singleton/DisplayPower.
149    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
150        let protocol_name = <DisplayPowerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
151        Self { client: fidl::client::Client::new(channel, protocol_name) }
152    }
153
154    /// Get a Stream of events from the remote end of the protocol.
155    ///
156    /// # Panics
157    ///
158    /// Panics if the event stream was already taken.
159    pub fn take_event_stream(&self) -> DisplayPowerEventStream {
160        DisplayPowerEventStream { event_receiver: self.client.take_event_receiver() }
161    }
162
163    /// Set the power state of the default connected display device to `power_mode`.
164    ///
165    /// Errors:
166    ///  - `ZX_ERR_NOT_FOUND`: There is no connected display.
167    ///  - `ZX_ERR_NOT_SUPPORTED`: The default connected display driver or hardware
168    ///    does not support the requested power mode.
169    ///  - `ZX_ERR_INTERNAL`: Operation failed for another reason.
170    pub fn r#set_power_mode(
171        &self,
172        mut power_mode: PowerMode,
173    ) -> fidl::client::QueryResponseFut<
174        DisplayPowerSetPowerModeResult,
175        fidl::encoding::DefaultFuchsiaResourceDialect,
176    > {
177        DisplayPowerProxyInterface::r#set_power_mode(self, power_mode)
178    }
179}
180
181impl DisplayPowerProxyInterface for DisplayPowerProxy {
182    type SetPowerModeResponseFut = fidl::client::QueryResponseFut<
183        DisplayPowerSetPowerModeResult,
184        fidl::encoding::DefaultFuchsiaResourceDialect,
185    >;
186    fn r#set_power_mode(&self, mut power_mode: PowerMode) -> Self::SetPowerModeResponseFut {
187        fn _decode(
188            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
189        ) -> Result<DisplayPowerSetPowerModeResult, fidl::Error> {
190            let _response = fidl::client::decode_transaction_body::<
191                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
192                fidl::encoding::DefaultFuchsiaResourceDialect,
193                0x420dcd07d68e1fbc,
194            >(_buf?)?
195            .into_result::<DisplayPowerMarker>("set_power_mode")?;
196            Ok(_response.map(|x| x))
197        }
198        self.client.send_query_and_decode::<
199            DisplayPowerSetPowerModeRequest,
200            DisplayPowerSetPowerModeResult,
201        >(
202            (power_mode,),
203            0x420dcd07d68e1fbc,
204            fidl::encoding::DynamicFlags::FLEXIBLE,
205            _decode,
206        )
207    }
208}
209
210pub struct DisplayPowerEventStream {
211    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
212}
213
214impl std::marker::Unpin for DisplayPowerEventStream {}
215
216impl futures::stream::FusedStream for DisplayPowerEventStream {
217    fn is_terminated(&self) -> bool {
218        self.event_receiver.is_terminated()
219    }
220}
221
222impl futures::Stream for DisplayPowerEventStream {
223    type Item = Result<DisplayPowerEvent, fidl::Error>;
224
225    fn poll_next(
226        mut self: std::pin::Pin<&mut Self>,
227        cx: &mut std::task::Context<'_>,
228    ) -> std::task::Poll<Option<Self::Item>> {
229        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
230            &mut self.event_receiver,
231            cx
232        )?) {
233            Some(buf) => std::task::Poll::Ready(Some(DisplayPowerEvent::decode(buf))),
234            None => std::task::Poll::Ready(None),
235        }
236    }
237}
238
239#[derive(Debug)]
240pub enum DisplayPowerEvent {
241    #[non_exhaustive]
242    _UnknownEvent {
243        /// Ordinal of the event that was sent.
244        ordinal: u64,
245    },
246}
247
248impl DisplayPowerEvent {
249    /// Decodes a message buffer as a [`DisplayPowerEvent`].
250    fn decode(
251        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
252    ) -> Result<DisplayPowerEvent, fidl::Error> {
253        let (bytes, _handles) = buf.split_mut();
254        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
255        debug_assert_eq!(tx_header.tx_id, 0);
256        match tx_header.ordinal {
257            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
258                Ok(DisplayPowerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
259            }
260            _ => Err(fidl::Error::UnknownOrdinal {
261                ordinal: tx_header.ordinal,
262                protocol_name: <DisplayPowerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
263            }),
264        }
265    }
266}
267
268/// A Stream of incoming requests for fuchsia.ui.display.singleton/DisplayPower.
269pub struct DisplayPowerRequestStream {
270    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
271    is_terminated: bool,
272}
273
274impl std::marker::Unpin for DisplayPowerRequestStream {}
275
276impl futures::stream::FusedStream for DisplayPowerRequestStream {
277    fn is_terminated(&self) -> bool {
278        self.is_terminated
279    }
280}
281
282impl fidl::endpoints::RequestStream for DisplayPowerRequestStream {
283    type Protocol = DisplayPowerMarker;
284    type ControlHandle = DisplayPowerControlHandle;
285
286    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
287        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
288    }
289
290    fn control_handle(&self) -> Self::ControlHandle {
291        DisplayPowerControlHandle { inner: self.inner.clone() }
292    }
293
294    fn into_inner(
295        self,
296    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
297    {
298        (self.inner, self.is_terminated)
299    }
300
301    fn from_inner(
302        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
303        is_terminated: bool,
304    ) -> Self {
305        Self { inner, is_terminated }
306    }
307}
308
309impl futures::Stream for DisplayPowerRequestStream {
310    type Item = Result<DisplayPowerRequest, fidl::Error>;
311
312    fn poll_next(
313        mut self: std::pin::Pin<&mut Self>,
314        cx: &mut std::task::Context<'_>,
315    ) -> std::task::Poll<Option<Self::Item>> {
316        let this = &mut *self;
317        if this.inner.check_shutdown(cx) {
318            this.is_terminated = true;
319            return std::task::Poll::Ready(None);
320        }
321        if this.is_terminated {
322            panic!("polled DisplayPowerRequestStream after completion");
323        }
324        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
325            |bytes, handles| {
326                match this.inner.channel().read_etc(cx, bytes, handles) {
327                    std::task::Poll::Ready(Ok(())) => {}
328                    std::task::Poll::Pending => return std::task::Poll::Pending,
329                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
330                        this.is_terminated = true;
331                        return std::task::Poll::Ready(None);
332                    }
333                    std::task::Poll::Ready(Err(e)) => {
334                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
335                            e.into(),
336                        ))));
337                    }
338                }
339
340                // A message has been received from the channel
341                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
342
343                std::task::Poll::Ready(Some(match header.ordinal {
344                    0x420dcd07d68e1fbc => {
345                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
346                        let mut req = fidl::new_empty!(
347                            DisplayPowerSetPowerModeRequest,
348                            fidl::encoding::DefaultFuchsiaResourceDialect
349                        );
350                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DisplayPowerSetPowerModeRequest>(&header, _body_bytes, handles, &mut req)?;
351                        let control_handle =
352                            DisplayPowerControlHandle { inner: this.inner.clone() };
353                        Ok(DisplayPowerRequest::SetPowerMode {
354                            power_mode: req.power_mode,
355
356                            responder: DisplayPowerSetPowerModeResponder {
357                                control_handle: std::mem::ManuallyDrop::new(control_handle),
358                                tx_id: header.tx_id,
359                            },
360                        })
361                    }
362                    _ if header.tx_id == 0
363                        && header
364                            .dynamic_flags()
365                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
366                    {
367                        Ok(DisplayPowerRequest::_UnknownMethod {
368                            ordinal: header.ordinal,
369                            control_handle: DisplayPowerControlHandle { inner: this.inner.clone() },
370                            method_type: fidl::MethodType::OneWay,
371                        })
372                    }
373                    _ if header
374                        .dynamic_flags()
375                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
376                    {
377                        this.inner.send_framework_err(
378                            fidl::encoding::FrameworkErr::UnknownMethod,
379                            header.tx_id,
380                            header.ordinal,
381                            header.dynamic_flags(),
382                            (bytes, handles),
383                        )?;
384                        Ok(DisplayPowerRequest::_UnknownMethod {
385                            ordinal: header.ordinal,
386                            control_handle: DisplayPowerControlHandle { inner: this.inner.clone() },
387                            method_type: fidl::MethodType::TwoWay,
388                        })
389                    }
390                    _ => Err(fidl::Error::UnknownOrdinal {
391                        ordinal: header.ordinal,
392                        protocol_name:
393                            <DisplayPowerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
394                    }),
395                }))
396            },
397        )
398    }
399}
400
401/// Controls the power state of the default display device.
402#[derive(Debug)]
403pub enum DisplayPowerRequest {
404    /// Set the power state of the default connected display device to `power_mode`.
405    ///
406    /// Errors:
407    ///  - `ZX_ERR_NOT_FOUND`: There is no connected display.
408    ///  - `ZX_ERR_NOT_SUPPORTED`: The default connected display driver or hardware
409    ///    does not support the requested power mode.
410    ///  - `ZX_ERR_INTERNAL`: Operation failed for another reason.
411    SetPowerMode { power_mode: PowerMode, responder: DisplayPowerSetPowerModeResponder },
412    /// An interaction was received which does not match any known method.
413    #[non_exhaustive]
414    _UnknownMethod {
415        /// Ordinal of the method that was called.
416        ordinal: u64,
417        control_handle: DisplayPowerControlHandle,
418        method_type: fidl::MethodType,
419    },
420}
421
422impl DisplayPowerRequest {
423    #[allow(irrefutable_let_patterns)]
424    pub fn into_set_power_mode(self) -> Option<(PowerMode, DisplayPowerSetPowerModeResponder)> {
425        if let DisplayPowerRequest::SetPowerMode { power_mode, responder } = self {
426            Some((power_mode, responder))
427        } else {
428            None
429        }
430    }
431
432    /// Name of the method defined in FIDL
433    pub fn method_name(&self) -> &'static str {
434        match *self {
435            DisplayPowerRequest::SetPowerMode { .. } => "set_power_mode",
436            DisplayPowerRequest::_UnknownMethod {
437                method_type: fidl::MethodType::OneWay, ..
438            } => "unknown one-way method",
439            DisplayPowerRequest::_UnknownMethod {
440                method_type: fidl::MethodType::TwoWay, ..
441            } => "unknown two-way method",
442        }
443    }
444}
445
446#[derive(Debug, Clone)]
447pub struct DisplayPowerControlHandle {
448    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
449}
450
451impl fidl::endpoints::ControlHandle for DisplayPowerControlHandle {
452    fn shutdown(&self) {
453        self.inner.shutdown()
454    }
455
456    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
457        self.inner.shutdown_with_epitaph(status)
458    }
459
460    fn is_closed(&self) -> bool {
461        self.inner.channel().is_closed()
462    }
463    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
464        self.inner.channel().on_closed()
465    }
466
467    #[cfg(target_os = "fuchsia")]
468    fn signal_peer(
469        &self,
470        clear_mask: zx::Signals,
471        set_mask: zx::Signals,
472    ) -> Result<(), zx_status::Status> {
473        use fidl::Peered;
474        self.inner.channel().signal_peer(clear_mask, set_mask)
475    }
476}
477
478impl DisplayPowerControlHandle {}
479
480#[must_use = "FIDL methods require a response to be sent"]
481#[derive(Debug)]
482pub struct DisplayPowerSetPowerModeResponder {
483    control_handle: std::mem::ManuallyDrop<DisplayPowerControlHandle>,
484    tx_id: u32,
485}
486
487/// Set the the channel to be shutdown (see [`DisplayPowerControlHandle::shutdown`])
488/// if the responder is dropped without sending a response, so that the client
489/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
490impl std::ops::Drop for DisplayPowerSetPowerModeResponder {
491    fn drop(&mut self) {
492        self.control_handle.shutdown();
493        // Safety: drops once, never accessed again
494        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
495    }
496}
497
498impl fidl::endpoints::Responder for DisplayPowerSetPowerModeResponder {
499    type ControlHandle = DisplayPowerControlHandle;
500
501    fn control_handle(&self) -> &DisplayPowerControlHandle {
502        &self.control_handle
503    }
504
505    fn drop_without_shutdown(mut self) {
506        // Safety: drops once, never accessed again due to mem::forget
507        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
508        // Prevent Drop from running (which would shut down the channel)
509        std::mem::forget(self);
510    }
511}
512
513impl DisplayPowerSetPowerModeResponder {
514    /// Sends a response to the FIDL transaction.
515    ///
516    /// Sets the channel to shutdown if an error occurs.
517    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
518        let _result = self.send_raw(result);
519        if _result.is_err() {
520            self.control_handle.shutdown();
521        }
522        self.drop_without_shutdown();
523        _result
524    }
525
526    /// Similar to "send" but does not shutdown the channel if an error occurs.
527    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
528        let _result = self.send_raw(result);
529        self.drop_without_shutdown();
530        _result
531    }
532
533    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
534        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
535            fidl::encoding::EmptyStruct,
536            i32,
537        >>(
538            fidl::encoding::FlexibleResult::new(result),
539            self.tx_id,
540            0x420dcd07d68e1fbc,
541            fidl::encoding::DynamicFlags::FLEXIBLE,
542        )
543    }
544}
545
546#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
547pub struct InfoMarker;
548
549impl fidl::endpoints::ProtocolMarker for InfoMarker {
550    type Proxy = InfoProxy;
551    type RequestStream = InfoRequestStream;
552    #[cfg(target_os = "fuchsia")]
553    type SynchronousProxy = InfoSynchronousProxy;
554
555    const DEBUG_NAME: &'static str = "fuchsia.ui.display.singleton.Info";
556}
557impl fidl::endpoints::DiscoverableProtocolMarker for InfoMarker {}
558
559pub trait InfoProxyInterface: Send + Sync {
560    type GetMetricsResponseFut: std::future::Future<Output = Result<Metrics, fidl::Error>> + Send;
561    fn r#get_metrics(&self) -> Self::GetMetricsResponseFut;
562}
563#[derive(Debug)]
564#[cfg(target_os = "fuchsia")]
565pub struct InfoSynchronousProxy {
566    client: fidl::client::sync::Client,
567}
568
569#[cfg(target_os = "fuchsia")]
570impl fidl::endpoints::SynchronousProxy for InfoSynchronousProxy {
571    type Proxy = InfoProxy;
572    type Protocol = InfoMarker;
573
574    fn from_channel(inner: fidl::Channel) -> Self {
575        Self::new(inner)
576    }
577
578    fn into_channel(self) -> fidl::Channel {
579        self.client.into_channel()
580    }
581
582    fn as_channel(&self) -> &fidl::Channel {
583        self.client.as_channel()
584    }
585}
586
587#[cfg(target_os = "fuchsia")]
588impl InfoSynchronousProxy {
589    pub fn new(channel: fidl::Channel) -> Self {
590        let protocol_name = <InfoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
591        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
592    }
593
594    pub fn into_channel(self) -> fidl::Channel {
595        self.client.into_channel()
596    }
597
598    /// Waits until an event arrives and returns it. It is safe for other
599    /// threads to make concurrent requests while waiting for an event.
600    pub fn wait_for_event(&self, deadline: zx::MonotonicInstant) -> Result<InfoEvent, fidl::Error> {
601        InfoEvent::decode(self.client.wait_for_event(deadline)?)
602    }
603
604    pub fn r#get_metrics(&self, ___deadline: zx::MonotonicInstant) -> Result<Metrics, fidl::Error> {
605        let _response =
606            self.client.send_query::<fidl::encoding::EmptyPayload, InfoGetMetricsResponse>(
607                (),
608                0x6d631353834698be,
609                fidl::encoding::DynamicFlags::empty(),
610                ___deadline,
611            )?;
612        Ok(_response.info)
613    }
614}
615
616#[cfg(target_os = "fuchsia")]
617impl From<InfoSynchronousProxy> for zx::NullableHandle {
618    fn from(value: InfoSynchronousProxy) -> Self {
619        value.into_channel().into()
620    }
621}
622
623#[cfg(target_os = "fuchsia")]
624impl From<fidl::Channel> for InfoSynchronousProxy {
625    fn from(value: fidl::Channel) -> Self {
626        Self::new(value)
627    }
628}
629
630#[cfg(target_os = "fuchsia")]
631impl fidl::endpoints::FromClient for InfoSynchronousProxy {
632    type Protocol = InfoMarker;
633
634    fn from_client(value: fidl::endpoints::ClientEnd<InfoMarker>) -> Self {
635        Self::new(value.into_channel())
636    }
637}
638
639#[derive(Debug, Clone)]
640pub struct InfoProxy {
641    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
642}
643
644impl fidl::endpoints::Proxy for InfoProxy {
645    type Protocol = InfoMarker;
646
647    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
648        Self::new(inner)
649    }
650
651    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
652        self.client.into_channel().map_err(|client| Self { client })
653    }
654
655    fn as_channel(&self) -> &::fidl::AsyncChannel {
656        self.client.as_channel()
657    }
658}
659
660impl InfoProxy {
661    /// Create a new Proxy for fuchsia.ui.display.singleton/Info.
662    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
663        let protocol_name = <InfoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
664        Self { client: fidl::client::Client::new(channel, protocol_name) }
665    }
666
667    /// Get a Stream of events from the remote end of the protocol.
668    ///
669    /// # Panics
670    ///
671    /// Panics if the event stream was already taken.
672    pub fn take_event_stream(&self) -> InfoEventStream {
673        InfoEventStream { event_receiver: self.client.take_event_receiver() }
674    }
675
676    pub fn r#get_metrics(
677        &self,
678    ) -> fidl::client::QueryResponseFut<Metrics, fidl::encoding::DefaultFuchsiaResourceDialect>
679    {
680        InfoProxyInterface::r#get_metrics(self)
681    }
682}
683
684impl InfoProxyInterface for InfoProxy {
685    type GetMetricsResponseFut =
686        fidl::client::QueryResponseFut<Metrics, fidl::encoding::DefaultFuchsiaResourceDialect>;
687    fn r#get_metrics(&self) -> Self::GetMetricsResponseFut {
688        fn _decode(
689            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
690        ) -> Result<Metrics, fidl::Error> {
691            let _response = fidl::client::decode_transaction_body::<
692                InfoGetMetricsResponse,
693                fidl::encoding::DefaultFuchsiaResourceDialect,
694                0x6d631353834698be,
695            >(_buf?)?;
696            Ok(_response.info)
697        }
698        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Metrics>(
699            (),
700            0x6d631353834698be,
701            fidl::encoding::DynamicFlags::empty(),
702            _decode,
703        )
704    }
705}
706
707pub struct InfoEventStream {
708    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
709}
710
711impl std::marker::Unpin for InfoEventStream {}
712
713impl futures::stream::FusedStream for InfoEventStream {
714    fn is_terminated(&self) -> bool {
715        self.event_receiver.is_terminated()
716    }
717}
718
719impl futures::Stream for InfoEventStream {
720    type Item = Result<InfoEvent, fidl::Error>;
721
722    fn poll_next(
723        mut self: std::pin::Pin<&mut Self>,
724        cx: &mut std::task::Context<'_>,
725    ) -> std::task::Poll<Option<Self::Item>> {
726        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
727            &mut self.event_receiver,
728            cx
729        )?) {
730            Some(buf) => std::task::Poll::Ready(Some(InfoEvent::decode(buf))),
731            None => std::task::Poll::Ready(None),
732        }
733    }
734}
735
736#[derive(Debug)]
737pub enum InfoEvent {}
738
739impl InfoEvent {
740    /// Decodes a message buffer as a [`InfoEvent`].
741    fn decode(
742        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
743    ) -> Result<InfoEvent, fidl::Error> {
744        let (bytes, _handles) = buf.split_mut();
745        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
746        debug_assert_eq!(tx_header.tx_id, 0);
747        match tx_header.ordinal {
748            _ => Err(fidl::Error::UnknownOrdinal {
749                ordinal: tx_header.ordinal,
750                protocol_name: <InfoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
751            }),
752        }
753    }
754}
755
756/// A Stream of incoming requests for fuchsia.ui.display.singleton/Info.
757pub struct InfoRequestStream {
758    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
759    is_terminated: bool,
760}
761
762impl std::marker::Unpin for InfoRequestStream {}
763
764impl futures::stream::FusedStream for InfoRequestStream {
765    fn is_terminated(&self) -> bool {
766        self.is_terminated
767    }
768}
769
770impl fidl::endpoints::RequestStream for InfoRequestStream {
771    type Protocol = InfoMarker;
772    type ControlHandle = InfoControlHandle;
773
774    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
775        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
776    }
777
778    fn control_handle(&self) -> Self::ControlHandle {
779        InfoControlHandle { inner: self.inner.clone() }
780    }
781
782    fn into_inner(
783        self,
784    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
785    {
786        (self.inner, self.is_terminated)
787    }
788
789    fn from_inner(
790        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
791        is_terminated: bool,
792    ) -> Self {
793        Self { inner, is_terminated }
794    }
795}
796
797impl futures::Stream for InfoRequestStream {
798    type Item = Result<InfoRequest, fidl::Error>;
799
800    fn poll_next(
801        mut self: std::pin::Pin<&mut Self>,
802        cx: &mut std::task::Context<'_>,
803    ) -> std::task::Poll<Option<Self::Item>> {
804        let this = &mut *self;
805        if this.inner.check_shutdown(cx) {
806            this.is_terminated = true;
807            return std::task::Poll::Ready(None);
808        }
809        if this.is_terminated {
810            panic!("polled InfoRequestStream after completion");
811        }
812        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
813            |bytes, handles| {
814                match this.inner.channel().read_etc(cx, bytes, handles) {
815                    std::task::Poll::Ready(Ok(())) => {}
816                    std::task::Poll::Pending => return std::task::Poll::Pending,
817                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
818                        this.is_terminated = true;
819                        return std::task::Poll::Ready(None);
820                    }
821                    std::task::Poll::Ready(Err(e)) => {
822                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
823                            e.into(),
824                        ))));
825                    }
826                }
827
828                // A message has been received from the channel
829                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
830
831                std::task::Poll::Ready(Some(match header.ordinal {
832                    0x6d631353834698be => {
833                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
834                        let mut req = fidl::new_empty!(
835                            fidl::encoding::EmptyPayload,
836                            fidl::encoding::DefaultFuchsiaResourceDialect
837                        );
838                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
839                        let control_handle = InfoControlHandle { inner: this.inner.clone() };
840                        Ok(InfoRequest::GetMetrics {
841                            responder: InfoGetMetricsResponder {
842                                control_handle: std::mem::ManuallyDrop::new(control_handle),
843                                tx_id: header.tx_id,
844                            },
845                        })
846                    }
847                    _ => Err(fidl::Error::UnknownOrdinal {
848                        ordinal: header.ordinal,
849                        protocol_name: <InfoMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
850                    }),
851                }))
852            },
853        )
854    }
855}
856
857/// Get information about Scenic's primary display.
858#[derive(Debug)]
859pub enum InfoRequest {
860    GetMetrics { responder: InfoGetMetricsResponder },
861}
862
863impl InfoRequest {
864    #[allow(irrefutable_let_patterns)]
865    pub fn into_get_metrics(self) -> Option<(InfoGetMetricsResponder)> {
866        if let InfoRequest::GetMetrics { responder } = self { Some((responder)) } else { None }
867    }
868
869    /// Name of the method defined in FIDL
870    pub fn method_name(&self) -> &'static str {
871        match *self {
872            InfoRequest::GetMetrics { .. } => "get_metrics",
873        }
874    }
875}
876
877#[derive(Debug, Clone)]
878pub struct InfoControlHandle {
879    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
880}
881
882impl fidl::endpoints::ControlHandle for InfoControlHandle {
883    fn shutdown(&self) {
884        self.inner.shutdown()
885    }
886
887    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
888        self.inner.shutdown_with_epitaph(status)
889    }
890
891    fn is_closed(&self) -> bool {
892        self.inner.channel().is_closed()
893    }
894    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
895        self.inner.channel().on_closed()
896    }
897
898    #[cfg(target_os = "fuchsia")]
899    fn signal_peer(
900        &self,
901        clear_mask: zx::Signals,
902        set_mask: zx::Signals,
903    ) -> Result<(), zx_status::Status> {
904        use fidl::Peered;
905        self.inner.channel().signal_peer(clear_mask, set_mask)
906    }
907}
908
909impl InfoControlHandle {}
910
911#[must_use = "FIDL methods require a response to be sent"]
912#[derive(Debug)]
913pub struct InfoGetMetricsResponder {
914    control_handle: std::mem::ManuallyDrop<InfoControlHandle>,
915    tx_id: u32,
916}
917
918/// Set the the channel to be shutdown (see [`InfoControlHandle::shutdown`])
919/// if the responder is dropped without sending a response, so that the client
920/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
921impl std::ops::Drop for InfoGetMetricsResponder {
922    fn drop(&mut self) {
923        self.control_handle.shutdown();
924        // Safety: drops once, never accessed again
925        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
926    }
927}
928
929impl fidl::endpoints::Responder for InfoGetMetricsResponder {
930    type ControlHandle = InfoControlHandle;
931
932    fn control_handle(&self) -> &InfoControlHandle {
933        &self.control_handle
934    }
935
936    fn drop_without_shutdown(mut self) {
937        // Safety: drops once, never accessed again due to mem::forget
938        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
939        // Prevent Drop from running (which would shut down the channel)
940        std::mem::forget(self);
941    }
942}
943
944impl InfoGetMetricsResponder {
945    /// Sends a response to the FIDL transaction.
946    ///
947    /// Sets the channel to shutdown if an error occurs.
948    pub fn send(self, mut info: &Metrics) -> Result<(), fidl::Error> {
949        let _result = self.send_raw(info);
950        if _result.is_err() {
951            self.control_handle.shutdown();
952        }
953        self.drop_without_shutdown();
954        _result
955    }
956
957    /// Similar to "send" but does not shutdown the channel if an error occurs.
958    pub fn send_no_shutdown_on_err(self, mut info: &Metrics) -> Result<(), fidl::Error> {
959        let _result = self.send_raw(info);
960        self.drop_without_shutdown();
961        _result
962    }
963
964    fn send_raw(&self, mut info: &Metrics) -> Result<(), fidl::Error> {
965        self.control_handle.inner.send::<InfoGetMetricsResponse>(
966            (info,),
967            self.tx_id,
968            0x6d631353834698be,
969            fidl::encoding::DynamicFlags::empty(),
970        )
971    }
972}
973
974#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
975pub struct VsyncSourceMarker;
976
977impl fidl::endpoints::ProtocolMarker for VsyncSourceMarker {
978    type Proxy = VsyncSourceProxy;
979    type RequestStream = VsyncSourceRequestStream;
980    #[cfg(target_os = "fuchsia")]
981    type SynchronousProxy = VsyncSourceSynchronousProxy;
982
983    const DEBUG_NAME: &'static str = "fuchsia.ui.display.singleton.VsyncSource";
984}
985impl fidl::endpoints::DiscoverableProtocolMarker for VsyncSourceMarker {}
986
987pub trait VsyncSourceProxyInterface: Send + Sync {
988    fn r#set_vsync_enabled(&self, enabled: bool) -> Result<(), fidl::Error>;
989}
990#[derive(Debug)]
991#[cfg(target_os = "fuchsia")]
992pub struct VsyncSourceSynchronousProxy {
993    client: fidl::client::sync::Client,
994}
995
996#[cfg(target_os = "fuchsia")]
997impl fidl::endpoints::SynchronousProxy for VsyncSourceSynchronousProxy {
998    type Proxy = VsyncSourceProxy;
999    type Protocol = VsyncSourceMarker;
1000
1001    fn from_channel(inner: fidl::Channel) -> Self {
1002        Self::new(inner)
1003    }
1004
1005    fn into_channel(self) -> fidl::Channel {
1006        self.client.into_channel()
1007    }
1008
1009    fn as_channel(&self) -> &fidl::Channel {
1010        self.client.as_channel()
1011    }
1012}
1013
1014#[cfg(target_os = "fuchsia")]
1015impl VsyncSourceSynchronousProxy {
1016    pub fn new(channel: fidl::Channel) -> Self {
1017        let protocol_name = <VsyncSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1018        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1019    }
1020
1021    pub fn into_channel(self) -> fidl::Channel {
1022        self.client.into_channel()
1023    }
1024
1025    /// Waits until an event arrives and returns it. It is safe for other
1026    /// threads to make concurrent requests while waiting for an event.
1027    pub fn wait_for_event(
1028        &self,
1029        deadline: zx::MonotonicInstant,
1030    ) -> Result<VsyncSourceEvent, fidl::Error> {
1031        VsyncSourceEvent::decode(self.client.wait_for_event(deadline)?)
1032    }
1033
1034    /// Enables or disables receiving `OnVsync` for the given display.
1035    ///
1036    /// The client receives `OnVsync` callbacks iff this function is called with `enabled=true`.
1037    /// Calling this with `enabled=false` stops generating callbacks. Note that there may be a
1038    /// race with a server receiving this and extra `OnVsync` may be received.
1039    ///
1040    /// By default, the listener is assumed to have called `enabled=false`.
1041    pub fn r#set_vsync_enabled(&self, mut enabled: bool) -> Result<(), fidl::Error> {
1042        self.client.send::<VsyncSourceSetVsyncEnabledRequest>(
1043            (enabled,),
1044            0x5aaab140804e1b32,
1045            fidl::encoding::DynamicFlags::empty(),
1046        )
1047    }
1048}
1049
1050#[cfg(target_os = "fuchsia")]
1051impl From<VsyncSourceSynchronousProxy> for zx::NullableHandle {
1052    fn from(value: VsyncSourceSynchronousProxy) -> Self {
1053        value.into_channel().into()
1054    }
1055}
1056
1057#[cfg(target_os = "fuchsia")]
1058impl From<fidl::Channel> for VsyncSourceSynchronousProxy {
1059    fn from(value: fidl::Channel) -> Self {
1060        Self::new(value)
1061    }
1062}
1063
1064#[cfg(target_os = "fuchsia")]
1065impl fidl::endpoints::FromClient for VsyncSourceSynchronousProxy {
1066    type Protocol = VsyncSourceMarker;
1067
1068    fn from_client(value: fidl::endpoints::ClientEnd<VsyncSourceMarker>) -> Self {
1069        Self::new(value.into_channel())
1070    }
1071}
1072
1073#[derive(Debug, Clone)]
1074pub struct VsyncSourceProxy {
1075    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1076}
1077
1078impl fidl::endpoints::Proxy for VsyncSourceProxy {
1079    type Protocol = VsyncSourceMarker;
1080
1081    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1082        Self::new(inner)
1083    }
1084
1085    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1086        self.client.into_channel().map_err(|client| Self { client })
1087    }
1088
1089    fn as_channel(&self) -> &::fidl::AsyncChannel {
1090        self.client.as_channel()
1091    }
1092}
1093
1094impl VsyncSourceProxy {
1095    /// Create a new Proxy for fuchsia.ui.display.singleton/VsyncSource.
1096    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1097        let protocol_name = <VsyncSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1098        Self { client: fidl::client::Client::new(channel, protocol_name) }
1099    }
1100
1101    /// Get a Stream of events from the remote end of the protocol.
1102    ///
1103    /// # Panics
1104    ///
1105    /// Panics if the event stream was already taken.
1106    pub fn take_event_stream(&self) -> VsyncSourceEventStream {
1107        VsyncSourceEventStream { event_receiver: self.client.take_event_receiver() }
1108    }
1109
1110    /// Enables or disables receiving `OnVsync` for the given display.
1111    ///
1112    /// The client receives `OnVsync` callbacks iff this function is called with `enabled=true`.
1113    /// Calling this with `enabled=false` stops generating callbacks. Note that there may be a
1114    /// race with a server receiving this and extra `OnVsync` may be received.
1115    ///
1116    /// By default, the listener is assumed to have called `enabled=false`.
1117    pub fn r#set_vsync_enabled(&self, mut enabled: bool) -> Result<(), fidl::Error> {
1118        VsyncSourceProxyInterface::r#set_vsync_enabled(self, enabled)
1119    }
1120}
1121
1122impl VsyncSourceProxyInterface for VsyncSourceProxy {
1123    fn r#set_vsync_enabled(&self, mut enabled: bool) -> Result<(), fidl::Error> {
1124        self.client.send::<VsyncSourceSetVsyncEnabledRequest>(
1125            (enabled,),
1126            0x5aaab140804e1b32,
1127            fidl::encoding::DynamicFlags::empty(),
1128        )
1129    }
1130}
1131
1132pub struct VsyncSourceEventStream {
1133    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1134}
1135
1136impl std::marker::Unpin for VsyncSourceEventStream {}
1137
1138impl futures::stream::FusedStream for VsyncSourceEventStream {
1139    fn is_terminated(&self) -> bool {
1140        self.event_receiver.is_terminated()
1141    }
1142}
1143
1144impl futures::Stream for VsyncSourceEventStream {
1145    type Item = Result<VsyncSourceEvent, fidl::Error>;
1146
1147    fn poll_next(
1148        mut self: std::pin::Pin<&mut Self>,
1149        cx: &mut std::task::Context<'_>,
1150    ) -> std::task::Poll<Option<Self::Item>> {
1151        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1152            &mut self.event_receiver,
1153            cx
1154        )?) {
1155            Some(buf) => std::task::Poll::Ready(Some(VsyncSourceEvent::decode(buf))),
1156            None => std::task::Poll::Ready(None),
1157        }
1158    }
1159}
1160
1161#[derive(Debug)]
1162pub enum VsyncSourceEvent {
1163    OnVsync { timestamp: i64 },
1164}
1165
1166impl VsyncSourceEvent {
1167    #[allow(irrefutable_let_patterns)]
1168    pub fn into_on_vsync(self) -> Option<i64> {
1169        if let VsyncSourceEvent::OnVsync { timestamp } = self { Some((timestamp)) } else { None }
1170    }
1171
1172    /// Decodes a message buffer as a [`VsyncSourceEvent`].
1173    fn decode(
1174        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1175    ) -> Result<VsyncSourceEvent, fidl::Error> {
1176        let (bytes, _handles) = buf.split_mut();
1177        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1178        debug_assert_eq!(tx_header.tx_id, 0);
1179        match tx_header.ordinal {
1180            0x6677c178c3451448 => {
1181                let mut out = fidl::new_empty!(
1182                    VsyncSourceOnVsyncRequest,
1183                    fidl::encoding::DefaultFuchsiaResourceDialect
1184                );
1185                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VsyncSourceOnVsyncRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
1186                Ok((VsyncSourceEvent::OnVsync { timestamp: out.timestamp }))
1187            }
1188            _ => Err(fidl::Error::UnknownOrdinal {
1189                ordinal: tx_header.ordinal,
1190                protocol_name: <VsyncSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1191            }),
1192        }
1193    }
1194}
1195
1196/// A Stream of incoming requests for fuchsia.ui.display.singleton/VsyncSource.
1197pub struct VsyncSourceRequestStream {
1198    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1199    is_terminated: bool,
1200}
1201
1202impl std::marker::Unpin for VsyncSourceRequestStream {}
1203
1204impl futures::stream::FusedStream for VsyncSourceRequestStream {
1205    fn is_terminated(&self) -> bool {
1206        self.is_terminated
1207    }
1208}
1209
1210impl fidl::endpoints::RequestStream for VsyncSourceRequestStream {
1211    type Protocol = VsyncSourceMarker;
1212    type ControlHandle = VsyncSourceControlHandle;
1213
1214    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1215        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1216    }
1217
1218    fn control_handle(&self) -> Self::ControlHandle {
1219        VsyncSourceControlHandle { inner: self.inner.clone() }
1220    }
1221
1222    fn into_inner(
1223        self,
1224    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1225    {
1226        (self.inner, self.is_terminated)
1227    }
1228
1229    fn from_inner(
1230        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1231        is_terminated: bool,
1232    ) -> Self {
1233        Self { inner, is_terminated }
1234    }
1235}
1236
1237impl futures::Stream for VsyncSourceRequestStream {
1238    type Item = Result<VsyncSourceRequest, fidl::Error>;
1239
1240    fn poll_next(
1241        mut self: std::pin::Pin<&mut Self>,
1242        cx: &mut std::task::Context<'_>,
1243    ) -> std::task::Poll<Option<Self::Item>> {
1244        let this = &mut *self;
1245        if this.inner.check_shutdown(cx) {
1246            this.is_terminated = true;
1247            return std::task::Poll::Ready(None);
1248        }
1249        if this.is_terminated {
1250            panic!("polled VsyncSourceRequestStream after completion");
1251        }
1252        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1253            |bytes, handles| {
1254                match this.inner.channel().read_etc(cx, bytes, handles) {
1255                    std::task::Poll::Ready(Ok(())) => {}
1256                    std::task::Poll::Pending => return std::task::Poll::Pending,
1257                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1258                        this.is_terminated = true;
1259                        return std::task::Poll::Ready(None);
1260                    }
1261                    std::task::Poll::Ready(Err(e)) => {
1262                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1263                            e.into(),
1264                        ))));
1265                    }
1266                }
1267
1268                // A message has been received from the channel
1269                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1270
1271                std::task::Poll::Ready(Some(match header.ordinal {
1272                    0x5aaab140804e1b32 => {
1273                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1274                        let mut req = fidl::new_empty!(
1275                            VsyncSourceSetVsyncEnabledRequest,
1276                            fidl::encoding::DefaultFuchsiaResourceDialect
1277                        );
1278                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<VsyncSourceSetVsyncEnabledRequest>(&header, _body_bytes, handles, &mut req)?;
1279                        let control_handle = VsyncSourceControlHandle { inner: this.inner.clone() };
1280                        Ok(VsyncSourceRequest::SetVsyncEnabled {
1281                            enabled: req.enabled,
1282
1283                            control_handle,
1284                        })
1285                    }
1286                    _ => Err(fidl::Error::UnknownOrdinal {
1287                        ordinal: header.ordinal,
1288                        protocol_name:
1289                            <VsyncSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1290                    }),
1291                }))
1292            },
1293        )
1294    }
1295}
1296
1297#[derive(Debug)]
1298pub enum VsyncSourceRequest {
1299    /// Enables or disables receiving `OnVsync` for the given display.
1300    ///
1301    /// The client receives `OnVsync` callbacks iff this function is called with `enabled=true`.
1302    /// Calling this with `enabled=false` stops generating callbacks. Note that there may be a
1303    /// race with a server receiving this and extra `OnVsync` may be received.
1304    ///
1305    /// By default, the listener is assumed to have called `enabled=false`.
1306    SetVsyncEnabled { enabled: bool, control_handle: VsyncSourceControlHandle },
1307}
1308
1309impl VsyncSourceRequest {
1310    #[allow(irrefutable_let_patterns)]
1311    pub fn into_set_vsync_enabled(self) -> Option<(bool, VsyncSourceControlHandle)> {
1312        if let VsyncSourceRequest::SetVsyncEnabled { enabled, control_handle } = self {
1313            Some((enabled, control_handle))
1314        } else {
1315            None
1316        }
1317    }
1318
1319    /// Name of the method defined in FIDL
1320    pub fn method_name(&self) -> &'static str {
1321        match *self {
1322            VsyncSourceRequest::SetVsyncEnabled { .. } => "set_vsync_enabled",
1323        }
1324    }
1325}
1326
1327#[derive(Debug, Clone)]
1328pub struct VsyncSourceControlHandle {
1329    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1330}
1331
1332impl fidl::endpoints::ControlHandle for VsyncSourceControlHandle {
1333    fn shutdown(&self) {
1334        self.inner.shutdown()
1335    }
1336
1337    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1338        self.inner.shutdown_with_epitaph(status)
1339    }
1340
1341    fn is_closed(&self) -> bool {
1342        self.inner.channel().is_closed()
1343    }
1344    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1345        self.inner.channel().on_closed()
1346    }
1347
1348    #[cfg(target_os = "fuchsia")]
1349    fn signal_peer(
1350        &self,
1351        clear_mask: zx::Signals,
1352        set_mask: zx::Signals,
1353    ) -> Result<(), zx_status::Status> {
1354        use fidl::Peered;
1355        self.inner.channel().signal_peer(clear_mask, set_mask)
1356    }
1357}
1358
1359impl VsyncSourceControlHandle {
1360    pub fn send_on_vsync(&self, mut timestamp: i64) -> Result<(), fidl::Error> {
1361        self.inner.send::<VsyncSourceOnVsyncRequest>(
1362            (timestamp,),
1363            0,
1364            0x6677c178c3451448,
1365            fidl::encoding::DynamicFlags::empty(),
1366        )
1367    }
1368}
1369
1370mod internal {
1371    use super::*;
1372}