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
11/// A unique identifier for an alarm.
12///
13/// This alias is used to identify alarms within a single `WakeAlarms`
14/// connection. It is the client's responsibility to ensure that the IDs are
15/// unique for all active alarms.
16pub type AlarmId = String;
17
18/// Describes the error codes that can be returned from `WakeAlarms` API calls.
19#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
20pub enum WakeAlarmsError {
21    /// A new failure mode has been observed that has not yet been assigned an
22    /// error code.
23    ///
24    /// This indicates that the API version may need to be updated.
25    Unspecified,
26    /// The alarm was canceled or rescheduled by the API user.
27    Dropped,
28    /// The server end encountered an error internal to its code, which should
29    /// not ever happen in normal operation. Receiving this error means that the
30    /// server end of the connection has a bug that must be fixed.
31    Internal,
32    /// A parameter provided by the user is incorrect. For example, providing
33    /// an empty value for `alarm_id`.
34    InvalidArgs,
35    #[doc(hidden)]
36    __SourceBreaking { unknown_ordinal: u32 },
37}
38
39/// Pattern that matches an unknown `WakeAlarmsError` member.
40#[macro_export]
41macro_rules! WakeAlarmsErrorUnknown {
42    () => {
43        _
44    };
45}
46
47impl WakeAlarmsError {
48    #[inline]
49    pub fn from_primitive(prim: u32) -> Option<Self> {
50        match prim {
51            1 => Some(Self::Unspecified),
52            2 => Some(Self::Dropped),
53            3 => Some(Self::Internal),
54            4 => Some(Self::InvalidArgs),
55            _ => None,
56        }
57    }
58
59    #[inline]
60    pub fn from_primitive_allow_unknown(prim: u32) -> Self {
61        match prim {
62            1 => Self::Unspecified,
63            2 => Self::Dropped,
64            3 => Self::Internal,
65            4 => Self::InvalidArgs,
66            unknown_ordinal => Self::__SourceBreaking { unknown_ordinal },
67        }
68    }
69
70    #[inline]
71    pub fn unknown() -> Self {
72        Self::__SourceBreaking { unknown_ordinal: 0xffffffff }
73    }
74
75    #[inline]
76    pub const fn into_primitive(self) -> u32 {
77        match self {
78            Self::Unspecified => 1,
79            Self::Dropped => 2,
80            Self::Internal => 3,
81            Self::InvalidArgs => 4,
82            Self::__SourceBreaking { unknown_ordinal } => unknown_ordinal,
83        }
84    }
85
86    #[inline]
87    pub fn is_unknown(&self) -> bool {
88        match self {
89            Self::__SourceBreaking { unknown_ordinal: _ } => true,
90            _ => false,
91        }
92    }
93}
94
95/// A timestamp denoting an instant on the UTC timeline.
96#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
97#[repr(C)]
98pub struct InstantUtc {
99    /// `timestamp_utc` is the number of nanoseconds since the start of the Unix
100    /// epoch, relative to the UTC timezone.
101    ///
102    /// Fuchsia FIDL library `zx` does not have a core type that denotes this
103    /// (in contrast to say `zx.Time`), so we use a custom type to try and make
104    /// it harder to provide a timestamp set on the wrong timeline.
105    ///
106    /// ## Usage note
107    ///
108    /// Timestamps that reference the UTC timeline are unusual. This is because
109    /// the UTC timeline is actively adjusted to match the external notion of
110    /// accurate UTC time, and can change the rate, or can even "jump" both
111    /// forwards or backwards. Adjusting the notion of the UTC time manually
112    /// can pull in or push out deadlines tied to this timeline.
113    ///
114    /// This is why it is always recommended to use the UTC timeline only to
115    /// denote instants on the UTC timeline, and not use it to measure
116    /// durations.
117    pub timestamp_utc: i64,
118}
119
120impl fidl::Persistable for InstantUtc {}
121
122#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
123pub struct WakeAlarmsCancelRequest {
124    /// The unique identifier of the alarm to cancel.
125    ///
126    /// The alarm identified by `alarm_id` is canceled, and will no
127    /// longer be expected to fire. The respective `SetAndWait` will
128    /// return `WakeAlarmsError.DROPPED`.
129    ///
130    /// A race condition is possible where the alarm fires while
131    /// the `Cancel` call is being processed, or even slightly later.
132    /// The caller must handle such an event gracefully.
133    pub alarm_id: String,
134}
135
136impl fidl::Persistable for WakeAlarmsCancelRequest {}
137
138pub mod notifier_ordinals {
139    pub const NOTIFY: u64 = 0x23d11b31ba0d67d4;
140    pub const NOTIFY_ERROR: u64 = 0x62e915191b0113e9;
141}
142
143pub mod wake_alarms_ordinals {
144    pub const SET_AND_WAIT: u64 = 0x57ebd075ce4beba;
145    pub const CANCEL: u64 = 0x7b23a9760115e55c;
146    pub const SET: u64 = 0x1f110857e48fd72c;
147    pub const SET_AND_WAIT_UTC: u64 = 0x4ea69d33af584219;
148}
149
150mod internal {
151    use super::*;
152    unsafe impl fidl::encoding::TypeMarker for WakeAlarmsError {
153        type Owned = Self;
154
155        #[inline(always)]
156        fn inline_align(_context: fidl::encoding::Context) -> usize {
157            std::mem::align_of::<u32>()
158        }
159
160        #[inline(always)]
161        fn inline_size(_context: fidl::encoding::Context) -> usize {
162            std::mem::size_of::<u32>()
163        }
164
165        #[inline(always)]
166        fn encode_is_copy() -> bool {
167            false
168        }
169
170        #[inline(always)]
171        fn decode_is_copy() -> bool {
172            false
173        }
174    }
175
176    impl fidl::encoding::ValueTypeMarker for WakeAlarmsError {
177        type Borrowed<'a> = Self;
178        #[inline(always)]
179        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
180            *value
181        }
182    }
183
184    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
185        for WakeAlarmsError
186    {
187        #[inline]
188        unsafe fn encode(
189            self,
190            encoder: &mut fidl::encoding::Encoder<'_, D>,
191            offset: usize,
192            _depth: fidl::encoding::Depth,
193        ) -> fidl::Result<()> {
194            encoder.debug_check_bounds::<Self>(offset);
195            encoder.write_num(self.into_primitive(), offset);
196            Ok(())
197        }
198    }
199
200    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for WakeAlarmsError {
201        #[inline(always)]
202        fn new_empty() -> Self {
203            Self::unknown()
204        }
205
206        #[inline]
207        unsafe fn decode(
208            &mut self,
209            decoder: &mut fidl::encoding::Decoder<'_, D>,
210            offset: usize,
211            _depth: fidl::encoding::Depth,
212        ) -> fidl::Result<()> {
213            decoder.debug_check_bounds::<Self>(offset);
214            let prim = decoder.read_num::<u32>(offset);
215
216            *self = Self::from_primitive_allow_unknown(prim);
217            Ok(())
218        }
219    }
220
221    impl fidl::encoding::ValueTypeMarker for InstantUtc {
222        type Borrowed<'a> = &'a Self;
223        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
224            value
225        }
226    }
227
228    unsafe impl fidl::encoding::TypeMarker for InstantUtc {
229        type Owned = Self;
230
231        #[inline(always)]
232        fn inline_align(_context: fidl::encoding::Context) -> usize {
233            8
234        }
235
236        #[inline(always)]
237        fn inline_size(_context: fidl::encoding::Context) -> usize {
238            8
239        }
240        #[inline(always)]
241        fn encode_is_copy() -> bool {
242            true
243        }
244
245        #[inline(always)]
246        fn decode_is_copy() -> bool {
247            true
248        }
249    }
250
251    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<InstantUtc, D>
252        for &InstantUtc
253    {
254        #[inline]
255        unsafe fn encode(
256            self,
257            encoder: &mut fidl::encoding::Encoder<'_, D>,
258            offset: usize,
259            _depth: fidl::encoding::Depth,
260        ) -> fidl::Result<()> {
261            encoder.debug_check_bounds::<InstantUtc>(offset);
262            unsafe {
263                // Copy the object into the buffer.
264                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
265                (buf_ptr as *mut InstantUtc).write_unaligned((self as *const InstantUtc).read());
266                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
267                // done second because the memcpy will write garbage to these bytes.
268            }
269            Ok(())
270        }
271    }
272    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<i64, D>>
273        fidl::encoding::Encode<InstantUtc, D> for (T0,)
274    {
275        #[inline]
276        unsafe fn encode(
277            self,
278            encoder: &mut fidl::encoding::Encoder<'_, D>,
279            offset: usize,
280            depth: fidl::encoding::Depth,
281        ) -> fidl::Result<()> {
282            encoder.debug_check_bounds::<InstantUtc>(offset);
283            // Zero out padding regions. There's no need to apply masks
284            // because the unmasked parts will be overwritten by fields.
285            // Write the fields.
286            self.0.encode(encoder, offset + 0, depth)?;
287            Ok(())
288        }
289    }
290
291    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for InstantUtc {
292        #[inline(always)]
293        fn new_empty() -> Self {
294            Self { timestamp_utc: fidl::new_empty!(i64, D) }
295        }
296
297        #[inline]
298        unsafe fn decode(
299            &mut self,
300            decoder: &mut fidl::encoding::Decoder<'_, D>,
301            offset: usize,
302            _depth: fidl::encoding::Depth,
303        ) -> fidl::Result<()> {
304            decoder.debug_check_bounds::<Self>(offset);
305            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
306            // Verify that padding bytes are zero.
307            // Copy from the buffer into the object.
308            unsafe {
309                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
310            }
311            Ok(())
312        }
313    }
314
315    impl fidl::encoding::ValueTypeMarker for WakeAlarmsCancelRequest {
316        type Borrowed<'a> = &'a Self;
317        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
318            value
319        }
320    }
321
322    unsafe impl fidl::encoding::TypeMarker for WakeAlarmsCancelRequest {
323        type Owned = Self;
324
325        #[inline(always)]
326        fn inline_align(_context: fidl::encoding::Context) -> usize {
327            8
328        }
329
330        #[inline(always)]
331        fn inline_size(_context: fidl::encoding::Context) -> usize {
332            16
333        }
334    }
335
336    unsafe impl<D: fidl::encoding::ResourceDialect>
337        fidl::encoding::Encode<WakeAlarmsCancelRequest, D> for &WakeAlarmsCancelRequest
338    {
339        #[inline]
340        unsafe fn encode(
341            self,
342            encoder: &mut fidl::encoding::Encoder<'_, D>,
343            offset: usize,
344            _depth: fidl::encoding::Depth,
345        ) -> fidl::Result<()> {
346            encoder.debug_check_bounds::<WakeAlarmsCancelRequest>(offset);
347            // Delegate to tuple encoding.
348            fidl::encoding::Encode::<WakeAlarmsCancelRequest, D>::encode(
349                (<fidl::encoding::BoundedString<128> as fidl::encoding::ValueTypeMarker>::borrow(
350                    &self.alarm_id,
351                ),),
352                encoder,
353                offset,
354                _depth,
355            )
356        }
357    }
358    unsafe impl<
359        D: fidl::encoding::ResourceDialect,
360        T0: fidl::encoding::Encode<fidl::encoding::BoundedString<128>, D>,
361    > fidl::encoding::Encode<WakeAlarmsCancelRequest, D> for (T0,)
362    {
363        #[inline]
364        unsafe fn encode(
365            self,
366            encoder: &mut fidl::encoding::Encoder<'_, D>,
367            offset: usize,
368            depth: fidl::encoding::Depth,
369        ) -> fidl::Result<()> {
370            encoder.debug_check_bounds::<WakeAlarmsCancelRequest>(offset);
371            // Zero out padding regions. There's no need to apply masks
372            // because the unmasked parts will be overwritten by fields.
373            // Write the fields.
374            self.0.encode(encoder, offset + 0, depth)?;
375            Ok(())
376        }
377    }
378
379    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
380        for WakeAlarmsCancelRequest
381    {
382        #[inline(always)]
383        fn new_empty() -> Self {
384            Self { alarm_id: fidl::new_empty!(fidl::encoding::BoundedString<128>, D) }
385        }
386
387        #[inline]
388        unsafe fn decode(
389            &mut self,
390            decoder: &mut fidl::encoding::Decoder<'_, D>,
391            offset: usize,
392            _depth: fidl::encoding::Depth,
393        ) -> fidl::Result<()> {
394            decoder.debug_check_bounds::<Self>(offset);
395            // Verify that padding bytes are zero.
396            fidl::decode!(
397                fidl::encoding::BoundedString<128>,
398                D,
399                &mut self.alarm_id,
400                decoder,
401                offset + 0,
402                _depth
403            )?;
404            Ok(())
405        }
406    }
407}