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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13pub type OngoingActivityId = u32;
14
15/// State is an enumeration of the activity states the system may be in.
16#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
17#[repr(u32)]
18pub enum State {
19    Unknown = 0,
20    /// IDLE implies that the system is not currently being used by a user.
21    /// In other words, the system is not ACTIVE.
22    Idle = 1,
23    /// ACTIVE implies that a user has recently or is currently using the
24    /// system.
25    ///
26    /// Activity can be signalled by discrete interactions (cursor, keyboard,
27    /// touchscreen), or by ongoing activities (video playback).
28    ///
29    /// The specific meaning of "recently" is an implementation
30    /// detail of the Activity Service, but a typical value is 15 minutes.
31    Active = 2,
32}
33
34impl State {
35    #[inline]
36    pub fn from_primitive(prim: u32) -> Option<Self> {
37        match prim {
38            0 => Some(Self::Unknown),
39            1 => Some(Self::Idle),
40            2 => Some(Self::Active),
41            _ => None,
42        }
43    }
44
45    #[inline]
46    pub const fn into_primitive(self) -> u32 {
47        self as u32
48    }
49
50    #[deprecated = "Strict enums should not use `is_unknown`"]
51    #[inline]
52    pub fn is_unknown(&self) -> bool {
53        false
54    }
55}
56
57#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
58pub struct ListenerOnStateChangedRequest {
59    pub state: State,
60    pub transition_time: i64,
61}
62
63impl fidl::Persistable for ListenerOnStateChangedRequest {}
64
65#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
66pub struct ProviderWatchStateRequest {
67    pub listener: fidl::endpoints::ClientEnd<ListenerMarker>,
68}
69
70impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for ProviderWatchStateRequest {}
71
72/// GenericActivity is a user or system activity of unspecified type, e.g.
73/// a keyboard press or an alarm going off.
74#[derive(Clone, Debug, Default, PartialEq)]
75pub struct GenericActivity {
76    /// Brief human-readable label for the activity, for logging/debugging.
77    /// e.g. "cursor", "key", "video"
78    pub label: Option<String>,
79    #[doc(hidden)]
80    pub __source_breaking: fidl::marker::SourceBreaking,
81}
82
83impl fidl::Persistable for GenericActivity {}
84
85/// DiscreteActivity is an activity which occurs at a point in time.
86#[derive(Clone, Debug)]
87pub enum DiscreteActivity {
88    /// Activities that require no special handling.
89    Generic(GenericActivity),
90    #[doc(hidden)]
91    __SourceBreaking { unknown_ordinal: u64 },
92}
93
94/// Pattern that matches an unknown `DiscreteActivity` member.
95#[macro_export]
96macro_rules! DiscreteActivityUnknown {
97    () => {
98        _
99    };
100}
101
102// Custom PartialEq so that unknown variants are not equal to themselves.
103impl PartialEq for DiscreteActivity {
104    fn eq(&self, other: &Self) -> bool {
105        match (self, other) {
106            (Self::Generic(x), Self::Generic(y)) => *x == *y,
107            _ => false,
108        }
109    }
110}
111
112impl DiscreteActivity {
113    #[inline]
114    pub fn ordinal(&self) -> u64 {
115        match *self {
116            Self::Generic(_) => 1,
117            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
118        }
119    }
120
121    #[inline]
122    pub fn unknown_variant_for_testing() -> Self {
123        Self::__SourceBreaking { unknown_ordinal: 0 }
124    }
125
126    #[inline]
127    pub fn is_unknown(&self) -> bool {
128        match self {
129            Self::__SourceBreaking { .. } => true,
130            _ => false,
131        }
132    }
133}
134
135impl fidl::Persistable for DiscreteActivity {}
136
137/// OngoingActivity is an activity which has a definite start and end time.
138#[derive(Clone, Debug)]
139pub enum OngoingActivity {
140    /// Activities that require no special handling.
141    Generic(GenericActivity),
142    #[doc(hidden)]
143    __SourceBreaking { unknown_ordinal: u64 },
144}
145
146/// Pattern that matches an unknown `OngoingActivity` member.
147#[macro_export]
148macro_rules! OngoingActivityUnknown {
149    () => {
150        _
151    };
152}
153
154// Custom PartialEq so that unknown variants are not equal to themselves.
155impl PartialEq for OngoingActivity {
156    fn eq(&self, other: &Self) -> bool {
157        match (self, other) {
158            (Self::Generic(x), Self::Generic(y)) => *x == *y,
159            _ => false,
160        }
161    }
162}
163
164impl OngoingActivity {
165    #[inline]
166    pub fn ordinal(&self) -> u64 {
167        match *self {
168            Self::Generic(_) => 1,
169            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
170        }
171    }
172
173    #[inline]
174    pub fn unknown_variant_for_testing() -> Self {
175        Self::__SourceBreaking { unknown_ordinal: 0 }
176    }
177
178    #[inline]
179    pub fn is_unknown(&self) -> bool {
180        match self {
181            Self::__SourceBreaking { .. } => true,
182            _ => false,
183        }
184    }
185}
186
187impl fidl::Persistable for OngoingActivity {}
188
189#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
190pub struct ListenerMarker;
191
192impl fidl::endpoints::ProtocolMarker for ListenerMarker {
193    type Proxy = ListenerProxy;
194    type RequestStream = ListenerRequestStream;
195    #[cfg(target_os = "fuchsia")]
196    type SynchronousProxy = ListenerSynchronousProxy;
197
198    const DEBUG_NAME: &'static str = "(anonymous) Listener";
199}
200
201pub trait ListenerProxyInterface: Send + Sync {
202    type OnStateChangedResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
203    fn r#on_state_changed(
204        &self,
205        state: State,
206        transition_time: i64,
207    ) -> Self::OnStateChangedResponseFut;
208}
209#[derive(Debug)]
210#[cfg(target_os = "fuchsia")]
211pub struct ListenerSynchronousProxy {
212    client: fidl::client::sync::Client,
213}
214
215#[cfg(target_os = "fuchsia")]
216impl fidl::endpoints::SynchronousProxy for ListenerSynchronousProxy {
217    type Proxy = ListenerProxy;
218    type Protocol = ListenerMarker;
219
220    fn from_channel(inner: fidl::Channel) -> Self {
221        Self::new(inner)
222    }
223
224    fn into_channel(self) -> fidl::Channel {
225        self.client.into_channel()
226    }
227
228    fn as_channel(&self) -> &fidl::Channel {
229        self.client.as_channel()
230    }
231}
232
233#[cfg(target_os = "fuchsia")]
234impl ListenerSynchronousProxy {
235    pub fn new(channel: fidl::Channel) -> Self {
236        let protocol_name = <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
237        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
238    }
239
240    pub fn into_channel(self) -> fidl::Channel {
241        self.client.into_channel()
242    }
243
244    /// Waits until an event arrives and returns it. It is safe for other
245    /// threads to make concurrent requests while waiting for an event.
246    pub fn wait_for_event(
247        &self,
248        deadline: zx::MonotonicInstant,
249    ) -> Result<ListenerEvent, fidl::Error> {
250        ListenerEvent::decode(self.client.wait_for_event(deadline)?)
251    }
252
253    /// Callback that is invoked whenever the system state changes.
254    /// The Listener is expected to acknowledge each call explicitly and will
255    /// not receive new state until this acknowledgement is done.
256    pub fn r#on_state_changed(
257        &self,
258        mut state: State,
259        mut transition_time: i64,
260        ___deadline: zx::MonotonicInstant,
261    ) -> Result<(), fidl::Error> {
262        let _response =
263            self.client.send_query::<ListenerOnStateChangedRequest, fidl::encoding::EmptyPayload>(
264                (state, transition_time),
265                0xf74db3e6d5ba415,
266                fidl::encoding::DynamicFlags::empty(),
267                ___deadline,
268            )?;
269        Ok(_response)
270    }
271}
272
273#[derive(Debug, Clone)]
274pub struct ListenerProxy {
275    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
276}
277
278impl fidl::endpoints::Proxy for ListenerProxy {
279    type Protocol = ListenerMarker;
280
281    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
282        Self::new(inner)
283    }
284
285    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
286        self.client.into_channel().map_err(|client| Self { client })
287    }
288
289    fn as_channel(&self) -> &::fidl::AsyncChannel {
290        self.client.as_channel()
291    }
292}
293
294impl ListenerProxy {
295    /// Create a new Proxy for fuchsia.ui.activity/Listener.
296    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
297        let protocol_name = <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
298        Self { client: fidl::client::Client::new(channel, protocol_name) }
299    }
300
301    /// Get a Stream of events from the remote end of the protocol.
302    ///
303    /// # Panics
304    ///
305    /// Panics if the event stream was already taken.
306    pub fn take_event_stream(&self) -> ListenerEventStream {
307        ListenerEventStream { event_receiver: self.client.take_event_receiver() }
308    }
309
310    /// Callback that is invoked whenever the system state changes.
311    /// The Listener is expected to acknowledge each call explicitly and will
312    /// not receive new state until this acknowledgement is done.
313    pub fn r#on_state_changed(
314        &self,
315        mut state: State,
316        mut transition_time: i64,
317    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
318        ListenerProxyInterface::r#on_state_changed(self, state, transition_time)
319    }
320}
321
322impl ListenerProxyInterface for ListenerProxy {
323    type OnStateChangedResponseFut =
324        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
325    fn r#on_state_changed(
326        &self,
327        mut state: State,
328        mut transition_time: i64,
329    ) -> Self::OnStateChangedResponseFut {
330        fn _decode(
331            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
332        ) -> Result<(), fidl::Error> {
333            let _response = fidl::client::decode_transaction_body::<
334                fidl::encoding::EmptyPayload,
335                fidl::encoding::DefaultFuchsiaResourceDialect,
336                0xf74db3e6d5ba415,
337            >(_buf?)?;
338            Ok(_response)
339        }
340        self.client.send_query_and_decode::<ListenerOnStateChangedRequest, ()>(
341            (state, transition_time),
342            0xf74db3e6d5ba415,
343            fidl::encoding::DynamicFlags::empty(),
344            _decode,
345        )
346    }
347}
348
349pub struct ListenerEventStream {
350    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
351}
352
353impl std::marker::Unpin for ListenerEventStream {}
354
355impl futures::stream::FusedStream for ListenerEventStream {
356    fn is_terminated(&self) -> bool {
357        self.event_receiver.is_terminated()
358    }
359}
360
361impl futures::Stream for ListenerEventStream {
362    type Item = Result<ListenerEvent, fidl::Error>;
363
364    fn poll_next(
365        mut self: std::pin::Pin<&mut Self>,
366        cx: &mut std::task::Context<'_>,
367    ) -> std::task::Poll<Option<Self::Item>> {
368        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
369            &mut self.event_receiver,
370            cx
371        )?) {
372            Some(buf) => std::task::Poll::Ready(Some(ListenerEvent::decode(buf))),
373            None => std::task::Poll::Ready(None),
374        }
375    }
376}
377
378#[derive(Debug)]
379pub enum ListenerEvent {}
380
381impl ListenerEvent {
382    /// Decodes a message buffer as a [`ListenerEvent`].
383    fn decode(
384        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
385    ) -> Result<ListenerEvent, fidl::Error> {
386        let (bytes, _handles) = buf.split_mut();
387        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
388        debug_assert_eq!(tx_header.tx_id, 0);
389        match tx_header.ordinal {
390            _ => Err(fidl::Error::UnknownOrdinal {
391                ordinal: tx_header.ordinal,
392                protocol_name: <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
393            }),
394        }
395    }
396}
397
398/// A Stream of incoming requests for fuchsia.ui.activity/Listener.
399pub struct ListenerRequestStream {
400    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
401    is_terminated: bool,
402}
403
404impl std::marker::Unpin for ListenerRequestStream {}
405
406impl futures::stream::FusedStream for ListenerRequestStream {
407    fn is_terminated(&self) -> bool {
408        self.is_terminated
409    }
410}
411
412impl fidl::endpoints::RequestStream for ListenerRequestStream {
413    type Protocol = ListenerMarker;
414    type ControlHandle = ListenerControlHandle;
415
416    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
417        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
418    }
419
420    fn control_handle(&self) -> Self::ControlHandle {
421        ListenerControlHandle { inner: self.inner.clone() }
422    }
423
424    fn into_inner(
425        self,
426    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
427    {
428        (self.inner, self.is_terminated)
429    }
430
431    fn from_inner(
432        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
433        is_terminated: bool,
434    ) -> Self {
435        Self { inner, is_terminated }
436    }
437}
438
439impl futures::Stream for ListenerRequestStream {
440    type Item = Result<ListenerRequest, fidl::Error>;
441
442    fn poll_next(
443        mut self: std::pin::Pin<&mut Self>,
444        cx: &mut std::task::Context<'_>,
445    ) -> std::task::Poll<Option<Self::Item>> {
446        let this = &mut *self;
447        if this.inner.check_shutdown(cx) {
448            this.is_terminated = true;
449            return std::task::Poll::Ready(None);
450        }
451        if this.is_terminated {
452            panic!("polled ListenerRequestStream after completion");
453        }
454        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
455            |bytes, handles| {
456                match this.inner.channel().read_etc(cx, bytes, handles) {
457                    std::task::Poll::Ready(Ok(())) => {}
458                    std::task::Poll::Pending => return std::task::Poll::Pending,
459                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
460                        this.is_terminated = true;
461                        return std::task::Poll::Ready(None);
462                    }
463                    std::task::Poll::Ready(Err(e)) => {
464                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
465                            e.into(),
466                        ))))
467                    }
468                }
469
470                // A message has been received from the channel
471                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
472
473                std::task::Poll::Ready(Some(match header.ordinal {
474                    0xf74db3e6d5ba415 => {
475                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
476                        let mut req = fidl::new_empty!(
477                            ListenerOnStateChangedRequest,
478                            fidl::encoding::DefaultFuchsiaResourceDialect
479                        );
480                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ListenerOnStateChangedRequest>(&header, _body_bytes, handles, &mut req)?;
481                        let control_handle = ListenerControlHandle { inner: this.inner.clone() };
482                        Ok(ListenerRequest::OnStateChanged {
483                            state: req.state,
484                            transition_time: req.transition_time,
485
486                            responder: ListenerOnStateChangedResponder {
487                                control_handle: std::mem::ManuallyDrop::new(control_handle),
488                                tx_id: header.tx_id,
489                            },
490                        })
491                    }
492                    _ => Err(fidl::Error::UnknownOrdinal {
493                        ordinal: header.ordinal,
494                        protocol_name:
495                            <ListenerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
496                    }),
497                }))
498            },
499        )
500    }
501}
502
503/// The Listener protocol subscribes to changes in the system's activity
504/// state. Clients which care about the activity state of the system are
505/// expected to implement this protocol and subscribe via Provider.WatchState.
506#[derive(Debug)]
507pub enum ListenerRequest {
508    /// Callback that is invoked whenever the system state changes.
509    /// The Listener is expected to acknowledge each call explicitly and will
510    /// not receive new state until this acknowledgement is done.
511    OnStateChanged {
512        state: State,
513        transition_time: i64,
514        responder: ListenerOnStateChangedResponder,
515    },
516}
517
518impl ListenerRequest {
519    #[allow(irrefutable_let_patterns)]
520    pub fn into_on_state_changed(self) -> Option<(State, i64, ListenerOnStateChangedResponder)> {
521        if let ListenerRequest::OnStateChanged { state, transition_time, responder } = self {
522            Some((state, transition_time, responder))
523        } else {
524            None
525        }
526    }
527
528    /// Name of the method defined in FIDL
529    pub fn method_name(&self) -> &'static str {
530        match *self {
531            ListenerRequest::OnStateChanged { .. } => "on_state_changed",
532        }
533    }
534}
535
536#[derive(Debug, Clone)]
537pub struct ListenerControlHandle {
538    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
539}
540
541impl fidl::endpoints::ControlHandle for ListenerControlHandle {
542    fn shutdown(&self) {
543        self.inner.shutdown()
544    }
545    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
546        self.inner.shutdown_with_epitaph(status)
547    }
548
549    fn is_closed(&self) -> bool {
550        self.inner.channel().is_closed()
551    }
552    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
553        self.inner.channel().on_closed()
554    }
555
556    #[cfg(target_os = "fuchsia")]
557    fn signal_peer(
558        &self,
559        clear_mask: zx::Signals,
560        set_mask: zx::Signals,
561    ) -> Result<(), zx_status::Status> {
562        use fidl::Peered;
563        self.inner.channel().signal_peer(clear_mask, set_mask)
564    }
565}
566
567impl ListenerControlHandle {}
568
569#[must_use = "FIDL methods require a response to be sent"]
570#[derive(Debug)]
571pub struct ListenerOnStateChangedResponder {
572    control_handle: std::mem::ManuallyDrop<ListenerControlHandle>,
573    tx_id: u32,
574}
575
576/// Set the the channel to be shutdown (see [`ListenerControlHandle::shutdown`])
577/// if the responder is dropped without sending a response, so that the client
578/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
579impl std::ops::Drop for ListenerOnStateChangedResponder {
580    fn drop(&mut self) {
581        self.control_handle.shutdown();
582        // Safety: drops once, never accessed again
583        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
584    }
585}
586
587impl fidl::endpoints::Responder for ListenerOnStateChangedResponder {
588    type ControlHandle = ListenerControlHandle;
589
590    fn control_handle(&self) -> &ListenerControlHandle {
591        &self.control_handle
592    }
593
594    fn drop_without_shutdown(mut self) {
595        // Safety: drops once, never accessed again due to mem::forget
596        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
597        // Prevent Drop from running (which would shut down the channel)
598        std::mem::forget(self);
599    }
600}
601
602impl ListenerOnStateChangedResponder {
603    /// Sends a response to the FIDL transaction.
604    ///
605    /// Sets the channel to shutdown if an error occurs.
606    pub fn send(self) -> Result<(), fidl::Error> {
607        let _result = self.send_raw();
608        if _result.is_err() {
609            self.control_handle.shutdown();
610        }
611        self.drop_without_shutdown();
612        _result
613    }
614
615    /// Similar to "send" but does not shutdown the channel if an error occurs.
616    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
617        let _result = self.send_raw();
618        self.drop_without_shutdown();
619        _result
620    }
621
622    fn send_raw(&self) -> Result<(), fidl::Error> {
623        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
624            (),
625            self.tx_id,
626            0xf74db3e6d5ba415,
627            fidl::encoding::DynamicFlags::empty(),
628        )
629    }
630}
631
632#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
633pub struct ProviderMarker;
634
635impl fidl::endpoints::ProtocolMarker for ProviderMarker {
636    type Proxy = ProviderProxy;
637    type RequestStream = ProviderRequestStream;
638    #[cfg(target_os = "fuchsia")]
639    type SynchronousProxy = ProviderSynchronousProxy;
640
641    const DEBUG_NAME: &'static str = "fuchsia.ui.activity.Provider";
642}
643impl fidl::endpoints::DiscoverableProtocolMarker for ProviderMarker {}
644
645pub trait ProviderProxyInterface: Send + Sync {
646    fn r#watch_state(
647        &self,
648        listener: fidl::endpoints::ClientEnd<ListenerMarker>,
649    ) -> Result<(), fidl::Error>;
650}
651#[derive(Debug)]
652#[cfg(target_os = "fuchsia")]
653pub struct ProviderSynchronousProxy {
654    client: fidl::client::sync::Client,
655}
656
657#[cfg(target_os = "fuchsia")]
658impl fidl::endpoints::SynchronousProxy for ProviderSynchronousProxy {
659    type Proxy = ProviderProxy;
660    type Protocol = ProviderMarker;
661
662    fn from_channel(inner: fidl::Channel) -> Self {
663        Self::new(inner)
664    }
665
666    fn into_channel(self) -> fidl::Channel {
667        self.client.into_channel()
668    }
669
670    fn as_channel(&self) -> &fidl::Channel {
671        self.client.as_channel()
672    }
673}
674
675#[cfg(target_os = "fuchsia")]
676impl ProviderSynchronousProxy {
677    pub fn new(channel: fidl::Channel) -> Self {
678        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
679        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
680    }
681
682    pub fn into_channel(self) -> fidl::Channel {
683        self.client.into_channel()
684    }
685
686    /// Waits until an event arrives and returns it. It is safe for other
687    /// threads to make concurrent requests while waiting for an event.
688    pub fn wait_for_event(
689        &self,
690        deadline: zx::MonotonicInstant,
691    ) -> Result<ProviderEvent, fidl::Error> {
692        ProviderEvent::decode(self.client.wait_for_event(deadline)?)
693    }
694
695    /// Subscribe to changes in the system's state.
696    /// The server will always invoke listener.OnStateChanged at least once with
697    /// the initial state, and after that invoke listener.OnStateChanged
698    /// whenever the system's state changes.
699    pub fn r#watch_state(
700        &self,
701        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
702    ) -> Result<(), fidl::Error> {
703        self.client.send::<ProviderWatchStateRequest>(
704            (listener,),
705            0x592e25a4cbe7f884,
706            fidl::encoding::DynamicFlags::empty(),
707        )
708    }
709}
710
711#[derive(Debug, Clone)]
712pub struct ProviderProxy {
713    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
714}
715
716impl fidl::endpoints::Proxy for ProviderProxy {
717    type Protocol = ProviderMarker;
718
719    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
720        Self::new(inner)
721    }
722
723    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
724        self.client.into_channel().map_err(|client| Self { client })
725    }
726
727    fn as_channel(&self) -> &::fidl::AsyncChannel {
728        self.client.as_channel()
729    }
730}
731
732impl ProviderProxy {
733    /// Create a new Proxy for fuchsia.ui.activity/Provider.
734    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
735        let protocol_name = <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
736        Self { client: fidl::client::Client::new(channel, protocol_name) }
737    }
738
739    /// Get a Stream of events from the remote end of the protocol.
740    ///
741    /// # Panics
742    ///
743    /// Panics if the event stream was already taken.
744    pub fn take_event_stream(&self) -> ProviderEventStream {
745        ProviderEventStream { event_receiver: self.client.take_event_receiver() }
746    }
747
748    /// Subscribe to changes in the system's state.
749    /// The server will always invoke listener.OnStateChanged at least once with
750    /// the initial state, and after that invoke listener.OnStateChanged
751    /// whenever the system's state changes.
752    pub fn r#watch_state(
753        &self,
754        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
755    ) -> Result<(), fidl::Error> {
756        ProviderProxyInterface::r#watch_state(self, listener)
757    }
758}
759
760impl ProviderProxyInterface for ProviderProxy {
761    fn r#watch_state(
762        &self,
763        mut listener: fidl::endpoints::ClientEnd<ListenerMarker>,
764    ) -> Result<(), fidl::Error> {
765        self.client.send::<ProviderWatchStateRequest>(
766            (listener,),
767            0x592e25a4cbe7f884,
768            fidl::encoding::DynamicFlags::empty(),
769        )
770    }
771}
772
773pub struct ProviderEventStream {
774    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
775}
776
777impl std::marker::Unpin for ProviderEventStream {}
778
779impl futures::stream::FusedStream for ProviderEventStream {
780    fn is_terminated(&self) -> bool {
781        self.event_receiver.is_terminated()
782    }
783}
784
785impl futures::Stream for ProviderEventStream {
786    type Item = Result<ProviderEvent, fidl::Error>;
787
788    fn poll_next(
789        mut self: std::pin::Pin<&mut Self>,
790        cx: &mut std::task::Context<'_>,
791    ) -> std::task::Poll<Option<Self::Item>> {
792        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
793            &mut self.event_receiver,
794            cx
795        )?) {
796            Some(buf) => std::task::Poll::Ready(Some(ProviderEvent::decode(buf))),
797            None => std::task::Poll::Ready(None),
798        }
799    }
800}
801
802#[derive(Debug)]
803pub enum ProviderEvent {}
804
805impl ProviderEvent {
806    /// Decodes a message buffer as a [`ProviderEvent`].
807    fn decode(
808        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
809    ) -> Result<ProviderEvent, fidl::Error> {
810        let (bytes, _handles) = buf.split_mut();
811        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
812        debug_assert_eq!(tx_header.tx_id, 0);
813        match tx_header.ordinal {
814            _ => Err(fidl::Error::UnknownOrdinal {
815                ordinal: tx_header.ordinal,
816                protocol_name: <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
817            }),
818        }
819    }
820}
821
822/// A Stream of incoming requests for fuchsia.ui.activity/Provider.
823pub struct ProviderRequestStream {
824    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
825    is_terminated: bool,
826}
827
828impl std::marker::Unpin for ProviderRequestStream {}
829
830impl futures::stream::FusedStream for ProviderRequestStream {
831    fn is_terminated(&self) -> bool {
832        self.is_terminated
833    }
834}
835
836impl fidl::endpoints::RequestStream for ProviderRequestStream {
837    type Protocol = ProviderMarker;
838    type ControlHandle = ProviderControlHandle;
839
840    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
841        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
842    }
843
844    fn control_handle(&self) -> Self::ControlHandle {
845        ProviderControlHandle { inner: self.inner.clone() }
846    }
847
848    fn into_inner(
849        self,
850    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
851    {
852        (self.inner, self.is_terminated)
853    }
854
855    fn from_inner(
856        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
857        is_terminated: bool,
858    ) -> Self {
859        Self { inner, is_terminated }
860    }
861}
862
863impl futures::Stream for ProviderRequestStream {
864    type Item = Result<ProviderRequest, fidl::Error>;
865
866    fn poll_next(
867        mut self: std::pin::Pin<&mut Self>,
868        cx: &mut std::task::Context<'_>,
869    ) -> std::task::Poll<Option<Self::Item>> {
870        let this = &mut *self;
871        if this.inner.check_shutdown(cx) {
872            this.is_terminated = true;
873            return std::task::Poll::Ready(None);
874        }
875        if this.is_terminated {
876            panic!("polled ProviderRequestStream after completion");
877        }
878        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
879            |bytes, handles| {
880                match this.inner.channel().read_etc(cx, bytes, handles) {
881                    std::task::Poll::Ready(Ok(())) => {}
882                    std::task::Poll::Pending => return std::task::Poll::Pending,
883                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
884                        this.is_terminated = true;
885                        return std::task::Poll::Ready(None);
886                    }
887                    std::task::Poll::Ready(Err(e)) => {
888                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
889                            e.into(),
890                        ))))
891                    }
892                }
893
894                // A message has been received from the channel
895                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
896
897                std::task::Poll::Ready(Some(match header.ordinal {
898                    0x592e25a4cbe7f884 => {
899                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
900                        let mut req = fidl::new_empty!(
901                            ProviderWatchStateRequest,
902                            fidl::encoding::DefaultFuchsiaResourceDialect
903                        );
904                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ProviderWatchStateRequest>(&header, _body_bytes, handles, &mut req)?;
905                        let control_handle = ProviderControlHandle { inner: this.inner.clone() };
906                        Ok(ProviderRequest::WatchState { listener: req.listener, control_handle })
907                    }
908                    _ => Err(fidl::Error::UnknownOrdinal {
909                        ordinal: header.ordinal,
910                        protocol_name:
911                            <ProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
912                    }),
913                }))
914            },
915        )
916    }
917}
918
919/// The Provider protocol offers a subscription interface through
920/// which clients can watch for changes in the system's activity state.
921#[derive(Debug)]
922pub enum ProviderRequest {
923    /// Subscribe to changes in the system's state.
924    /// The server will always invoke listener.OnStateChanged at least once with
925    /// the initial state, and after that invoke listener.OnStateChanged
926    /// whenever the system's state changes.
927    WatchState {
928        listener: fidl::endpoints::ClientEnd<ListenerMarker>,
929        control_handle: ProviderControlHandle,
930    },
931}
932
933impl ProviderRequest {
934    #[allow(irrefutable_let_patterns)]
935    pub fn into_watch_state(
936        self,
937    ) -> Option<(fidl::endpoints::ClientEnd<ListenerMarker>, ProviderControlHandle)> {
938        if let ProviderRequest::WatchState { listener, control_handle } = self {
939            Some((listener, control_handle))
940        } else {
941            None
942        }
943    }
944
945    /// Name of the method defined in FIDL
946    pub fn method_name(&self) -> &'static str {
947        match *self {
948            ProviderRequest::WatchState { .. } => "watch_state",
949        }
950    }
951}
952
953#[derive(Debug, Clone)]
954pub struct ProviderControlHandle {
955    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
956}
957
958impl fidl::endpoints::ControlHandle for ProviderControlHandle {
959    fn shutdown(&self) {
960        self.inner.shutdown()
961    }
962    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
963        self.inner.shutdown_with_epitaph(status)
964    }
965
966    fn is_closed(&self) -> bool {
967        self.inner.channel().is_closed()
968    }
969    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
970        self.inner.channel().on_closed()
971    }
972
973    #[cfg(target_os = "fuchsia")]
974    fn signal_peer(
975        &self,
976        clear_mask: zx::Signals,
977        set_mask: zx::Signals,
978    ) -> Result<(), zx_status::Status> {
979        use fidl::Peered;
980        self.inner.channel().signal_peer(clear_mask, set_mask)
981    }
982}
983
984impl ProviderControlHandle {}
985
986mod internal {
987    use super::*;
988    unsafe impl fidl::encoding::TypeMarker for State {
989        type Owned = Self;
990
991        #[inline(always)]
992        fn inline_align(_context: fidl::encoding::Context) -> usize {
993            std::mem::align_of::<u32>()
994        }
995
996        #[inline(always)]
997        fn inline_size(_context: fidl::encoding::Context) -> usize {
998            std::mem::size_of::<u32>()
999        }
1000
1001        #[inline(always)]
1002        fn encode_is_copy() -> bool {
1003            true
1004        }
1005
1006        #[inline(always)]
1007        fn decode_is_copy() -> bool {
1008            false
1009        }
1010    }
1011
1012    impl fidl::encoding::ValueTypeMarker for State {
1013        type Borrowed<'a> = Self;
1014        #[inline(always)]
1015        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1016            *value
1017        }
1018    }
1019
1020    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for State {
1021        #[inline]
1022        unsafe fn encode(
1023            self,
1024            encoder: &mut fidl::encoding::Encoder<'_, D>,
1025            offset: usize,
1026            _depth: fidl::encoding::Depth,
1027        ) -> fidl::Result<()> {
1028            encoder.debug_check_bounds::<Self>(offset);
1029            encoder.write_num(self.into_primitive(), offset);
1030            Ok(())
1031        }
1032    }
1033
1034    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for State {
1035        #[inline(always)]
1036        fn new_empty() -> Self {
1037            Self::Unknown
1038        }
1039
1040        #[inline]
1041        unsafe fn decode(
1042            &mut self,
1043            decoder: &mut fidl::encoding::Decoder<'_, D>,
1044            offset: usize,
1045            _depth: fidl::encoding::Depth,
1046        ) -> fidl::Result<()> {
1047            decoder.debug_check_bounds::<Self>(offset);
1048            let prim = decoder.read_num::<u32>(offset);
1049
1050            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
1051            Ok(())
1052        }
1053    }
1054
1055    impl fidl::encoding::ValueTypeMarker for ListenerOnStateChangedRequest {
1056        type Borrowed<'a> = &'a Self;
1057        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1058            value
1059        }
1060    }
1061
1062    unsafe impl fidl::encoding::TypeMarker for ListenerOnStateChangedRequest {
1063        type Owned = Self;
1064
1065        #[inline(always)]
1066        fn inline_align(_context: fidl::encoding::Context) -> usize {
1067            8
1068        }
1069
1070        #[inline(always)]
1071        fn inline_size(_context: fidl::encoding::Context) -> usize {
1072            16
1073        }
1074    }
1075
1076    unsafe impl<D: fidl::encoding::ResourceDialect>
1077        fidl::encoding::Encode<ListenerOnStateChangedRequest, D>
1078        for &ListenerOnStateChangedRequest
1079    {
1080        #[inline]
1081        unsafe fn encode(
1082            self,
1083            encoder: &mut fidl::encoding::Encoder<'_, D>,
1084            offset: usize,
1085            _depth: fidl::encoding::Depth,
1086        ) -> fidl::Result<()> {
1087            encoder.debug_check_bounds::<ListenerOnStateChangedRequest>(offset);
1088            // Delegate to tuple encoding.
1089            fidl::encoding::Encode::<ListenerOnStateChangedRequest, D>::encode(
1090                (
1091                    <State as fidl::encoding::ValueTypeMarker>::borrow(&self.state),
1092                    <i64 as fidl::encoding::ValueTypeMarker>::borrow(&self.transition_time),
1093                ),
1094                encoder,
1095                offset,
1096                _depth,
1097            )
1098        }
1099    }
1100    unsafe impl<
1101            D: fidl::encoding::ResourceDialect,
1102            T0: fidl::encoding::Encode<State, D>,
1103            T1: fidl::encoding::Encode<i64, D>,
1104        > fidl::encoding::Encode<ListenerOnStateChangedRequest, D> for (T0, T1)
1105    {
1106        #[inline]
1107        unsafe fn encode(
1108            self,
1109            encoder: &mut fidl::encoding::Encoder<'_, D>,
1110            offset: usize,
1111            depth: fidl::encoding::Depth,
1112        ) -> fidl::Result<()> {
1113            encoder.debug_check_bounds::<ListenerOnStateChangedRequest>(offset);
1114            // Zero out padding regions. There's no need to apply masks
1115            // because the unmasked parts will be overwritten by fields.
1116            unsafe {
1117                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
1118                (ptr as *mut u64).write_unaligned(0);
1119            }
1120            // Write the fields.
1121            self.0.encode(encoder, offset + 0, depth)?;
1122            self.1.encode(encoder, offset + 8, depth)?;
1123            Ok(())
1124        }
1125    }
1126
1127    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
1128        for ListenerOnStateChangedRequest
1129    {
1130        #[inline(always)]
1131        fn new_empty() -> Self {
1132            Self { state: fidl::new_empty!(State, D), transition_time: fidl::new_empty!(i64, D) }
1133        }
1134
1135        #[inline]
1136        unsafe fn decode(
1137            &mut self,
1138            decoder: &mut fidl::encoding::Decoder<'_, D>,
1139            offset: usize,
1140            _depth: fidl::encoding::Depth,
1141        ) -> fidl::Result<()> {
1142            decoder.debug_check_bounds::<Self>(offset);
1143            // Verify that padding bytes are zero.
1144            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
1145            let padval = unsafe { (ptr as *const u64).read_unaligned() };
1146            let mask = 0xffffffff00000000u64;
1147            let maskedval = padval & mask;
1148            if maskedval != 0 {
1149                return Err(fidl::Error::NonZeroPadding {
1150                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
1151                });
1152            }
1153            fidl::decode!(State, D, &mut self.state, decoder, offset + 0, _depth)?;
1154            fidl::decode!(i64, D, &mut self.transition_time, decoder, offset + 8, _depth)?;
1155            Ok(())
1156        }
1157    }
1158
1159    impl fidl::encoding::ResourceTypeMarker for ProviderWatchStateRequest {
1160        type Borrowed<'a> = &'a mut Self;
1161        fn take_or_borrow<'a>(
1162            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1163        ) -> Self::Borrowed<'a> {
1164            value
1165        }
1166    }
1167
1168    unsafe impl fidl::encoding::TypeMarker for ProviderWatchStateRequest {
1169        type Owned = Self;
1170
1171        #[inline(always)]
1172        fn inline_align(_context: fidl::encoding::Context) -> usize {
1173            4
1174        }
1175
1176        #[inline(always)]
1177        fn inline_size(_context: fidl::encoding::Context) -> usize {
1178            4
1179        }
1180    }
1181
1182    unsafe impl
1183        fidl::encoding::Encode<
1184            ProviderWatchStateRequest,
1185            fidl::encoding::DefaultFuchsiaResourceDialect,
1186        > for &mut ProviderWatchStateRequest
1187    {
1188        #[inline]
1189        unsafe fn encode(
1190            self,
1191            encoder: &mut fidl::encoding::Encoder<
1192                '_,
1193                fidl::encoding::DefaultFuchsiaResourceDialect,
1194            >,
1195            offset: usize,
1196            _depth: fidl::encoding::Depth,
1197        ) -> fidl::Result<()> {
1198            encoder.debug_check_bounds::<ProviderWatchStateRequest>(offset);
1199            // Delegate to tuple encoding.
1200            fidl::encoding::Encode::<ProviderWatchStateRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1201                (
1202                    <fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.listener),
1203                ),
1204                encoder, offset, _depth
1205            )
1206        }
1207    }
1208    unsafe impl<
1209            T0: fidl::encoding::Encode<
1210                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
1211                fidl::encoding::DefaultFuchsiaResourceDialect,
1212            >,
1213        >
1214        fidl::encoding::Encode<
1215            ProviderWatchStateRequest,
1216            fidl::encoding::DefaultFuchsiaResourceDialect,
1217        > for (T0,)
1218    {
1219        #[inline]
1220        unsafe fn encode(
1221            self,
1222            encoder: &mut fidl::encoding::Encoder<
1223                '_,
1224                fidl::encoding::DefaultFuchsiaResourceDialect,
1225            >,
1226            offset: usize,
1227            depth: fidl::encoding::Depth,
1228        ) -> fidl::Result<()> {
1229            encoder.debug_check_bounds::<ProviderWatchStateRequest>(offset);
1230            // Zero out padding regions. There's no need to apply masks
1231            // because the unmasked parts will be overwritten by fields.
1232            // Write the fields.
1233            self.0.encode(encoder, offset + 0, depth)?;
1234            Ok(())
1235        }
1236    }
1237
1238    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1239        for ProviderWatchStateRequest
1240    {
1241        #[inline(always)]
1242        fn new_empty() -> Self {
1243            Self {
1244                listener: fidl::new_empty!(
1245                    fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
1246                    fidl::encoding::DefaultFuchsiaResourceDialect
1247                ),
1248            }
1249        }
1250
1251        #[inline]
1252        unsafe fn decode(
1253            &mut self,
1254            decoder: &mut fidl::encoding::Decoder<
1255                '_,
1256                fidl::encoding::DefaultFuchsiaResourceDialect,
1257            >,
1258            offset: usize,
1259            _depth: fidl::encoding::Depth,
1260        ) -> fidl::Result<()> {
1261            decoder.debug_check_bounds::<Self>(offset);
1262            // Verify that padding bytes are zero.
1263            fidl::decode!(
1264                fidl::encoding::Endpoint<fidl::endpoints::ClientEnd<ListenerMarker>>,
1265                fidl::encoding::DefaultFuchsiaResourceDialect,
1266                &mut self.listener,
1267                decoder,
1268                offset + 0,
1269                _depth
1270            )?;
1271            Ok(())
1272        }
1273    }
1274
1275    impl GenericActivity {
1276        #[inline(always)]
1277        fn max_ordinal_present(&self) -> u64 {
1278            if let Some(_) = self.label {
1279                return 1;
1280            }
1281            0
1282        }
1283    }
1284
1285    impl fidl::encoding::ValueTypeMarker for GenericActivity {
1286        type Borrowed<'a> = &'a Self;
1287        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1288            value
1289        }
1290    }
1291
1292    unsafe impl fidl::encoding::TypeMarker for GenericActivity {
1293        type Owned = Self;
1294
1295        #[inline(always)]
1296        fn inline_align(_context: fidl::encoding::Context) -> usize {
1297            8
1298        }
1299
1300        #[inline(always)]
1301        fn inline_size(_context: fidl::encoding::Context) -> usize {
1302            16
1303        }
1304    }
1305
1306    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<GenericActivity, D>
1307        for &GenericActivity
1308    {
1309        unsafe fn encode(
1310            self,
1311            encoder: &mut fidl::encoding::Encoder<'_, D>,
1312            offset: usize,
1313            mut depth: fidl::encoding::Depth,
1314        ) -> fidl::Result<()> {
1315            encoder.debug_check_bounds::<GenericActivity>(offset);
1316            // Vector header
1317            let max_ordinal: u64 = self.max_ordinal_present();
1318            encoder.write_num(max_ordinal, offset);
1319            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
1320            // Calling encoder.out_of_line_offset(0) is not allowed.
1321            if max_ordinal == 0 {
1322                return Ok(());
1323            }
1324            depth.increment()?;
1325            let envelope_size = 8;
1326            let bytes_len = max_ordinal as usize * envelope_size;
1327            #[allow(unused_variables)]
1328            let offset = encoder.out_of_line_offset(bytes_len);
1329            let mut _prev_end_offset: usize = 0;
1330            if 1 > max_ordinal {
1331                return Ok(());
1332            }
1333
1334            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
1335            // are envelope_size bytes.
1336            let cur_offset: usize = (1 - 1) * envelope_size;
1337
1338            // Zero reserved fields.
1339            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
1340
1341            // Safety:
1342            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
1343            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
1344            //   envelope_size bytes, there is always sufficient room.
1345            fidl::encoding::encode_in_envelope_optional::<fidl::encoding::UnboundedString, D>(
1346                self.label.as_ref().map(
1347                    <fidl::encoding::UnboundedString as fidl::encoding::ValueTypeMarker>::borrow,
1348                ),
1349                encoder,
1350                offset + cur_offset,
1351                depth,
1352            )?;
1353
1354            _prev_end_offset = cur_offset + envelope_size;
1355
1356            Ok(())
1357        }
1358    }
1359
1360    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for GenericActivity {
1361        #[inline(always)]
1362        fn new_empty() -> Self {
1363            Self::default()
1364        }
1365
1366        unsafe fn decode(
1367            &mut self,
1368            decoder: &mut fidl::encoding::Decoder<'_, D>,
1369            offset: usize,
1370            mut depth: fidl::encoding::Depth,
1371        ) -> fidl::Result<()> {
1372            decoder.debug_check_bounds::<Self>(offset);
1373            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
1374                None => return Err(fidl::Error::NotNullable),
1375                Some(len) => len,
1376            };
1377            // Calling decoder.out_of_line_offset(0) is not allowed.
1378            if len == 0 {
1379                return Ok(());
1380            };
1381            depth.increment()?;
1382            let envelope_size = 8;
1383            let bytes_len = len * envelope_size;
1384            let offset = decoder.out_of_line_offset(bytes_len)?;
1385            // Decode the envelope for each type.
1386            let mut _next_ordinal_to_read = 0;
1387            let mut next_offset = offset;
1388            let end_offset = offset + bytes_len;
1389            _next_ordinal_to_read += 1;
1390            if next_offset >= end_offset {
1391                return Ok(());
1392            }
1393
1394            // Decode unknown envelopes for gaps in ordinals.
1395            while _next_ordinal_to_read < 1 {
1396                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1397                _next_ordinal_to_read += 1;
1398                next_offset += envelope_size;
1399            }
1400
1401            let next_out_of_line = decoder.next_out_of_line();
1402            let handles_before = decoder.remaining_handles();
1403            if let Some((inlined, num_bytes, num_handles)) =
1404                fidl::encoding::decode_envelope_header(decoder, next_offset)?
1405            {
1406                let member_inline_size =
1407                    <fidl::encoding::UnboundedString as fidl::encoding::TypeMarker>::inline_size(
1408                        decoder.context,
1409                    );
1410                if inlined != (member_inline_size <= 4) {
1411                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
1412                }
1413                let inner_offset;
1414                let mut inner_depth = depth.clone();
1415                if inlined {
1416                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
1417                    inner_offset = next_offset;
1418                } else {
1419                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1420                    inner_depth.increment()?;
1421                }
1422                let val_ref = self
1423                    .label
1424                    .get_or_insert_with(|| fidl::new_empty!(fidl::encoding::UnboundedString, D));
1425                fidl::decode!(
1426                    fidl::encoding::UnboundedString,
1427                    D,
1428                    val_ref,
1429                    decoder,
1430                    inner_offset,
1431                    inner_depth
1432                )?;
1433                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
1434                {
1435                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
1436                }
1437                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1438                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1439                }
1440            }
1441
1442            next_offset += envelope_size;
1443
1444            // Decode the remaining unknown envelopes.
1445            while next_offset < end_offset {
1446                _next_ordinal_to_read += 1;
1447                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
1448                next_offset += envelope_size;
1449            }
1450
1451            Ok(())
1452        }
1453    }
1454
1455    impl fidl::encoding::ValueTypeMarker for DiscreteActivity {
1456        type Borrowed<'a> = &'a Self;
1457        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1458            value
1459        }
1460    }
1461
1462    unsafe impl fidl::encoding::TypeMarker for DiscreteActivity {
1463        type Owned = Self;
1464
1465        #[inline(always)]
1466        fn inline_align(_context: fidl::encoding::Context) -> usize {
1467            8
1468        }
1469
1470        #[inline(always)]
1471        fn inline_size(_context: fidl::encoding::Context) -> usize {
1472            16
1473        }
1474    }
1475
1476    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DiscreteActivity, D>
1477        for &DiscreteActivity
1478    {
1479        #[inline]
1480        unsafe fn encode(
1481            self,
1482            encoder: &mut fidl::encoding::Encoder<'_, D>,
1483            offset: usize,
1484            _depth: fidl::encoding::Depth,
1485        ) -> fidl::Result<()> {
1486            encoder.debug_check_bounds::<DiscreteActivity>(offset);
1487            encoder.write_num::<u64>(self.ordinal(), offset);
1488            match self {
1489                DiscreteActivity::Generic(ref val) => {
1490                    fidl::encoding::encode_in_envelope::<GenericActivity, D>(
1491                        <GenericActivity as fidl::encoding::ValueTypeMarker>::borrow(val),
1492                        encoder,
1493                        offset + 8,
1494                        _depth,
1495                    )
1496                }
1497                DiscreteActivity::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1498            }
1499        }
1500    }
1501
1502    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DiscreteActivity {
1503        #[inline(always)]
1504        fn new_empty() -> Self {
1505            Self::__SourceBreaking { unknown_ordinal: 0 }
1506        }
1507
1508        #[inline]
1509        unsafe fn decode(
1510            &mut self,
1511            decoder: &mut fidl::encoding::Decoder<'_, D>,
1512            offset: usize,
1513            mut depth: fidl::encoding::Depth,
1514        ) -> fidl::Result<()> {
1515            decoder.debug_check_bounds::<Self>(offset);
1516            #[allow(unused_variables)]
1517            let next_out_of_line = decoder.next_out_of_line();
1518            let handles_before = decoder.remaining_handles();
1519            let (ordinal, inlined, num_bytes, num_handles) =
1520                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1521
1522            let member_inline_size = match ordinal {
1523                1 => <GenericActivity as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1524                0 => return Err(fidl::Error::UnknownUnionTag),
1525                _ => num_bytes as usize,
1526            };
1527
1528            if inlined != (member_inline_size <= 4) {
1529                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1530            }
1531            let _inner_offset;
1532            if inlined {
1533                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1534                _inner_offset = offset + 8;
1535            } else {
1536                depth.increment()?;
1537                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1538            }
1539            match ordinal {
1540                1 => {
1541                    #[allow(irrefutable_let_patterns)]
1542                    if let DiscreteActivity::Generic(_) = self {
1543                        // Do nothing, read the value into the object
1544                    } else {
1545                        // Initialize `self` to the right variant
1546                        *self = DiscreteActivity::Generic(fidl::new_empty!(GenericActivity, D));
1547                    }
1548                    #[allow(irrefutable_let_patterns)]
1549                    if let DiscreteActivity::Generic(ref mut val) = self {
1550                        fidl::decode!(GenericActivity, D, val, decoder, _inner_offset, depth)?;
1551                    } else {
1552                        unreachable!()
1553                    }
1554                }
1555                #[allow(deprecated)]
1556                ordinal => {
1557                    for _ in 0..num_handles {
1558                        decoder.drop_next_handle()?;
1559                    }
1560                    *self = DiscreteActivity::__SourceBreaking { unknown_ordinal: ordinal };
1561                }
1562            }
1563            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1564                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1565            }
1566            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1567                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1568            }
1569            Ok(())
1570        }
1571    }
1572
1573    impl fidl::encoding::ValueTypeMarker for OngoingActivity {
1574        type Borrowed<'a> = &'a Self;
1575        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1576            value
1577        }
1578    }
1579
1580    unsafe impl fidl::encoding::TypeMarker for OngoingActivity {
1581        type Owned = Self;
1582
1583        #[inline(always)]
1584        fn inline_align(_context: fidl::encoding::Context) -> usize {
1585            8
1586        }
1587
1588        #[inline(always)]
1589        fn inline_size(_context: fidl::encoding::Context) -> usize {
1590            16
1591        }
1592    }
1593
1594    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<OngoingActivity, D>
1595        for &OngoingActivity
1596    {
1597        #[inline]
1598        unsafe fn encode(
1599            self,
1600            encoder: &mut fidl::encoding::Encoder<'_, D>,
1601            offset: usize,
1602            _depth: fidl::encoding::Depth,
1603        ) -> fidl::Result<()> {
1604            encoder.debug_check_bounds::<OngoingActivity>(offset);
1605            encoder.write_num::<u64>(self.ordinal(), offset);
1606            match self {
1607                OngoingActivity::Generic(ref val) => {
1608                    fidl::encoding::encode_in_envelope::<GenericActivity, D>(
1609                        <GenericActivity as fidl::encoding::ValueTypeMarker>::borrow(val),
1610                        encoder,
1611                        offset + 8,
1612                        _depth,
1613                    )
1614                }
1615                OngoingActivity::__SourceBreaking { .. } => Err(fidl::Error::UnknownUnionTag),
1616            }
1617        }
1618    }
1619
1620    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for OngoingActivity {
1621        #[inline(always)]
1622        fn new_empty() -> Self {
1623            Self::__SourceBreaking { unknown_ordinal: 0 }
1624        }
1625
1626        #[inline]
1627        unsafe fn decode(
1628            &mut self,
1629            decoder: &mut fidl::encoding::Decoder<'_, D>,
1630            offset: usize,
1631            mut depth: fidl::encoding::Depth,
1632        ) -> fidl::Result<()> {
1633            decoder.debug_check_bounds::<Self>(offset);
1634            #[allow(unused_variables)]
1635            let next_out_of_line = decoder.next_out_of_line();
1636            let handles_before = decoder.remaining_handles();
1637            let (ordinal, inlined, num_bytes, num_handles) =
1638                fidl::encoding::decode_union_inline_portion(decoder, offset)?;
1639
1640            let member_inline_size = match ordinal {
1641                1 => <GenericActivity as fidl::encoding::TypeMarker>::inline_size(decoder.context),
1642                0 => return Err(fidl::Error::UnknownUnionTag),
1643                _ => num_bytes as usize,
1644            };
1645
1646            if inlined != (member_inline_size <= 4) {
1647                return Err(fidl::Error::InvalidInlineBitInEnvelope);
1648            }
1649            let _inner_offset;
1650            if inlined {
1651                decoder.check_inline_envelope_padding(offset + 8, member_inline_size)?;
1652                _inner_offset = offset + 8;
1653            } else {
1654                depth.increment()?;
1655                _inner_offset = decoder.out_of_line_offset(member_inline_size)?;
1656            }
1657            match ordinal {
1658                1 => {
1659                    #[allow(irrefutable_let_patterns)]
1660                    if let OngoingActivity::Generic(_) = self {
1661                        // Do nothing, read the value into the object
1662                    } else {
1663                        // Initialize `self` to the right variant
1664                        *self = OngoingActivity::Generic(fidl::new_empty!(GenericActivity, D));
1665                    }
1666                    #[allow(irrefutable_let_patterns)]
1667                    if let OngoingActivity::Generic(ref mut val) = self {
1668                        fidl::decode!(GenericActivity, D, val, decoder, _inner_offset, depth)?;
1669                    } else {
1670                        unreachable!()
1671                    }
1672                }
1673                #[allow(deprecated)]
1674                ordinal => {
1675                    for _ in 0..num_handles {
1676                        decoder.drop_next_handle()?;
1677                    }
1678                    *self = OngoingActivity::__SourceBreaking { unknown_ordinal: ordinal };
1679                }
1680            }
1681            if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize) {
1682                return Err(fidl::Error::InvalidNumBytesInEnvelope);
1683            }
1684            if handles_before != decoder.remaining_handles() + (num_handles as usize) {
1685                return Err(fidl::Error::InvalidNumHandlesInEnvelope);
1686            }
1687            Ok(())
1688        }
1689    }
1690}