fidl_fuchsia_power_suspend__common/
fidl_fuchsia_power_suspend__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/// A collection of statistics related to suspend/resume of the device.
12#[derive(Clone, Debug, Default, PartialEq)]
13pub struct SuspendStats {
14    /// The number of times the device has successfully suspended.
15    pub success_count: Option<u64>,
16    /// The number of times the device has failed to suspend.
17    pub fail_count: Option<u64>,
18    /// The error code logged after the last failed suspend attempt.
19    pub last_failed_error: Option<i32>,
20    /// The amount of time spent in the previous suspend state.
21    /// May not be available on all platforms.
22    pub last_time_in_suspend: Option<i64>,
23    /// The amount of time spent performing suspend and resume operations for
24    /// the previous suspend state.
25    /// Suspend and resume operations are those actions taken by the platform in
26    /// order to enter and exit, respectively, a suspended state.
27    pub last_time_in_suspend_operations: Option<i64>,
28    /// The total amount of time spent in a suspended state.
29    pub total_time_in_suspend: Option<i64>,
30    #[doc(hidden)]
31    pub __source_breaking: fidl::marker::SourceBreaking,
32}
33
34impl fidl::Persistable for SuspendStats {}
35
36pub mod stats_ordinals {
37    pub const WATCH: u64 = 0x1c90507c87636a84;
38}
39
40mod internal {
41    use super::*;
42
43    impl SuspendStats {
44        #[inline(always)]
45        fn max_ordinal_present(&self) -> u64 {
46            if let Some(_) = self.total_time_in_suspend {
47                return 6;
48            }
49            if let Some(_) = self.last_time_in_suspend_operations {
50                return 5;
51            }
52            if let Some(_) = self.last_time_in_suspend {
53                return 4;
54            }
55            if let Some(_) = self.last_failed_error {
56                return 3;
57            }
58            if let Some(_) = self.fail_count {
59                return 2;
60            }
61            if let Some(_) = self.success_count {
62                return 1;
63            }
64            0
65        }
66    }
67
68    impl fidl::encoding::ValueTypeMarker for SuspendStats {
69        type Borrowed<'a> = &'a Self;
70        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
71            value
72        }
73    }
74
75    unsafe impl fidl::encoding::TypeMarker for SuspendStats {
76        type Owned = Self;
77
78        #[inline(always)]
79        fn inline_align(_context: fidl::encoding::Context) -> usize {
80            8
81        }
82
83        #[inline(always)]
84        fn inline_size(_context: fidl::encoding::Context) -> usize {
85            16
86        }
87    }
88
89    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<SuspendStats, D>
90        for &SuspendStats
91    {
92        unsafe fn encode(
93            self,
94            encoder: &mut fidl::encoding::Encoder<'_, D>,
95            offset: usize,
96            mut depth: fidl::encoding::Depth,
97        ) -> fidl::Result<()> {
98            encoder.debug_check_bounds::<SuspendStats>(offset);
99            // Vector header
100            let max_ordinal: u64 = self.max_ordinal_present();
101            encoder.write_num(max_ordinal, offset);
102            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
103            // Calling encoder.out_of_line_offset(0) is not allowed.
104            if max_ordinal == 0 {
105                return Ok(());
106            }
107            depth.increment()?;
108            let envelope_size = 8;
109            let bytes_len = max_ordinal as usize * envelope_size;
110            #[allow(unused_variables)]
111            let offset = encoder.out_of_line_offset(bytes_len);
112            let mut _prev_end_offset: usize = 0;
113            if 1 > max_ordinal {
114                return Ok(());
115            }
116
117            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
118            // are envelope_size bytes.
119            let cur_offset: usize = (1 - 1) * envelope_size;
120
121            // Zero reserved fields.
122            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
123
124            // Safety:
125            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
126            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
127            //   envelope_size bytes, there is always sufficient room.
128            fidl::encoding::encode_in_envelope_optional::<u64, D>(
129                self.success_count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
130                encoder,
131                offset + cur_offset,
132                depth,
133            )?;
134
135            _prev_end_offset = cur_offset + envelope_size;
136            if 2 > max_ordinal {
137                return Ok(());
138            }
139
140            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
141            // are envelope_size bytes.
142            let cur_offset: usize = (2 - 1) * envelope_size;
143
144            // Zero reserved fields.
145            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
146
147            // Safety:
148            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
149            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
150            //   envelope_size bytes, there is always sufficient room.
151            fidl::encoding::encode_in_envelope_optional::<u64, D>(
152                self.fail_count.as_ref().map(<u64 as fidl::encoding::ValueTypeMarker>::borrow),
153                encoder,
154                offset + cur_offset,
155                depth,
156            )?;
157
158            _prev_end_offset = cur_offset + envelope_size;
159            if 3 > max_ordinal {
160                return Ok(());
161            }
162
163            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
164            // are envelope_size bytes.
165            let cur_offset: usize = (3 - 1) * envelope_size;
166
167            // Zero reserved fields.
168            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
169
170            // Safety:
171            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
172            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
173            //   envelope_size bytes, there is always sufficient room.
174            fidl::encoding::encode_in_envelope_optional::<i32, D>(
175                self.last_failed_error
176                    .as_ref()
177                    .map(<i32 as fidl::encoding::ValueTypeMarker>::borrow),
178                encoder,
179                offset + cur_offset,
180                depth,
181            )?;
182
183            _prev_end_offset = cur_offset + envelope_size;
184            if 4 > max_ordinal {
185                return Ok(());
186            }
187
188            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
189            // are envelope_size bytes.
190            let cur_offset: usize = (4 - 1) * envelope_size;
191
192            // Zero reserved fields.
193            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
194
195            // Safety:
196            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
197            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
198            //   envelope_size bytes, there is always sufficient room.
199            fidl::encoding::encode_in_envelope_optional::<i64, D>(
200                self.last_time_in_suspend
201                    .as_ref()
202                    .map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
203                encoder,
204                offset + cur_offset,
205                depth,
206            )?;
207
208            _prev_end_offset = cur_offset + envelope_size;
209            if 5 > max_ordinal {
210                return Ok(());
211            }
212
213            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
214            // are envelope_size bytes.
215            let cur_offset: usize = (5 - 1) * envelope_size;
216
217            // Zero reserved fields.
218            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
219
220            // Safety:
221            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
222            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
223            //   envelope_size bytes, there is always sufficient room.
224            fidl::encoding::encode_in_envelope_optional::<i64, D>(
225                self.last_time_in_suspend_operations
226                    .as_ref()
227                    .map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
228                encoder,
229                offset + cur_offset,
230                depth,
231            )?;
232
233            _prev_end_offset = cur_offset + envelope_size;
234            if 6 > max_ordinal {
235                return Ok(());
236            }
237
238            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
239            // are envelope_size bytes.
240            let cur_offset: usize = (6 - 1) * envelope_size;
241
242            // Zero reserved fields.
243            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
244
245            // Safety:
246            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
247            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
248            //   envelope_size bytes, there is always sufficient room.
249            fidl::encoding::encode_in_envelope_optional::<i64, D>(
250                self.total_time_in_suspend
251                    .as_ref()
252                    .map(<i64 as fidl::encoding::ValueTypeMarker>::borrow),
253                encoder,
254                offset + cur_offset,
255                depth,
256            )?;
257
258            _prev_end_offset = cur_offset + envelope_size;
259
260            Ok(())
261        }
262    }
263
264    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SuspendStats {
265        #[inline(always)]
266        fn new_empty() -> Self {
267            Self::default()
268        }
269
270        unsafe fn decode(
271            &mut self,
272            decoder: &mut fidl::encoding::Decoder<'_, D>,
273            offset: usize,
274            mut depth: fidl::encoding::Depth,
275        ) -> fidl::Result<()> {
276            decoder.debug_check_bounds::<Self>(offset);
277            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
278                None => return Err(fidl::Error::NotNullable),
279                Some(len) => len,
280            };
281            // Calling decoder.out_of_line_offset(0) is not allowed.
282            if len == 0 {
283                return Ok(());
284            };
285            depth.increment()?;
286            let envelope_size = 8;
287            let bytes_len = len * envelope_size;
288            let offset = decoder.out_of_line_offset(bytes_len)?;
289            // Decode the envelope for each type.
290            let mut _next_ordinal_to_read = 0;
291            let mut next_offset = offset;
292            let end_offset = offset + bytes_len;
293            _next_ordinal_to_read += 1;
294            if next_offset >= end_offset {
295                return Ok(());
296            }
297
298            // Decode unknown envelopes for gaps in ordinals.
299            while _next_ordinal_to_read < 1 {
300                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
301                _next_ordinal_to_read += 1;
302                next_offset += envelope_size;
303            }
304
305            let next_out_of_line = decoder.next_out_of_line();
306            let handles_before = decoder.remaining_handles();
307            if let Some((inlined, num_bytes, num_handles)) =
308                fidl::encoding::decode_envelope_header(decoder, next_offset)?
309            {
310                let member_inline_size =
311                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
312                if inlined != (member_inline_size <= 4) {
313                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
314                }
315                let inner_offset;
316                let mut inner_depth = depth.clone();
317                if inlined {
318                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
319                    inner_offset = next_offset;
320                } else {
321                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
322                    inner_depth.increment()?;
323                }
324                let val_ref = self.success_count.get_or_insert_with(|| fidl::new_empty!(u64, D));
325                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
326                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
327                {
328                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
329                }
330                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
331                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
332                }
333            }
334
335            next_offset += envelope_size;
336            _next_ordinal_to_read += 1;
337            if next_offset >= end_offset {
338                return Ok(());
339            }
340
341            // Decode unknown envelopes for gaps in ordinals.
342            while _next_ordinal_to_read < 2 {
343                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
344                _next_ordinal_to_read += 1;
345                next_offset += envelope_size;
346            }
347
348            let next_out_of_line = decoder.next_out_of_line();
349            let handles_before = decoder.remaining_handles();
350            if let Some((inlined, num_bytes, num_handles)) =
351                fidl::encoding::decode_envelope_header(decoder, next_offset)?
352            {
353                let member_inline_size =
354                    <u64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
355                if inlined != (member_inline_size <= 4) {
356                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
357                }
358                let inner_offset;
359                let mut inner_depth = depth.clone();
360                if inlined {
361                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
362                    inner_offset = next_offset;
363                } else {
364                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
365                    inner_depth.increment()?;
366                }
367                let val_ref = self.fail_count.get_or_insert_with(|| fidl::new_empty!(u64, D));
368                fidl::decode!(u64, D, val_ref, decoder, inner_offset, inner_depth)?;
369                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
370                {
371                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
372                }
373                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
374                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
375                }
376            }
377
378            next_offset += envelope_size;
379            _next_ordinal_to_read += 1;
380            if next_offset >= end_offset {
381                return Ok(());
382            }
383
384            // Decode unknown envelopes for gaps in ordinals.
385            while _next_ordinal_to_read < 3 {
386                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
387                _next_ordinal_to_read += 1;
388                next_offset += envelope_size;
389            }
390
391            let next_out_of_line = decoder.next_out_of_line();
392            let handles_before = decoder.remaining_handles();
393            if let Some((inlined, num_bytes, num_handles)) =
394                fidl::encoding::decode_envelope_header(decoder, next_offset)?
395            {
396                let member_inline_size =
397                    <i32 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
398                if inlined != (member_inline_size <= 4) {
399                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
400                }
401                let inner_offset;
402                let mut inner_depth = depth.clone();
403                if inlined {
404                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
405                    inner_offset = next_offset;
406                } else {
407                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
408                    inner_depth.increment()?;
409                }
410                let val_ref =
411                    self.last_failed_error.get_or_insert_with(|| fidl::new_empty!(i32, D));
412                fidl::decode!(i32, D, val_ref, decoder, inner_offset, inner_depth)?;
413                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
414                {
415                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
416                }
417                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
418                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
419                }
420            }
421
422            next_offset += envelope_size;
423            _next_ordinal_to_read += 1;
424            if next_offset >= end_offset {
425                return Ok(());
426            }
427
428            // Decode unknown envelopes for gaps in ordinals.
429            while _next_ordinal_to_read < 4 {
430                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
431                _next_ordinal_to_read += 1;
432                next_offset += envelope_size;
433            }
434
435            let next_out_of_line = decoder.next_out_of_line();
436            let handles_before = decoder.remaining_handles();
437            if let Some((inlined, num_bytes, num_handles)) =
438                fidl::encoding::decode_envelope_header(decoder, next_offset)?
439            {
440                let member_inline_size =
441                    <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
442                if inlined != (member_inline_size <= 4) {
443                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
444                }
445                let inner_offset;
446                let mut inner_depth = depth.clone();
447                if inlined {
448                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
449                    inner_offset = next_offset;
450                } else {
451                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
452                    inner_depth.increment()?;
453                }
454                let val_ref =
455                    self.last_time_in_suspend.get_or_insert_with(|| fidl::new_empty!(i64, D));
456                fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
457                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
458                {
459                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
460                }
461                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
462                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
463                }
464            }
465
466            next_offset += envelope_size;
467            _next_ordinal_to_read += 1;
468            if next_offset >= end_offset {
469                return Ok(());
470            }
471
472            // Decode unknown envelopes for gaps in ordinals.
473            while _next_ordinal_to_read < 5 {
474                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
475                _next_ordinal_to_read += 1;
476                next_offset += envelope_size;
477            }
478
479            let next_out_of_line = decoder.next_out_of_line();
480            let handles_before = decoder.remaining_handles();
481            if let Some((inlined, num_bytes, num_handles)) =
482                fidl::encoding::decode_envelope_header(decoder, next_offset)?
483            {
484                let member_inline_size =
485                    <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
486                if inlined != (member_inline_size <= 4) {
487                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
488                }
489                let inner_offset;
490                let mut inner_depth = depth.clone();
491                if inlined {
492                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
493                    inner_offset = next_offset;
494                } else {
495                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
496                    inner_depth.increment()?;
497                }
498                let val_ref = self
499                    .last_time_in_suspend_operations
500                    .get_or_insert_with(|| fidl::new_empty!(i64, D));
501                fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
502                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
503                {
504                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
505                }
506                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
507                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
508                }
509            }
510
511            next_offset += envelope_size;
512            _next_ordinal_to_read += 1;
513            if next_offset >= end_offset {
514                return Ok(());
515            }
516
517            // Decode unknown envelopes for gaps in ordinals.
518            while _next_ordinal_to_read < 6 {
519                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
520                _next_ordinal_to_read += 1;
521                next_offset += envelope_size;
522            }
523
524            let next_out_of_line = decoder.next_out_of_line();
525            let handles_before = decoder.remaining_handles();
526            if let Some((inlined, num_bytes, num_handles)) =
527                fidl::encoding::decode_envelope_header(decoder, next_offset)?
528            {
529                let member_inline_size =
530                    <i64 as fidl::encoding::TypeMarker>::inline_size(decoder.context);
531                if inlined != (member_inline_size <= 4) {
532                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
533                }
534                let inner_offset;
535                let mut inner_depth = depth.clone();
536                if inlined {
537                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
538                    inner_offset = next_offset;
539                } else {
540                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
541                    inner_depth.increment()?;
542                }
543                let val_ref =
544                    self.total_time_in_suspend.get_or_insert_with(|| fidl::new_empty!(i64, D));
545                fidl::decode!(i64, D, val_ref, decoder, inner_offset, inner_depth)?;
546                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
547                {
548                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
549                }
550                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
551                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
552                }
553            }
554
555            next_offset += envelope_size;
556
557            // Decode the remaining unknown envelopes.
558            while next_offset < end_offset {
559                _next_ordinal_to_read += 1;
560                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
561                next_offset += envelope_size;
562            }
563
564            Ok(())
565        }
566    }
567}