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