fidl_fuchsia_ui_activity/
fidl_fuchsia_ui_activity.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_activity__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct ProviderWatchStateRequest {
16    pub listener: fidl::endpoints::ClientEnd<ListenerMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ProviderWatchStateRequest {}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
22pub struct ListenerMarker;
23
24impl fidl::endpoints::ProtocolMarker for ListenerMarker {
25    type Proxy = ListenerProxy;
26    type RequestStream = ListenerRequestStream;
27    #[cfg(target_os = "fuchsia")]
28    type SynchronousProxy = ListenerSynchronousProxy;
29
30    const DEBUG_NAME: &'static str = "(anonymous) Listener";
31}
32
33pub trait ListenerProxyInterface: Send + Sync {
34    type OnStateChangedResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
35    fn r#on_state_changed(
36        &self,
37        state: State,
38        transition_time: i64,
39    ) -> Self::OnStateChangedResponseFut;
40}
41#[derive(Debug)]
42#[cfg(target_os = "fuchsia")]
43pub struct ListenerSynchronousProxy {
44    client: fidl::client::sync::Client,
45}
46
47#[cfg(target_os = "fuchsia")]
48impl fidl::endpoints::SynchronousProxy for ListenerSynchronousProxy {
49    type Proxy = ListenerProxy;
50    type Protocol = ListenerMarker;
51
52    fn from_channel(inner: fidl::Channel) -> Self {
53        Self::new(inner)
54    }
55
56    fn into_channel(self) -> fidl::Channel {
57        self.client.into_channel()
58    }
59
60    fn as_channel(&self) -> &fidl::Channel {
61        self.client.as_channel()
62    }
63}
64
65#[cfg(target_os = "fuchsia")]
66impl ListenerSynchronousProxy {
67    pub fn new(channel: fidl::Channel) -> Self {
68        let protocol_name = <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
69        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
70    }
71
72    pub fn into_channel(self) -> fidl::Channel {
73        self.client.into_channel()
74    }
75
76    /// Waits until an event arrives and returns it. It is safe for other
77    /// threads to make concurrent requests while waiting for an event.
78    pub fn wait_for_event(
79        &self,
80        deadline: zx::MonotonicInstant,
81    ) -> Result<ListenerEvent, fidl::Error> {
82        ListenerEvent::decode(self.client.wait_for_event(deadline)?)
83    }
84
85    /// Callback that is invoked whenever the system state changes.
86    /// The Listener is expected to acknowledge each call explicitly and will
87    /// not receive new state until this acknowledgement is done.
88    pub fn r#on_state_changed(
89        &self,
90        mut state: State,
91        mut transition_time: i64,
92        ___deadline: zx::MonotonicInstant,
93    ) -> Result<(), fidl::Error> {
94        let _response =
95            self.client.send_query::<ListenerOnStateChangedRequest, fidl::encoding::EmptyPayload>(
96                (state, transition_time),
97                0xf74db3e6d5ba415,
98                fidl::encoding::DynamicFlags::empty(),
99                ___deadline,
100            )?;
101        Ok(_response)
102    }
103}
104
105#[cfg(target_os = "fuchsia")]
106impl From<ListenerSynchronousProxy> for zx::NullableHandle {
107    fn from(value: ListenerSynchronousProxy) -> Self {
108        value.into_channel().into()
109    }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl From<fidl::Channel> for ListenerSynchronousProxy {
114    fn from(value: fidl::Channel) -> Self {
115        Self::new(value)
116    }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl fidl::endpoints::FromClient for ListenerSynchronousProxy {
121    type Protocol = ListenerMarker;
122
123    fn from_client(value: fidl::endpoints::ClientEnd<ListenerMarker>) -> Self {
124        Self::new(value.into_channel())
125    }
126}
127
128#[derive(Debug, Clone)]
129pub struct ListenerProxy {
130    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
131}
132
133impl fidl::endpoints::Proxy for ListenerProxy {
134    type Protocol = ListenerMarker;
135
136    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
137        Self::new(inner)
138    }
139
140    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
141        self.client.into_channel().map_err(|client| Self { client })
142    }
143
144    fn as_channel(&self) -> &::fidl::AsyncChannel {
145        self.client.as_channel()
146    }
147}
148
149impl ListenerProxy {
150    /// Create a new Proxy for fuchsia.ui.activity/Listener.
151    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
152        let protocol_name = <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
153        Self { client: fidl::client::Client::new(channel, protocol_name) }
154    }
155
156    /// Get a Stream of events from the remote end of the protocol.
157    ///
158    /// # Panics
159    ///
160    /// Panics if the event stream was already taken.
161    pub fn take_event_stream(&self) -> ListenerEventStream {
162        ListenerEventStream { event_receiver: self.client.take_event_receiver() }
163    }
164
165    /// Callback that is invoked whenever the system state changes.
166    /// The Listener is expected to acknowledge each call explicitly and will
167    /// not receive new state until this acknowledgement is done.
168    pub fn r#on_state_changed(
169        &self,
170        mut state: State,
171        mut transition_time: i64,
172    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
173        ListenerProxyInterface::r#on_state_changed(self, state, transition_time)
174    }
175}
176
177impl ListenerProxyInterface for ListenerProxy {
178    type OnStateChangedResponseFut =
179        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
180    fn r#on_state_changed(
181        &self,
182        mut state: State,
183        mut transition_time: i64,
184    ) -> Self::OnStateChangedResponseFut {
185        fn _decode(
186            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
187        ) -> Result<(), fidl::Error> {
188            let _response = fidl::client::decode_transaction_body::<
189                fidl::encoding::EmptyPayload,
190                fidl::encoding::DefaultFuchsiaResourceDialect,
191                0xf74db3e6d5ba415,
192            >(_buf?)?;
193            Ok(_response)
194        }
195        self.client.send_query_and_decode::<ListenerOnStateChangedRequest, ()>(
196            (state, transition_time),
197            0xf74db3e6d5ba415,
198            fidl::encoding::DynamicFlags::empty(),
199            _decode,
200        )
201    }
202}
203
204pub struct ListenerEventStream {
205    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
206}
207
208impl std::marker::Unpin for ListenerEventStream {}
209
210impl futures::stream::FusedStream for ListenerEventStream {
211    fn is_terminated(&self) -> bool {
212        self.event_receiver.is_terminated()
213    }
214}
215
216impl futures::Stream for ListenerEventStream {
217    type Item = Result<ListenerEvent, fidl::Error>;
218
219    fn poll_next(
220        mut self: std::pin::Pin<&mut Self>,
221        cx: &mut std::task::Context<'_>,
222    ) -> std::task::Poll<Option<Self::Item>> {
223        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
224            &mut self.event_receiver,
225            cx
226        )?) {
227            Some(buf) => std::task::Poll::Ready(Some(ListenerEvent::decode(buf))),
228            None => std::task::Poll::Ready(None),
229        }
230    }
231}
232
233#[derive(Debug)]
234pub enum ListenerEvent {}
235
236impl ListenerEvent {
237    /// Decodes a message buffer as a [`ListenerEvent`].
238    fn decode(
239        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
240    ) -> Result<ListenerEvent, fidl::Error> {
241        let (bytes, _handles) = buf.split_mut();
242        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
243        debug_assert_eq!(tx_header.tx_id, 0);
244        match tx_header.ordinal {
245            _ => Err(fidl::Error::UnknownOrdinal {
246                ordinal: tx_header.ordinal,
247                protocol_name: <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
248            }),
249        }
250    }
251}
252
253/// A Stream of incoming requests for fuchsia.ui.activity/Listener.
254pub struct ListenerRequestStream {
255    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
256    is_terminated: bool,
257}
258
259impl std::marker::Unpin for ListenerRequestStream {}
260
261impl futures::stream::FusedStream for ListenerRequestStream {
262    fn is_terminated(&self) -> bool {
263        self.is_terminated
264    }
265}
266
267impl fidl::endpoints::RequestStream for ListenerRequestStream {
268    type Protocol = ListenerMarker;
269    type ControlHandle = ListenerControlHandle;
270
271    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
272        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
273    }
274
275    fn control_handle(&self) -> Self::ControlHandle {
276        ListenerControlHandle { inner: self.inner.clone() }
277    }
278
279    fn into_inner(
280        self,
281    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
282    {
283        (self.inner, self.is_terminated)
284    }
285
286    fn from_inner(
287        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
288        is_terminated: bool,
289    ) -> Self {
290        Self { inner, is_terminated }
291    }
292}
293
294impl futures::Stream for ListenerRequestStream {
295    type Item = Result<ListenerRequest, fidl::Error>;
296
297    fn poll_next(
298        mut self: std::pin::Pin<&mut Self>,
299        cx: &mut std::task::Context<'_>,
300    ) -> std::task::Poll<Option<Self::Item>> {
301        let this = &mut *self;
302        if this.inner.check_shutdown(cx) {
303            this.is_terminated = true;
304            return std::task::Poll::Ready(None);
305        }
306        if this.is_terminated {
307            panic!("polled ListenerRequestStream after completion");
308        }
309        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
310            |bytes, handles| {
311                match this.inner.channel().read_etc(cx, bytes, handles) {
312                    std::task::Poll::Ready(Ok(())) => {}
313                    std::task::Poll::Pending => return std::task::Poll::Pending,
314                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
315                        this.is_terminated = true;
316                        return std::task::Poll::Ready(None);
317                    }
318                    std::task::Poll::Ready(Err(e)) => {
319                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
320                            e.into(),
321                        ))));
322                    }
323                }
324
325                // A message has been received from the channel
326                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
327
328                std::task::Poll::Ready(Some(match header.ordinal {
329                    0xf74db3e6d5ba415 => {
330                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
331                        let mut req = fidl::new_empty!(
332                            ListenerOnStateChangedRequest,
333                            fidl::encoding::DefaultFuchsiaResourceDialect
334                        );
335                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ListenerOnStateChangedRequest>(&header, _body_bytes, handles, &mut req)?;
336                        let control_handle = ListenerControlHandle { inner: this.inner.clone() };
337                        Ok(ListenerRequest::OnStateChanged {
338                            state: req.state,
339                            transition_time: req.transition_time,
340
341                            responder: ListenerOnStateChangedResponder {
342                                control_handle: std::mem::ManuallyDrop::new(control_handle),
343                                tx_id: header.tx_id,
344                            },
345                        })
346                    }
347                    _ => Err(fidl::Error::UnknownOrdinal {
348                        ordinal: header.ordinal,
349                        protocol_name:
350                            <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
351                    }),
352                }))
353            },
354        )
355    }
356}
357
358/// The Listener protocol subscribes to changes in the system's activity
359/// state. Clients which care about the activity state of the system are
360/// expected to implement this protocol and subscribe via Provider.WatchState.
361#[derive(Debug)]
362pub enum ListenerRequest {
363    /// Callback that is invoked whenever the system state changes.
364    /// The Listener is expected to acknowledge each call explicitly and will
365    /// not receive new state until this acknowledgement is done.
366    OnStateChanged {
367        state: State,
368        transition_time: i64,
369        responder: ListenerOnStateChangedResponder,
370    },
371}
372
373impl ListenerRequest {
374    #[allow(irrefutable_let_patterns)]
375    pub fn into_on_state_changed(self) -> Option<(State, i64, ListenerOnStateChangedResponder)> {
376        if let ListenerRequest::OnStateChanged { state, transition_time, responder } = self {
377            Some((state, transition_time, responder))
378        } else {
379            None
380        }
381    }
382
383    /// Name of the method defined in FIDL
384    pub fn method_name(&self) -> &'static str {
385        match *self {
386            ListenerRequest::OnStateChanged { .. } => "on_state_changed",
387        }
388    }
389}
390
391#[derive(Debug, Clone)]
392pub struct ListenerControlHandle {
393    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
394}
395
396impl fidl::endpoints::ControlHandle for ListenerControlHandle {
397    fn shutdown(&self) {
398        self.inner.shutdown()
399    }
400
401    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
402        self.inner.shutdown_with_epitaph(status)
403    }
404
405    fn is_closed(&self) -> bool {
406        self.inner.channel().is_closed()
407    }
408    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
409        self.inner.channel().on_closed()
410    }
411
412    #[cfg(target_os = "fuchsia")]
413    fn signal_peer(
414        &self,
415        clear_mask: zx::Signals,
416        set_mask: zx::Signals,
417    ) -> Result<(), zx_status::Status> {
418        use fidl::Peered;
419        self.inner.channel().signal_peer(clear_mask, set_mask)
420    }
421}
422
423impl ListenerControlHandle {}
424
425#[must_use = "FIDL methods require a response to be sent"]
426#[derive(Debug)]
427pub struct ListenerOnStateChangedResponder {
428    control_handle: std::mem::ManuallyDrop<ListenerControlHandle>,
429    tx_id: u32,
430}
431
432/// Set the the channel to be shutdown (see [`ListenerControlHandle::shutdown`])
433/// if the responder is dropped without sending a response, so that the client
434/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
435impl std::ops::Drop for ListenerOnStateChangedResponder {
436    fn drop(&mut self) {
437        self.control_handle.shutdown();
438        // Safety: drops once, never accessed again
439        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
440    }
441}
442
443impl fidl::endpoints::Responder for ListenerOnStateChangedResponder {
444    type ControlHandle = ListenerControlHandle;
445
446    fn control_handle(&self) -> &ListenerControlHandle {
447        &self.control_handle
448    }
449
450    fn drop_without_shutdown(mut self) {
451        // Safety: drops once, never accessed again due to mem::forget
452        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
453        // Prevent Drop from running (which would shut down the channel)
454        std::mem::forget(self);
455    }
456}
457
458impl ListenerOnStateChangedResponder {
459    /// Sends a response to the FIDL transaction.
460    ///
461    /// Sets the channel to shutdown if an error occurs.
462    pub fn send(self) -> Result<(), fidl::Error> {
463        let _result = self.send_raw();
464        if _result.is_err() {
465            self.control_handle.shutdown();
466        }
467        self.drop_without_shutdown();
468        _result
469    }
470
471    /// Similar to "send" but does not shutdown the channel if an error occurs.
472    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
473        let _result = self.send_raw();
474        self.drop_without_shutdown();
475        _result
476    }
477
478    fn send_raw(&self) -> Result<(), fidl::Error> {
479        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
480            (),
481            self.tx_id,
482            0xf74db3e6d5ba415,
483            fidl::encoding::DynamicFlags::empty(),
484        )
485    }
486}
487
488#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
489pub struct ProviderMarker;
490
491impl fidl::endpoints::ProtocolMarker for ProviderMarker {
492    type Proxy = ProviderProxy;
493    type RequestStream = ProviderRequestStream;
494    #[cfg(target_os = "fuchsia")]
495    type SynchronousProxy = ProviderSynchronousProxy;
496
497    const DEBUG_NAME: &'static str = "fuchsia.ui.activity.Provider";
498}
499impl fidl::endpoints::DiscoverableProtocolMarker for ProviderMarker {}
500
501pub trait ProviderProxyInterface: Send + Sync {
502    fn r#watch_state(
503        &self,
504        listener: fidl::endpoints::ClientEnd<ListenerMarker>,
505    ) -> Result<(), fidl::Error>;
506}
507#[derive(Debug)]
508#[cfg(target_os = "fuchsia")]
509pub struct ProviderSynchronousProxy {
510    client: fidl::client::sync::Client,
511}
512
513#[cfg(target_os = "fuchsia")]
514impl fidl::endpoints::SynchronousProxy for ProviderSynchronousProxy {
515    type Proxy = ProviderProxy;
516    type Protocol = ProviderMarker;
517
518    fn from_channel(inner: fidl::Channel) -> Self {
519        Self::new(inner)
520    }
521
522    fn into_channel(self) -> fidl::Channel {
523        self.client.into_channel()
524    }
525
526    fn as_channel(&self) -> &fidl::Channel {
527        self.client.as_channel()
528    }
529}
530
531#[cfg(target_os = "fuchsia")]
532impl ProviderSynchronousProxy {
533    pub fn new(channel: fidl::Channel) -> Self {
534        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
535        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
536    }
537
538    pub fn into_channel(self) -> fidl::Channel {
539        self.client.into_channel()
540    }
541
542    /// Waits until an event arrives and returns it. It is safe for other
543    /// threads to make concurrent requests while waiting for an event.
544    pub fn wait_for_event(
545        &self,
546        deadline: zx::MonotonicInstant,
547    ) -> Result<ProviderEvent, fidl::Error> {
548        ProviderEvent::decode(self.client.wait_for_event(deadline)?)
549    }
550
551    /// Subscribe to changes in the system's state.
552    /// The server will always invoke listener.OnStateChanged at least once with
553    /// the initial state, and after that invoke listener.OnStateChanged
554    /// whenever the system's state changes.
555    pub fn r#watch_state(
556        &self,
557        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
558    ) -> Result<(), fidl::Error> {
559        self.client.send::<ProviderWatchStateRequest>(
560            (listener,),
561            0x592e25a4cbe7f884,
562            fidl::encoding::DynamicFlags::empty(),
563        )
564    }
565}
566
567#[cfg(target_os = "fuchsia")]
568impl From<ProviderSynchronousProxy> for zx::NullableHandle {
569    fn from(value: ProviderSynchronousProxy) -> Self {
570        value.into_channel().into()
571    }
572}
573
574#[cfg(target_os = "fuchsia")]
575impl From<fidl::Channel> for ProviderSynchronousProxy {
576    fn from(value: fidl::Channel) -> Self {
577        Self::new(value)
578    }
579}
580
581#[cfg(target_os = "fuchsia")]
582impl fidl::endpoints::FromClient for ProviderSynchronousProxy {
583    type Protocol = ProviderMarker;
584
585    fn from_client(value: fidl::endpoints::ClientEnd<ProviderMarker>) -> Self {
586        Self::new(value.into_channel())
587    }
588}
589
590#[derive(Debug, Clone)]
591pub struct ProviderProxy {
592    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
593}
594
595impl fidl::endpoints::Proxy for ProviderProxy {
596    type Protocol = ProviderMarker;
597
598    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
599        Self::new(inner)
600    }
601
602    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
603        self.client.into_channel().map_err(|client| Self { client })
604    }
605
606    fn as_channel(&self) -> &::fidl::AsyncChannel {
607        self.client.as_channel()
608    }
609}
610
611impl ProviderProxy {
612    /// Create a new Proxy for fuchsia.ui.activity/Provider.
613    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
614        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
615        Self { client: fidl::client::Client::new(channel, protocol_name) }
616    }
617
618    /// Get a Stream of events from the remote end of the protocol.
619    ///
620    /// # Panics
621    ///
622    /// Panics if the event stream was already taken.
623    pub fn take_event_stream(&self) -> ProviderEventStream {
624        ProviderEventStream { event_receiver: self.client.take_event_receiver() }
625    }
626
627    /// Subscribe to changes in the system's state.
628    /// The server will always invoke listener.OnStateChanged at least once with
629    /// the initial state, and after that invoke listener.OnStateChanged
630    /// whenever the system's state changes.
631    pub fn r#watch_state(
632        &self,
633        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
634    ) -> Result<(), fidl::Error> {
635        ProviderProxyInterface::r#watch_state(self, listener)
636    }
637}
638
639impl ProviderProxyInterface for ProviderProxy {
640    fn r#watch_state(
641        &self,
642        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
643    ) -> Result<(), fidl::Error> {
644        self.client.send::<ProviderWatchStateRequest>(
645            (listener,),
646            0x592e25a4cbe7f884,
647            fidl::encoding::DynamicFlags::empty(),
648        )
649    }
650}
651
652pub struct ProviderEventStream {
653    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
654}
655
656impl std::marker::Unpin for ProviderEventStream {}
657
658impl futures::stream::FusedStream for ProviderEventStream {
659    fn is_terminated(&self) -> bool {
660        self.event_receiver.is_terminated()
661    }
662}
663
664impl futures::Stream for ProviderEventStream {
665    type Item = Result<ProviderEvent, fidl::Error>;
666
667    fn poll_next(
668        mut self: std::pin::Pin<&mut Self>,
669        cx: &mut std::task::Context<'_>,
670    ) -> std::task::Poll<Option<Self::Item>> {
671        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
672            &mut self.event_receiver,
673            cx
674        )?) {
675            Some(buf) => std::task::Poll::Ready(Some(ProviderEvent::decode(buf))),
676            None => std::task::Poll::Ready(None),
677        }
678    }
679}
680
681#[derive(Debug)]
682pub enum ProviderEvent {}
683
684impl ProviderEvent {
685    /// Decodes a message buffer as a [`ProviderEvent`].
686    fn decode(
687        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
688    ) -> Result<ProviderEvent, fidl::Error> {
689        let (bytes, _handles) = buf.split_mut();
690        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
691        debug_assert_eq!(tx_header.tx_id, 0);
692        match tx_header.ordinal {
693            _ => Err(fidl::Error::UnknownOrdinal {
694                ordinal: tx_header.ordinal,
695                protocol_name: <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
696            }),
697        }
698    }
699}
700
701/// A Stream of incoming requests for fuchsia.ui.activity/Provider.
702pub struct ProviderRequestStream {
703    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
704    is_terminated: bool,
705}
706
707impl std::marker::Unpin for ProviderRequestStream {}
708
709impl futures::stream::FusedStream for ProviderRequestStream {
710    fn is_terminated(&self) -> bool {
711        self.is_terminated
712    }
713}
714
715impl fidl::endpoints::RequestStream for ProviderRequestStream {
716    type Protocol = ProviderMarker;
717    type ControlHandle = ProviderControlHandle;
718
719    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
720        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
721    }
722
723    fn control_handle(&self) -> Self::ControlHandle {
724        ProviderControlHandle { inner: self.inner.clone() }
725    }
726
727    fn into_inner(
728        self,
729    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
730    {
731        (self.inner, self.is_terminated)
732    }
733
734    fn from_inner(
735        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
736        is_terminated: bool,
737    ) -> Self {
738        Self { inner, is_terminated }
739    }
740}
741
742impl futures::Stream for ProviderRequestStream {
743    type Item = Result<ProviderRequest, fidl::Error>;
744
745    fn poll_next(
746        mut self: std::pin::Pin<&mut Self>,
747        cx: &mut std::task::Context<'_>,
748    ) -> std::task::Poll<Option<Self::Item>> {
749        let this = &mut *self;
750        if this.inner.check_shutdown(cx) {
751            this.is_terminated = true;
752            return std::task::Poll::Ready(None);
753        }
754        if this.is_terminated {
755            panic!("polled ProviderRequestStream after completion");
756        }
757        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
758            |bytes, handles| {
759                match this.inner.channel().read_etc(cx, bytes, handles) {
760                    std::task::Poll::Ready(Ok(())) => {}
761                    std::task::Poll::Pending => return std::task::Poll::Pending,
762                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
763                        this.is_terminated = true;
764                        return std::task::Poll::Ready(None);
765                    }
766                    std::task::Poll::Ready(Err(e)) => {
767                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
768                            e.into(),
769                        ))));
770                    }
771                }
772
773                // A message has been received from the channel
774                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
775
776                std::task::Poll::Ready(Some(match header.ordinal {
777                    0x592e25a4cbe7f884 => {
778                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
779                        let mut req = fidl::new_empty!(
780                            ProviderWatchStateRequest,
781                            fidl::encoding::DefaultFuchsiaResourceDialect
782                        );
783                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderWatchStateRequest>(&header, _body_bytes, handles, &mut req)?;
784                        let control_handle = ProviderControlHandle { inner: this.inner.clone() };
785                        Ok(ProviderRequest::WatchState { listener: req.listener, control_handle })
786                    }
787                    _ => Err(fidl::Error::UnknownOrdinal {
788                        ordinal: header.ordinal,
789                        protocol_name:
790                            <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
791                    }),
792                }))
793            },
794        )
795    }
796}
797
798/// The Provider protocol offers a subscription interface through
799/// which clients can watch for changes in the system's activity state.
800#[derive(Debug)]
801pub enum ProviderRequest {
802    /// Subscribe to changes in the system's state.
803    /// The server will always invoke listener.OnStateChanged at least once with
804    /// the initial state, and after that invoke listener.OnStateChanged
805    /// whenever the system's state changes.
806    WatchState {
807        listener: fidl::endpoints::ClientEnd<ListenerMarker>,
808        control_handle: ProviderControlHandle,
809    },
810}
811
812impl ProviderRequest {
813    #[allow(irrefutable_let_patterns)]
814    pub fn into_watch_state(
815        self,
816    ) -> Option<(fidl::endpoints::ClientEnd<ListenerMarker>, ProviderControlHandle)> {
817        if let ProviderRequest::WatchState { listener, control_handle } = self {
818            Some((listener, control_handle))
819        } else {
820            None
821        }
822    }
823
824    /// Name of the method defined in FIDL
825    pub fn method_name(&self) -> &'static str {
826        match *self {
827            ProviderRequest::WatchState { .. } => "watch_state",
828        }
829    }
830}
831
832#[derive(Debug, Clone)]
833pub struct ProviderControlHandle {
834    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
835}
836
837impl fidl::endpoints::ControlHandle for ProviderControlHandle {
838    fn shutdown(&self) {
839        self.inner.shutdown()
840    }
841
842    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
843        self.inner.shutdown_with_epitaph(status)
844    }
845
846    fn is_closed(&self) -> bool {
847        self.inner.channel().is_closed()
848    }
849    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
850        self.inner.channel().on_closed()
851    }
852
853    #[cfg(target_os = "fuchsia")]
854    fn signal_peer(
855        &self,
856        clear_mask: zx::Signals,
857        set_mask: zx::Signals,
858    ) -> Result<(), zx_status::Status> {
859        use fidl::Peered;
860        self.inner.channel().signal_peer(clear_mask, set_mask)
861    }
862}
863
864impl ProviderControlHandle {}
865
866mod internal {
867    use super::*;
868
869    impl fidl::encoding::ResourceTypeMarker for ProviderWatchStateRequest {
870        type Borrowed<'a> = &'a mut Self;
871        fn take_or_borrow<'a>(
872            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
873        ) -> Self::Borrowed<'a> {
874            value
875        }
876    }
877
878    unsafe impl fidl::encoding::TypeMarker for ProviderWatchStateRequest {
879        type Owned = Self;
880
881        #[inline(always)]
882        fn inline_align(_context: fidl::encoding::Context) -> usize {
883            4
884        }
885
886        #[inline(always)]
887        fn inline_size(_context: fidl::encoding::Context) -> usize {
888            4
889        }
890    }
891
892    unsafe impl
893        fidl::encoding::Encode<
894            ProviderWatchStateRequest,
895            fidl::encoding::DefaultFuchsiaResourceDialect,
896        > for &mut ProviderWatchStateRequest
897    {
898        #[inline]
899        unsafe fn encode(
900            self,
901            encoder: &mut fidl::encoding::Encoder<
902                '_,
903                fidl::encoding::DefaultFuchsiaResourceDialect,
904            >,
905            offset: usize,
906            _depth: fidl::encoding::Depth,
907        ) -> fidl::Result<()> {
908            encoder.debug_check_bounds::<ProviderWatchStateRequest>(offset);
909            // Delegate to tuple encoding.
910            fidl::encoding::Encode::<ProviderWatchStateRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
911                (
912                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.listener),
913                ),
914                encoder, offset, _depth
915            )
916        }
917    }
918    unsafe impl<
919        T0: fidl::encoding::Encode<
920                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
921                fidl::encoding::DefaultFuchsiaResourceDialect,
922            >,
923    >
924        fidl::encoding::Encode<
925            ProviderWatchStateRequest,
926            fidl::encoding::DefaultFuchsiaResourceDialect,
927        > for (T0,)
928    {
929        #[inline]
930        unsafe fn encode(
931            self,
932            encoder: &mut fidl::encoding::Encoder<
933                '_,
934                fidl::encoding::DefaultFuchsiaResourceDialect,
935            >,
936            offset: usize,
937            depth: fidl::encoding::Depth,
938        ) -> fidl::Result<()> {
939            encoder.debug_check_bounds::<ProviderWatchStateRequest>(offset);
940            // Zero out padding regions. There's no need to apply masks
941            // because the unmasked parts will be overwritten by fields.
942            // Write the fields.
943            self.0.encode(encoder, offset + 0, depth)?;
944            Ok(())
945        }
946    }
947
948    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
949        for ProviderWatchStateRequest
950    {
951        #[inline(always)]
952        fn new_empty() -> Self {
953            Self {
954                listener: fidl::new_empty!(
955                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
956                    fidl::encoding::DefaultFuchsiaResourceDialect
957                ),
958            }
959        }
960
961        #[inline]
962        unsafe fn decode(
963            &mut self,
964            decoder: &mut fidl::encoding::Decoder<
965                '_,
966                fidl::encoding::DefaultFuchsiaResourceDialect,
967            >,
968            offset: usize,
969            _depth: fidl::encoding::Depth,
970        ) -> fidl::Result<()> {
971            decoder.debug_check_bounds::<Self>(offset);
972            // Verify that padding bytes are zero.
973            fidl::decode!(
974                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
975                fidl::encoding::DefaultFuchsiaResourceDialect,
976                &mut self.listener,
977                decoder,
978                offset + 0,
979                _depth
980            )?;
981            Ok(())
982        }
983    }
984}