fidl_fuchsia_time_alarms__common/
fidl_fuchsia_time_alarms__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 type AlarmId = String;
12
13/// WakeError describes the error code that can be returned from wake
14/// alarm API calls.
15#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum WakeError {
17    /// A catch all error can be used for any error during the execution
18    /// of any FIDL calls above.  Add new enum values for finer-grained
19    /// error reports.
20    Unspecified,
21    /// This alarm was dropped. There will be no wakes resulting from
22    /// this alarm.
23    Dropped,
24    /// The server end encountered an error internal to its code, which should
25    /// not ever happen in normal operation. Receiving this error means that the
26    /// server end of the connection has a bug that must be fixed.
27    Internal,
28    #[doc(hidden)]
29    __SourceBreaking { unknown_ordinal: u32 },
30}
31
32/// Pattern that matches an unknown `WakeError` member.
33#[macro_export]
34macro_rules! WakeErrorUnknown {
35    () => {
36        _
37    };
38}
39
40impl WakeError {
41    #[inline]
42    pub fn from_primitive(prim: u32) -> Option<Self> {
43        match prim {
44            1 => Some(Self::Unspecified),
45            2 => Some(Self::Dropped),
46            3 => Some(Self::Internal),
47            _ => None,
48        }
49    }
50
51    #[inline]
52    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
53        match prim {
54            1 => Self::Unspecified,
55            2 => Self::Dropped,
56            3 => Self::Internal,
57            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
58        }
59    }
60
61    #[inline]
62    pub fn unknown() -> Self {
63        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
64    }
65
66    #[inline]
67    pub const fn into_primitive(self) -> u32 {
68        match self {
69            Self::Unspecified => 1,
70            Self::Dropped => 2,
71            Self::Internal => 3,
72            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
73        }
74    }
75
76    #[inline]
77    pub fn is_unknown(&self) -> bool {
78        match self {
79            Self::__SourceBreaking { unknown_ordinal: _ } => true,
80            _ => false,
81        }
82    }
83}
84
85#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
86pub struct ClientSideBatonManagementCancelRequest {
87    /// The unique identifier of the alarm to cancel.
88    ///
89    /// The alarm identified by `alarm_id` is canceled, and will no
90    /// longer be expected to fire. The respective `SetAndWait` will
91    /// return [WakeError::DROPPED].
92    ///
93    /// A race condition is possible where the alarm fires while
94    /// the Cancel call is being processed, or even slightly later.
95    /// The caller must handle such an event gracefully.
96    pub alarm_id: String,
97}
98
99impl fidl::Persistable for ClientSideBatonManagementCancelRequest {}
100
101#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
102pub struct ClientSideBatonManagementCancelSyncRequest {
103    pub alarm_id: String,
104}
105
106impl fidl::Persistable for ClientSideBatonManagementCancelSyncRequest {}
107
108#[derive(Clone, Debug, Default, PartialEq)]
109pub struct WakeGetPropertiesResponse {
110    /// Set to true if the wake alarms functionality is supported.
111    /// The wake alarms may be unavailable if the hardware does
112    /// not have the required circuitry.
113    pub is_supported: Option<bool>,
114    #[doc(hidden)]
115    pub __source_breaking: fidl::marker::SourceBreaking,
116}
117
118impl fidl::Persistable for WakeGetPropertiesResponse {}
119
120pub mod client_side_baton_management_ordinals {
121    pub const SET_AND_WAIT: u64 = 0x46ea462fcd0246c0;
122    pub const CANCEL: u64 = 0x2d59ccae0bda24e3;
123    pub const CANCEL_SYNC: u64 = 0x397477d8067269c3;
124}
125
126pub mod wake_ordinals {
127    pub const SET_AND_WAIT: u64 = 0x46ea462fcd0246c0;
128    pub const CANCEL: u64 = 0x2d59ccae0bda24e3;
129    pub const CANCEL_SYNC: u64 = 0x397477d8067269c3;
130    pub const GET_PROPERTIES: u64 = 0x486a204b6463420;
131}
132
133mod internal {
134    use super::*;
135    unsafe impl fidl::encoding::TypeMarker for WakeError {
136        type Owned = Self;
137
138        #[inline(always)]
139        fn inline_align(_context: fidl::encoding::Context) -> usize {
140            std::mem::align_of::<u32>()
141        }
142
143        #[inline(always)]
144        fn inline_size(_context: fidl::encoding::Context) -> usize {
145            std::mem::size_of::<u32>()
146        }
147
148        #[inline(always)]
149        fn encode_is_copy() -> bool {
150            false
151        }
152
153        #[inline(always)]
154        fn decode_is_copy() -> bool {
155            false
156        }
157    }
158
159    impl fidl::encoding::ValueTypeMarker for WakeError {
160        type Borrowed<'a> = Self;
161        #[inline(always)]
162        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
163            *value
164        }
165    }
166
167    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D> for WakeError {
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::<Self>(offset);
176            encoder.write_num(self.into_primitive(), offset);
177            Ok(())
178        }
179    }
180
181    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WakeError {
182        #[inline(always)]
183        fn new_empty() -> Self {
184            Self::unknown()
185        }
186
187        #[inline]
188        unsafe fn decode(
189            &mut self,
190            decoder: &mut fidl::encoding::Decoder<'_, D>,
191            offset: usize,
192            _depth: fidl::encoding::Depth,
193        ) -> fidl::Result<()> {
194            decoder.debug_check_bounds::<Self>(offset);
195            let prim = decoder.read_num::<u32>(offset);
196
197            *self = Self::from_primitive_allow_unknown(prim);
198            Ok(())
199        }
200    }
201
202    impl fidl::encoding::ValueTypeMarker for ClientSideBatonManagementCancelRequest {
203        type Borrowed<'a> = &'a Self;
204        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
205            value
206        }
207    }
208
209    unsafe impl fidl::encoding::TypeMarker for ClientSideBatonManagementCancelRequest {
210        type Owned = Self;
211
212        #[inline(always)]
213        fn inline_align(_context: fidl::encoding::Context) -> usize {
214            8
215        }
216
217        #[inline(always)]
218        fn inline_size(_context: fidl::encoding::Context) -> usize {
219            16
220        }
221    }
222
223    unsafe impl<D: fidl::encoding::ResourceDialect>
224        fidl::encoding::Encode<ClientSideBatonManagementCancelRequest, D>
225        for &ClientSideBatonManagementCancelRequest
226    {
227        #[inline]
228        unsafe fn encode(
229            self,
230            encoder: &mut fidl::encoding::Encoder<'_, D>,
231            offset: usize,
232            _depth: fidl::encoding::Depth,
233        ) -> fidl::Result<()> {
234            encoder.debug_check_bounds::<ClientSideBatonManagementCancelRequest>(offset);
235            // Delegate to tuple encoding.
236            fidl::encoding::Encode::<ClientSideBatonManagementCancelRequest, D>::encode(
237                (<fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
238                    &self.alarm_id,
239                ),),
240                encoder,
241                offset,
242                _depth,
243            )
244        }
245    }
246    unsafe impl<
247            D: fidl::encoding::ResourceDialect,
248            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
249        > fidl::encoding::Encode<ClientSideBatonManagementCancelRequest, D> for (T0,)
250    {
251        #[inline]
252        unsafe fn encode(
253            self,
254            encoder: &mut fidl::encoding::Encoder<'_, D>,
255            offset: usize,
256            depth: fidl::encoding::Depth,
257        ) -> fidl::Result<()> {
258            encoder.debug_check_bounds::<ClientSideBatonManagementCancelRequest>(offset);
259            // Zero out padding regions. There's no need to apply masks
260            // because the unmasked parts will be overwritten by fields.
261            // Write the fields.
262            self.0.encode(encoder, offset + 0, depth)?;
263            Ok(())
264        }
265    }
266
267    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
268        for ClientSideBatonManagementCancelRequest
269    {
270        #[inline(always)]
271        fn new_empty() -> Self {
272            Self { alarm_id: fidl::new_empty!(fidl::encoding::BoundedString<128>, D) }
273        }
274
275        #[inline]
276        unsafe fn decode(
277            &mut self,
278            decoder: &mut fidl::encoding::Decoder<'_, D>,
279            offset: usize,
280            _depth: fidl::encoding::Depth,
281        ) -> fidl::Result<()> {
282            decoder.debug_check_bounds::<Self>(offset);
283            // Verify that padding bytes are zero.
284            fidl::decode!(
285                fidl::encoding::BoundedString<128>,
286                D,
287                &mut self.alarm_id,
288                decoder,
289                offset + 0,
290                _depth
291            )?;
292            Ok(())
293        }
294    }
295
296    impl fidl::encoding::ValueTypeMarker for ClientSideBatonManagementCancelSyncRequest {
297        type Borrowed<'a> = &'a Self;
298        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
299            value
300        }
301    }
302
303    unsafe impl fidl::encoding::TypeMarker for ClientSideBatonManagementCancelSyncRequest {
304        type Owned = Self;
305
306        #[inline(always)]
307        fn inline_align(_context: fidl::encoding::Context) -> usize {
308            8
309        }
310
311        #[inline(always)]
312        fn inline_size(_context: fidl::encoding::Context) -> usize {
313            16
314        }
315    }
316
317    unsafe impl<D: fidl::encoding::ResourceDialect>
318        fidl::encoding::Encode<ClientSideBatonManagementCancelSyncRequest, D>
319        for &ClientSideBatonManagementCancelSyncRequest
320    {
321        #[inline]
322        unsafe fn encode(
323            self,
324            encoder: &mut fidl::encoding::Encoder<'_, D>,
325            offset: usize,
326            _depth: fidl::encoding::Depth,
327        ) -> fidl::Result<()> {
328            encoder.debug_check_bounds::<ClientSideBatonManagementCancelSyncRequest>(offset);
329            // Delegate to tuple encoding.
330            fidl::encoding::Encode::<ClientSideBatonManagementCancelSyncRequest, D>::encode(
331                (<fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
332                    &self.alarm_id,
333                ),),
334                encoder,
335                offset,
336                _depth,
337            )
338        }
339    }
340    unsafe impl<
341            D: fidl::encoding::ResourceDialect,
342            T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
343        > fidl::encoding::Encode<ClientSideBatonManagementCancelSyncRequest, D> for (T0,)
344    {
345        #[inline]
346        unsafe fn encode(
347            self,
348            encoder: &mut fidl::encoding::Encoder<'_, D>,
349            offset: usize,
350            depth: fidl::encoding::Depth,
351        ) -> fidl::Result<()> {
352            encoder.debug_check_bounds::<ClientSideBatonManagementCancelSyncRequest>(offset);
353            // Zero out padding regions. There's no need to apply masks
354            // because the unmasked parts will be overwritten by fields.
355            // Write the fields.
356            self.0.encode(encoder, offset + 0, depth)?;
357            Ok(())
358        }
359    }
360
361    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
362        for ClientSideBatonManagementCancelSyncRequest
363    {
364        #[inline(always)]
365        fn new_empty() -> Self {
366            Self { alarm_id: fidl::new_empty!(fidl::encoding::BoundedString<128>, D) }
367        }
368
369        #[inline]
370        unsafe fn decode(
371            &mut self,
372            decoder: &mut fidl::encoding::Decoder<'_, D>,
373            offset: usize,
374            _depth: fidl::encoding::Depth,
375        ) -> fidl::Result<()> {
376            decoder.debug_check_bounds::<Self>(offset);
377            // Verify that padding bytes are zero.
378            fidl::decode!(
379                fidl::encoding::BoundedString<128>,
380                D,
381                &mut self.alarm_id,
382                decoder,
383                offset + 0,
384                _depth
385            )?;
386            Ok(())
387        }
388    }
389
390    impl WakeGetPropertiesResponse {
391        #[inline(always)]
392        fn max_ordinal_present(&self) -> u64 {
393            if let Some(_) = self.is_supported {
394                return 1;
395            }
396            0
397        }
398    }
399
400    impl fidl::encoding::ValueTypeMarker for WakeGetPropertiesResponse {
401        type Borrowed<'a> = &'a Self;
402        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
403            value
404        }
405    }
406
407    unsafe impl fidl::encoding::TypeMarker for WakeGetPropertiesResponse {
408        type Owned = Self;
409
410        #[inline(always)]
411        fn inline_align(_context: fidl::encoding::Context) -> usize {
412            8
413        }
414
415        #[inline(always)]
416        fn inline_size(_context: fidl::encoding::Context) -> usize {
417            16
418        }
419    }
420
421    unsafe impl<D: fidl::encoding::ResourceDialect>
422        fidl::encoding::Encode<WakeGetPropertiesResponse, D> for &WakeGetPropertiesResponse
423    {
424        unsafe fn encode(
425            self,
426            encoder: &mut fidl::encoding::Encoder<'_, D>,
427            offset: usize,
428            mut depth: fidl::encoding::Depth,
429        ) -> fidl::Result<()> {
430            encoder.debug_check_bounds::<WakeGetPropertiesResponse>(offset);
431            // Vector header
432            let max_ordinal: u64 = self.max_ordinal_present();
433            encoder.write_num(max_ordinal, offset);
434            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
435            // Calling encoder.out_of_line_offset(0) is not allowed.
436            if max_ordinal == 0 {
437                return Ok(());
438            }
439            depth.increment()?;
440            let envelope_size = 8;
441            let bytes_len = max_ordinal as usize * envelope_size;
442            #[allow(unused_variables)]
443            let offset = encoder.out_of_line_offset(bytes_len);
444            let mut _prev_end_offset: usize = 0;
445            if 1 > max_ordinal {
446                return Ok(());
447            }
448
449            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
450            // are envelope_size bytes.
451            let cur_offset: usize = (1 - 1) * envelope_size;
452
453            // Zero reserved fields.
454            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
455
456            // Safety:
457            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
458            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
459            //   envelope_size bytes, there is always sufficient room.
460            fidl::encoding::encode_in_envelope_optional::<bool, D>(
461                self.is_supported.as_ref().map(<bool as fidl::encoding::ValueTypeMarker>::borrow),
462                encoder,
463                offset + cur_offset,
464                depth,
465            )?;
466
467            _prev_end_offset = cur_offset + envelope_size;
468
469            Ok(())
470        }
471    }
472
473    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
474        for WakeGetPropertiesResponse
475    {
476        #[inline(always)]
477        fn new_empty() -> Self {
478            Self::default()
479        }
480
481        unsafe fn decode(
482            &mut self,
483            decoder: &mut fidl::encoding::Decoder<'_, D>,
484            offset: usize,
485            mut depth: fidl::encoding::Depth,
486        ) -> fidl::Result<()> {
487            decoder.debug_check_bounds::<Self>(offset);
488            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
489                None => return Err(fidl::Error::NotNullable),
490                Some(len) => len,
491            };
492            // Calling decoder.out_of_line_offset(0) is not allowed.
493            if len == 0 {
494                return Ok(());
495            };
496            depth.increment()?;
497            let envelope_size = 8;
498            let bytes_len = len * envelope_size;
499            let offset = decoder.out_of_line_offset(bytes_len)?;
500            // Decode the envelope for each type.
501            let mut _next_ordinal_to_read = 0;
502            let mut next_offset = offset;
503            let end_offset = offset + bytes_len;
504            _next_ordinal_to_read += 1;
505            if next_offset >= end_offset {
506                return Ok(());
507            }
508
509            // Decode unknown envelopes for gaps in ordinals.
510            while _next_ordinal_to_read < 1 {
511                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
512                _next_ordinal_to_read += 1;
513                next_offset += envelope_size;
514            }
515
516            let next_out_of_line = decoder.next_out_of_line();
517            let handles_before = decoder.remaining_handles();
518            if let Some((inlined, num_bytes, num_handles)) =
519                fidl::encoding::decode_envelope_header(decoder, next_offset)?
520            {
521                let member_inline_size =
522                    <bool as fidl::encoding::TypeMarker>::inline_size(decoder.context);
523                if inlined != (member_inline_size <= 4) {
524                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
525                }
526                let inner_offset;
527                let mut inner_depth = depth.clone();
528                if inlined {
529                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
530                    inner_offset = next_offset;
531                } else {
532                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
533                    inner_depth.increment()?;
534                }
535                let val_ref = self.is_supported.get_or_insert_with(|| fidl::new_empty!(bool, D));
536                fidl::decode!(bool, D, val_ref, decoder, inner_offset, inner_depth)?;
537                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
538                {
539                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
540                }
541                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
542                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
543                }
544            }
545
546            next_offset += envelope_size;
547
548            // Decode the remaining unknown envelopes.
549            while next_offset < end_offset {
550                _next_ordinal_to_read += 1;
551                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
552                next_offset += envelope_size;
553            }
554
555            Ok(())
556        }
557    }
558}