fidl_fuchsia_power_profile__common/
fidl_fuchsia_power_profile__common.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::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11/// System power profiles that may be returned by [Watcher.Watch].
12#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
13#[repr(u32)]
14pub enum Profile {
15    /// There is no active work in the system. On a system that supports it, the device may be put
16    /// into a lower-power or suspended state at any time.
17    Idle = 1,
18    /// Some background activity is occurring that should prevent the system from dropping into a
19    /// non-running or suspended state (example: downloading an OTA, performing a backup, or
20    /// CPU-based hotword monitoring).
21    BackgroundActive = 2,
22    /// The device is providing some user-visible experience such as running an app in the
23    /// foreground or streaming audio, or has recently received interaction from a user.
24    UserActive = 3,
25}
26
27impl Profile {
28    #[inline]
29    pub fn from_primitive(prim: u32) -> Option<Self> {
30        match prim {
31            1 => Some(Self::Idle),
32            2 => Some(Self::BackgroundActive),
33            3 => Some(Self::UserActive),
34            _ => None,
35        }
36    }
37
38    #[inline]
39    pub const fn into_primitive(self) -> u32 {
40        self as u32
41    }
42}
43
44#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
45pub struct WatcherWatchResponse {
46    pub profile: Profile,
47}
48
49impl fidl::Persistable for WatcherWatchResponse {}
50
51pub mod watcher_ordinals {
52    pub const WATCH: u64 = 0x5f29be53ad34a947;
53}
54
55mod internal {
56    use super::*;
57    unsafe impl fidl::encoding::TypeMarker for Profile {
58        type Owned = Self;
59
60        #[inline(always)]
61        fn inline_align(_context: fidl::encoding::Context) -> usize {
62            std::mem::align_of::<u32>()
63        }
64
65        #[inline(always)]
66        fn inline_size(_context: fidl::encoding::Context) -> usize {
67            std::mem::size_of::<u32>()
68        }
69
70        #[inline(always)]
71        fn encode_is_copy() -> bool {
72            true
73        }
74
75        #[inline(always)]
76        fn decode_is_copy() -> bool {
77            false
78        }
79    }
80
81    impl fidl::encoding::ValueTypeMarker for Profile {
82        type Borrowed<'a> = Self;
83        #[inline(always)]
84        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
85            *value
86        }
87    }
88
89    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for Profile {
90        #[inline]
91        unsafe fn encode(
92            self,
93            encoder: &mut fidl::encoding::Encoder<'_, D>,
94            offset: usize,
95            _depth: fidl::encoding::Depth,
96        ) -> fidl::Result<()> {
97            encoder.debug_check_bounds::<Self>(offset);
98            encoder.write_num(self.into_primitive(), offset);
99            Ok(())
100        }
101    }
102
103    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Profile {
104        #[inline(always)]
105        fn new_empty() -> Self {
106            Self::Idle
107        }
108
109        #[inline]
110        unsafe fn decode(
111            &mut self,
112            decoder: &mut fidl::encoding::Decoder<'_, D>,
113            offset: usize,
114            _depth: fidl::encoding::Depth,
115        ) -> fidl::Result<()> {
116            decoder.debug_check_bounds::<Self>(offset);
117            let prim = decoder.read_num::<u32>(offset);
118
119            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
120            Ok(())
121        }
122    }
123
124    impl fidl::encoding::ValueTypeMarker for WatcherWatchResponse {
125        type Borrowed<'a> = &'a Self;
126        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
127            value
128        }
129    }
130
131    unsafe impl fidl::encoding::TypeMarker for WatcherWatchResponse {
132        type Owned = Self;
133
134        #[inline(always)]
135        fn inline_align(_context: fidl::encoding::Context) -> usize {
136            4
137        }
138
139        #[inline(always)]
140        fn inline_size(_context: fidl::encoding::Context) -> usize {
141            4
142        }
143    }
144
145    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<WatcherWatchResponse, D>
146        for &WatcherWatchResponse
147    {
148        #[inline]
149        unsafe fn encode(
150            self,
151            encoder: &mut fidl::encoding::Encoder<'_, D>,
152            offset: usize,
153            _depth: fidl::encoding::Depth,
154        ) -> fidl::Result<()> {
155            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
156            // Delegate to tuple encoding.
157            fidl::encoding::Encode::<WatcherWatchResponse, D>::encode(
158                (<Profile as fidl::encoding::ValueTypeMarker>::borrow(&self.profile),),
159                encoder,
160                offset,
161                _depth,
162            )
163        }
164    }
165    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Profile, D>>
166        fidl::encoding::Encode<WatcherWatchResponse, D> for (T0,)
167    {
168        #[inline]
169        unsafe fn encode(
170            self,
171            encoder: &mut fidl::encoding::Encoder<'_, D>,
172            offset: usize,
173            depth: fidl::encoding::Depth,
174        ) -> fidl::Result<()> {
175            encoder.debug_check_bounds::<WatcherWatchResponse>(offset);
176            // Zero out padding regions. There's no need to apply masks
177            // because the unmasked parts will be overwritten by fields.
178            // Write the fields.
179            self.0.encode(encoder, offset + 0, depth)?;
180            Ok(())
181        }
182    }
183
184    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WatcherWatchResponse {
185        #[inline(always)]
186        fn new_empty() -> Self {
187            Self { profile: fidl::new_empty!(Profile, D) }
188        }
189
190        #[inline]
191        unsafe fn decode(
192            &mut self,
193            decoder: &mut fidl::encoding::Decoder<'_, D>,
194            offset: usize,
195            _depth: fidl::encoding::Depth,
196        ) -> fidl::Result<()> {
197            decoder.debug_check_bounds::<Self>(offset);
198            // Verify that padding bytes are zero.
199            fidl::decode!(Profile, D, &mut self.profile, decoder, offset + 0, _depth)?;
200            Ok(())
201        }
202    }
203}