Skip to main content

fidl_fuchsia_hardware_power_stats_common/
fidl_fuchsia_hardware_power_stats_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
11pub const MAX_NAME_LEN: u8 = 64;
12
13/// A representation of a platform subsystem, peripheral or power domain that impacts the total device power consumption.
14#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct Entity {
16    /// Unique name.
17    pub name: String,
18    /// All possible states.
19    pub states: Vec<State>,
20}
21
22impl fidl::Persistable for Entity {}
23
24/// A representation that a power entity may reside in.
25#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
26pub struct State {
27    /// Unique id internally created by the server.
28    pub id: i32,
29    /// Unique name.
30    pub name: String,
31}
32
33impl fidl::Persistable for State {}
34
35#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
36pub struct StateResidency {
37    /// Unique id of the State.
38    pub id: i32,
39    /// Unique name of the state.
40    pub name: String,
41    /// Total time in milliseconds that the corresponding PowerEntity resided
42    /// in this state since boot.
43    pub total_time_ms: u64,
44    ///  Total number of times that the state was entered since boot.
45    pub entry_count: u32,
46    /// Last time this state was entered, in milliseconds on the timeline of the
47    /// hardware counter that timestamps the state's transitions, or 0 if the
48    /// provider does not track it. This timeline can run ahead of the boot
49    /// timeline (`zx_clock_get_boot`) by the time spent before the kernel started.
50    pub last_entry_timestamp_ms: u64,
51}
52
53impl fidl::Persistable for StateResidency {}
54
55/// A state residencies result for a power entity.
56#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
57pub struct Stats {
58    /// Name of the PowerEntity.
59    pub entity: String,
60    pub state_residency_data: Vec<StateResidency>,
61}
62
63impl fidl::Persistable for Stats {}
64
65pub mod device_ordinals {
66    pub const GET_STATS: u64 = 0x57fe9346ac73f056;
67    pub const GET_ENTITIES: u64 = 0xc34340e0675de11;
68}
69
70mod internal {
71    use super::*;
72
73    impl fidl::encoding::ValueTypeMarker for Entity {
74        type Borrowed<'a> = &'a Self;
75        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
76            value
77        }
78    }
79
80    unsafe impl fidl::encoding::TypeMarker for Entity {
81        type Owned = Self;
82
83        #[inline(always)]
84        fn inline_align(_context: fidl::encoding::Context) -> usize {
85            8
86        }
87
88        #[inline(always)]
89        fn inline_size(_context: fidl::encoding::Context) -> usize {
90            32
91        }
92    }
93
94    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Entity, D> for &Entity {
95        #[inline]
96        unsafe fn encode(
97            self,
98            encoder: &mut fidl::encoding::Encoder<'_, D>,
99            offset: usize,
100            _depth: fidl::encoding::Depth,
101        ) -> fidl::Result<()> {
102            encoder.debug_check_bounds::<Entity>(offset);
103            // Delegate to tuple encoding.
104            fidl::encoding::Encode::<Entity, D>::encode(
105                (
106                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(&self.name),
107                    <fidl::encoding::UnboundedVector<State> as fidl::encoding::ValueTypeMarker>::borrow(&self.states),
108                ),
109                encoder, offset, _depth
110            )
111        }
112    }
113    unsafe impl<
114        D: fidl::encoding::ResourceDialect,
115        T0: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
116        T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<State>, D>,
117    > fidl::encoding::Encode<Entity, D> for (T0, T1)
118    {
119        #[inline]
120        unsafe fn encode(
121            self,
122            encoder: &mut fidl::encoding::Encoder<'_, D>,
123            offset: usize,
124            depth: fidl::encoding::Depth,
125        ) -> fidl::Result<()> {
126            encoder.debug_check_bounds::<Entity>(offset);
127            // Zero out padding regions. There's no need to apply masks
128            // because the unmasked parts will be overwritten by fields.
129            // Write the fields.
130            self.0.encode(encoder, offset + 0, depth)?;
131            self.1.encode(encoder, offset + 16, depth)?;
132            Ok(())
133        }
134    }
135
136    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Entity {
137        #[inline(always)]
138        fn new_empty() -> Self {
139            Self {
140                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
141                states: fidl::new_empty!(fidl::encoding::UnboundedVector<State>, D),
142            }
143        }
144
145        #[inline]
146        unsafe fn decode(
147            &mut self,
148            decoder: &mut fidl::encoding::Decoder<'_, D>,
149            offset: usize,
150            _depth: fidl::encoding::Depth,
151        ) -> fidl::Result<()> {
152            decoder.debug_check_bounds::<Self>(offset);
153            // Verify that padding bytes are zero.
154            fidl::decode!(
155                fidl::encoding::BoundedString<64>,
156                D,
157                &mut self.name,
158                decoder,
159                offset + 0,
160                _depth
161            )?;
162            fidl::decode!(
163                fidl::encoding::UnboundedVector<State>,
164                D,
165                &mut self.states,
166                decoder,
167                offset + 16,
168                _depth
169            )?;
170            Ok(())
171        }
172    }
173
174    impl fidl::encoding::ValueTypeMarker for State {
175        type Borrowed<'a> = &'a Self;
176        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
177            value
178        }
179    }
180
181    unsafe impl fidl::encoding::TypeMarker for State {
182        type Owned = Self;
183
184        #[inline(always)]
185        fn inline_align(_context: fidl::encoding::Context) -> usize {
186            8
187        }
188
189        #[inline(always)]
190        fn inline_size(_context: fidl::encoding::Context) -> usize {
191            24
192        }
193    }
194
195    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<State, D> for &State {
196        #[inline]
197        unsafe fn encode(
198            self,
199            encoder: &mut fidl::encoding::Encoder<'_, D>,
200            offset: usize,
201            _depth: fidl::encoding::Depth,
202        ) -> fidl::Result<()> {
203            encoder.debug_check_bounds::<State>(offset);
204            // Delegate to tuple encoding.
205            fidl::encoding::Encode::<State, D>::encode(
206                (
207                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
208                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(
209                        &self.name,
210                    ),
211                ),
212                encoder,
213                offset,
214                _depth,
215            )
216        }
217    }
218    unsafe impl<
219        D: fidl::encoding::ResourceDialect,
220        T0: fidl::encoding::Encode<i32, D>,
221        T1: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
222    > fidl::encoding::Encode<State, D> for (T0, T1)
223    {
224        #[inline]
225        unsafe fn encode(
226            self,
227            encoder: &mut fidl::encoding::Encoder<'_, D>,
228            offset: usize,
229            depth: fidl::encoding::Depth,
230        ) -> fidl::Result<()> {
231            encoder.debug_check_bounds::<State>(offset);
232            // Zero out padding regions. There's no need to apply masks
233            // because the unmasked parts will be overwritten by fields.
234            unsafe {
235                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
236                (ptr as *mut u64).write_unaligned(0);
237            }
238            // Write the fields.
239            self.0.encode(encoder, offset + 0, depth)?;
240            self.1.encode(encoder, offset + 8, depth)?;
241            Ok(())
242        }
243    }
244
245    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for State {
246        #[inline(always)]
247        fn new_empty() -> Self {
248            Self {
249                id: fidl::new_empty!(i32, D),
250                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
251            }
252        }
253
254        #[inline]
255        unsafe fn decode(
256            &mut self,
257            decoder: &mut fidl::encoding::Decoder<'_, D>,
258            offset: usize,
259            _depth: fidl::encoding::Depth,
260        ) -> fidl::Result<()> {
261            decoder.debug_check_bounds::<Self>(offset);
262            // Verify that padding bytes are zero.
263            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
264            let padval = unsafe { (ptr as *const u64).read_unaligned() };
265            let mask = 0xffffffff00000000u64;
266            let maskedval = padval & mask;
267            if maskedval != 0 {
268                return Err(fidl::Error::NonZeroPadding {
269                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
270                });
271            }
272            fidl::decode!(i32, D, &mut self.id, decoder, offset + 0, _depth)?;
273            fidl::decode!(
274                fidl::encoding::BoundedString<64>,
275                D,
276                &mut self.name,
277                decoder,
278                offset + 8,
279                _depth
280            )?;
281            Ok(())
282        }
283    }
284
285    impl fidl::encoding::ValueTypeMarker for StateResidency {
286        type Borrowed<'a> = &'a Self;
287        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
288            value
289        }
290    }
291
292    unsafe impl fidl::encoding::TypeMarker for StateResidency {
293        type Owned = Self;
294
295        #[inline(always)]
296        fn inline_align(_context: fidl::encoding::Context) -> usize {
297            8
298        }
299
300        #[inline(always)]
301        fn inline_size(_context: fidl::encoding::Context) -> usize {
302            48
303        }
304    }
305
306    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<StateResidency, D>
307        for &StateResidency
308    {
309        #[inline]
310        unsafe fn encode(
311            self,
312            encoder: &mut fidl::encoding::Encoder<'_, D>,
313            offset: usize,
314            _depth: fidl::encoding::Depth,
315        ) -> fidl::Result<()> {
316            encoder.debug_check_bounds::<StateResidency>(offset);
317            // Delegate to tuple encoding.
318            fidl::encoding::Encode::<StateResidency, D>::encode(
319                (
320                    <i32 as fidl::encoding::ValueTypeMarker>::borrow(&self.id),
321                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(
322                        &self.name,
323                    ),
324                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.total_time_ms),
325                    <u32 as fidl::encoding::ValueTypeMarker>::borrow(&self.entry_count),
326                    <u64 as fidl::encoding::ValueTypeMarker>::borrow(&self.last_entry_timestamp_ms),
327                ),
328                encoder,
329                offset,
330                _depth,
331            )
332        }
333    }
334    unsafe impl<
335        D: fidl::encoding::ResourceDialect,
336        T0: fidl::encoding::Encode<i32, D>,
337        T1: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
338        T2: fidl::encoding::Encode<u64, D>,
339        T3: fidl::encoding::Encode<u32, D>,
340        T4: fidl::encoding::Encode<u64, D>,
341    > fidl::encoding::Encode<StateResidency, D> for (T0, T1, T2, T3, T4)
342    {
343        #[inline]
344        unsafe fn encode(
345            self,
346            encoder: &mut fidl::encoding::Encoder<'_, D>,
347            offset: usize,
348            depth: fidl::encoding::Depth,
349        ) -> fidl::Result<()> {
350            encoder.debug_check_bounds::<StateResidency>(offset);
351            // Zero out padding regions. There's no need to apply masks
352            // because the unmasked parts will be overwritten by fields.
353            unsafe {
354                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(0);
355                (ptr as *mut u64).write_unaligned(0);
356            }
357            unsafe {
358                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(32);
359                (ptr as *mut u64).write_unaligned(0);
360            }
361            // Write the fields.
362            self.0.encode(encoder, offset + 0, depth)?;
363            self.1.encode(encoder, offset + 8, depth)?;
364            self.2.encode(encoder, offset + 24, depth)?;
365            self.3.encode(encoder, offset + 32, depth)?;
366            self.4.encode(encoder, offset + 40, depth)?;
367            Ok(())
368        }
369    }
370
371    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for StateResidency {
372        #[inline(always)]
373        fn new_empty() -> Self {
374            Self {
375                id: fidl::new_empty!(i32, D),
376                name: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
377                total_time_ms: fidl::new_empty!(u64, D),
378                entry_count: fidl::new_empty!(u32, D),
379                last_entry_timestamp_ms: fidl::new_empty!(u64, D),
380            }
381        }
382
383        #[inline]
384        unsafe fn decode(
385            &mut self,
386            decoder: &mut fidl::encoding::Decoder<'_, D>,
387            offset: usize,
388            _depth: fidl::encoding::Depth,
389        ) -> fidl::Result<()> {
390            decoder.debug_check_bounds::<Self>(offset);
391            // Verify that padding bytes are zero.
392            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(0) };
393            let padval = unsafe { (ptr as *const u64).read_unaligned() };
394            let mask = 0xffffffff00000000u64;
395            let maskedval = padval & mask;
396            if maskedval != 0 {
397                return Err(fidl::Error::NonZeroPadding {
398                    padding_start: offset + 0 + ((mask as u64).trailing_zeros() / 8) as usize,
399                });
400            }
401            let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(32) };
402            let padval = unsafe { (ptr as *const u64).read_unaligned() };
403            let mask = 0xffffffff00000000u64;
404            let maskedval = padval & mask;
405            if maskedval != 0 {
406                return Err(fidl::Error::NonZeroPadding {
407                    padding_start: offset + 32 + ((mask as u64).trailing_zeros() / 8) as usize,
408                });
409            }
410            fidl::decode!(i32, D, &mut self.id, decoder, offset + 0, _depth)?;
411            fidl::decode!(
412                fidl::encoding::BoundedString<64>,
413                D,
414                &mut self.name,
415                decoder,
416                offset + 8,
417                _depth
418            )?;
419            fidl::decode!(u64, D, &mut self.total_time_ms, decoder, offset + 24, _depth)?;
420            fidl::decode!(u32, D, &mut self.entry_count, decoder, offset + 32, _depth)?;
421            fidl::decode!(u64, D, &mut self.last_entry_timestamp_ms, decoder, offset + 40, _depth)?;
422            Ok(())
423        }
424    }
425
426    impl fidl::encoding::ValueTypeMarker for Stats {
427        type Borrowed<'a> = &'a Self;
428        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
429            value
430        }
431    }
432
433    unsafe impl fidl::encoding::TypeMarker for Stats {
434        type Owned = Self;
435
436        #[inline(always)]
437        fn inline_align(_context: fidl::encoding::Context) -> usize {
438            8
439        }
440
441        #[inline(always)]
442        fn inline_size(_context: fidl::encoding::Context) -> usize {
443            32
444        }
445    }
446
447    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Stats, D> for &Stats {
448        #[inline]
449        unsafe fn encode(
450            self,
451            encoder: &mut fidl::encoding::Encoder<'_, D>,
452            offset: usize,
453            _depth: fidl::encoding::Depth,
454        ) -> fidl::Result<()> {
455            encoder.debug_check_bounds::<Stats>(offset);
456            // Delegate to tuple encoding.
457            fidl::encoding::Encode::<Stats, D>::encode(
458                (
459                    <fidl::encoding::BoundedString<64> as fidl::encoding::ValueTypeMarker>::borrow(&self.entity),
460                    <fidl::encoding::UnboundedVector<StateResidency> as fidl::encoding::ValueTypeMarker>::borrow(&self.state_residency_data),
461                ),
462                encoder, offset, _depth
463            )
464        }
465    }
466    unsafe impl<
467        D: fidl::encoding::ResourceDialect,
468        T0: fidl::encoding::Encode<fidl::encoding::BoundedString<64>, D>,
469        T1: fidl::encoding::Encode<fidl::encoding::UnboundedVector<StateResidency>, D>,
470    > fidl::encoding::Encode<Stats, D> for (T0, T1)
471    {
472        #[inline]
473        unsafe fn encode(
474            self,
475            encoder: &mut fidl::encoding::Encoder<'_, D>,
476            offset: usize,
477            depth: fidl::encoding::Depth,
478        ) -> fidl::Result<()> {
479            encoder.debug_check_bounds::<Stats>(offset);
480            // Zero out padding regions. There's no need to apply masks
481            // because the unmasked parts will be overwritten by fields.
482            // Write the fields.
483            self.0.encode(encoder, offset + 0, depth)?;
484            self.1.encode(encoder, offset + 16, depth)?;
485            Ok(())
486        }
487    }
488
489    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Stats {
490        #[inline(always)]
491        fn new_empty() -> Self {
492            Self {
493                entity: fidl::new_empty!(fidl::encoding::BoundedString<64>, D),
494                state_residency_data: fidl::new_empty!(
495                    fidl::encoding::UnboundedVector<StateResidency>,
496                    D
497                ),
498            }
499        }
500
501        #[inline]
502        unsafe fn decode(
503            &mut self,
504            decoder: &mut fidl::encoding::Decoder<'_, D>,
505            offset: usize,
506            _depth: fidl::encoding::Depth,
507        ) -> fidl::Result<()> {
508            decoder.debug_check_bounds::<Self>(offset);
509            // Verify that padding bytes are zero.
510            fidl::decode!(
511                fidl::encoding::BoundedString<64>,
512                D,
513                &mut self.entity,
514                decoder,
515                offset + 0,
516                _depth
517            )?;
518            fidl::decode!(
519                fidl::encoding::UnboundedVector<StateResidency>,
520                D,
521                &mut self.state_residency_data,
522                decoder,
523                offset + 16,
524                _depth
525            )?;
526            Ok(())
527        }
528    }
529}