fidl_fuchsia_time/
fidl_fuchsia_time.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::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_time__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct MaintenanceGetWritableUtcClockResponse {
16    pub utc_clock: fidl::Clock,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for MaintenanceGetWritableUtcClockResponse
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct MaintenanceMarker;
26
27impl fidl::endpoints::ProtocolMarker for MaintenanceMarker {
28    type Proxy = MaintenanceProxy;
29    type RequestStream = MaintenanceRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = MaintenanceSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "fuchsia.time.Maintenance";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for MaintenanceMarker {}
36
37pub trait MaintenanceProxyInterface: Send + Sync {
38    type GetWritableUtcClockResponseFut: std::future::Future<Output = Result<fidl::Clock, fidl::Error>>
39        + Send;
40    fn r#get_writable_utc_clock(&self) -> Self::GetWritableUtcClockResponseFut;
41}
42#[derive(Debug)]
43#[cfg(target_os = "fuchsia")]
44pub struct MaintenanceSynchronousProxy {
45    client: fidl::client::sync::Client,
46}
47
48#[cfg(target_os = "fuchsia")]
49impl fidl::endpoints::SynchronousProxy for MaintenanceSynchronousProxy {
50    type Proxy = MaintenanceProxy;
51    type Protocol = MaintenanceMarker;
52
53    fn from_channel(inner: fidl::Channel) -> Self {
54        Self::new(inner)
55    }
56
57    fn into_channel(self) -> fidl::Channel {
58        self.client.into_channel()
59    }
60
61    fn as_channel(&self) -> &fidl::Channel {
62        self.client.as_channel()
63    }
64}
65
66#[cfg(target_os = "fuchsia")]
67impl MaintenanceSynchronousProxy {
68    pub fn new(channel: fidl::Channel) -> Self {
69        let protocol_name = <MaintenanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
70        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
71    }
72
73    pub fn into_channel(self) -> fidl::Channel {
74        self.client.into_channel()
75    }
76
77    /// Waits until an event arrives and returns it. It is safe for other
78    /// threads to make concurrent requests while waiting for an event.
79    pub fn wait_for_event(
80        &self,
81        deadline: zx::MonotonicInstant,
82    ) -> Result<MaintenanceEvent, fidl::Error> {
83        MaintenanceEvent::decode(self.client.wait_for_event(deadline)?)
84    }
85
86    /// Retrieve a UTC clock handle with write rights.
87    pub fn r#get_writable_utc_clock(
88        &self,
89        ___deadline: zx::MonotonicInstant,
90    ) -> Result<fidl::Clock, fidl::Error> {
91        let _response = self
92            .client
93            .send_query::<fidl::encoding::EmptyPayload, MaintenanceGetWritableUtcClockResponse>(
94                (),
95                0x7e4ff4ceb95bb136,
96                fidl::encoding::DynamicFlags::empty(),
97                ___deadline,
98            )?;
99        Ok(_response.utc_clock)
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<MaintenanceSynchronousProxy> for zx::NullableHandle {
105    fn from(value: MaintenanceSynchronousProxy) -> Self {
106        value.into_channel().into()
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl From<fidl::Channel> for MaintenanceSynchronousProxy {
112    fn from(value: fidl::Channel) -> Self {
113        Self::new(value)
114    }
115}
116
117#[cfg(target_os = "fuchsia")]
118impl fidl::endpoints::FromClient for MaintenanceSynchronousProxy {
119    type Protocol = MaintenanceMarker;
120
121    fn from_client(value: fidl::endpoints::ClientEnd<MaintenanceMarker>) -> Self {
122        Self::new(value.into_channel())
123    }
124}
125
126#[derive(Debug, Clone)]
127pub struct MaintenanceProxy {
128    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
129}
130
131impl fidl::endpoints::Proxy for MaintenanceProxy {
132    type Protocol = MaintenanceMarker;
133
134    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
135        Self::new(inner)
136    }
137
138    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
139        self.client.into_channel().map_err(|client| Self { client })
140    }
141
142    fn as_channel(&self) -> &::fidl::AsyncChannel {
143        self.client.as_channel()
144    }
145}
146
147impl MaintenanceProxy {
148    /// Create a new Proxy for fuchsia.time/Maintenance.
149    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
150        let protocol_name = <MaintenanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
151        Self { client: fidl::client::Client::new(channel, protocol_name) }
152    }
153
154    /// Get a Stream of events from the remote end of the protocol.
155    ///
156    /// # Panics
157    ///
158    /// Panics if the event stream was already taken.
159    pub fn take_event_stream(&self) -> MaintenanceEventStream {
160        MaintenanceEventStream { event_receiver: self.client.take_event_receiver() }
161    }
162
163    /// Retrieve a UTC clock handle with write rights.
164    pub fn r#get_writable_utc_clock(
165        &self,
166    ) -> fidl::client::QueryResponseFut<fidl::Clock, fidl::encoding::DefaultFuchsiaResourceDialect>
167    {
168        MaintenanceProxyInterface::r#get_writable_utc_clock(self)
169    }
170}
171
172impl MaintenanceProxyInterface for MaintenanceProxy {
173    type GetWritableUtcClockResponseFut =
174        fidl::client::QueryResponseFut<fidl::Clock, fidl::encoding::DefaultFuchsiaResourceDialect>;
175    fn r#get_writable_utc_clock(&self) -> Self::GetWritableUtcClockResponseFut {
176        fn _decode(
177            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
178        ) -> Result<fidl::Clock, fidl::Error> {
179            let _response = fidl::client::decode_transaction_body::<
180                MaintenanceGetWritableUtcClockResponse,
181                fidl::encoding::DefaultFuchsiaResourceDialect,
182                0x7e4ff4ceb95bb136,
183            >(_buf?)?;
184            Ok(_response.utc_clock)
185        }
186        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, fidl::Clock>(
187            (),
188            0x7e4ff4ceb95bb136,
189            fidl::encoding::DynamicFlags::empty(),
190            _decode,
191        )
192    }
193}
194
195pub struct MaintenanceEventStream {
196    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
197}
198
199impl std::marker::Unpin for MaintenanceEventStream {}
200
201impl futures::stream::FusedStream for MaintenanceEventStream {
202    fn is_terminated(&self) -> bool {
203        self.event_receiver.is_terminated()
204    }
205}
206
207impl futures::Stream for MaintenanceEventStream {
208    type Item = Result<MaintenanceEvent, fidl::Error>;
209
210    fn poll_next(
211        mut self: std::pin::Pin<&mut Self>,
212        cx: &mut std::task::Context<'_>,
213    ) -> std::task::Poll<Option<Self::Item>> {
214        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
215            &mut self.event_receiver,
216            cx
217        )?) {
218            Some(buf) => std::task::Poll::Ready(Some(MaintenanceEvent::decode(buf))),
219            None => std::task::Poll::Ready(None),
220        }
221    }
222}
223
224#[derive(Debug)]
225pub enum MaintenanceEvent {}
226
227impl MaintenanceEvent {
228    /// Decodes a message buffer as a [`MaintenanceEvent`].
229    fn decode(
230        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
231    ) -> Result<MaintenanceEvent, fidl::Error> {
232        let (bytes, _handles) = buf.split_mut();
233        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
234        debug_assert_eq!(tx_header.tx_id, 0);
235        match tx_header.ordinal {
236            _ => Err(fidl::Error::UnknownOrdinal {
237                ordinal: tx_header.ordinal,
238                protocol_name: <MaintenanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
239            }),
240        }
241    }
242}
243
244/// A Stream of incoming requests for fuchsia.time/Maintenance.
245pub struct MaintenanceRequestStream {
246    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
247    is_terminated: bool,
248}
249
250impl std::marker::Unpin for MaintenanceRequestStream {}
251
252impl futures::stream::FusedStream for MaintenanceRequestStream {
253    fn is_terminated(&self) -> bool {
254        self.is_terminated
255    }
256}
257
258impl fidl::endpoints::RequestStream for MaintenanceRequestStream {
259    type Protocol = MaintenanceMarker;
260    type ControlHandle = MaintenanceControlHandle;
261
262    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
263        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
264    }
265
266    fn control_handle(&self) -> Self::ControlHandle {
267        MaintenanceControlHandle { inner: self.inner.clone() }
268    }
269
270    fn into_inner(
271        self,
272    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
273    {
274        (self.inner, self.is_terminated)
275    }
276
277    fn from_inner(
278        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
279        is_terminated: bool,
280    ) -> Self {
281        Self { inner, is_terminated }
282    }
283}
284
285impl futures::Stream for MaintenanceRequestStream {
286    type Item = Result<MaintenanceRequest, fidl::Error>;
287
288    fn poll_next(
289        mut self: std::pin::Pin<&mut Self>,
290        cx: &mut std::task::Context<'_>,
291    ) -> std::task::Poll<Option<Self::Item>> {
292        let this = &mut *self;
293        if this.inner.check_shutdown(cx) {
294            this.is_terminated = true;
295            return std::task::Poll::Ready(None);
296        }
297        if this.is_terminated {
298            panic!("polled MaintenanceRequestStream after completion");
299        }
300        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
301            |bytes, handles| {
302                match this.inner.channel().read_etc(cx, bytes, handles) {
303                    std::task::Poll::Ready(Ok(())) => {}
304                    std::task::Poll::Pending => return std::task::Poll::Pending,
305                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
306                        this.is_terminated = true;
307                        return std::task::Poll::Ready(None);
308                    }
309                    std::task::Poll::Ready(Err(e)) => {
310                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
311                            e.into(),
312                        ))));
313                    }
314                }
315
316                // A message has been received from the channel
317                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
318
319                std::task::Poll::Ready(Some(match header.ordinal {
320                    0x7e4ff4ceb95bb136 => {
321                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
322                        let mut req = fidl::new_empty!(
323                            fidl::encoding::EmptyPayload,
324                            fidl::encoding::DefaultFuchsiaResourceDialect
325                        );
326                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
327                        let control_handle = MaintenanceControlHandle { inner: this.inner.clone() };
328                        Ok(MaintenanceRequest::GetWritableUtcClock {
329                            responder: MaintenanceGetWritableUtcClockResponder {
330                                control_handle: std::mem::ManuallyDrop::new(control_handle),
331                                tx_id: header.tx_id,
332                            },
333                        })
334                    }
335                    _ => Err(fidl::Error::UnknownOrdinal {
336                        ordinal: header.ordinal,
337                        protocol_name:
338                            <MaintenanceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
339                    }),
340                }))
341            },
342        )
343    }
344}
345
346/// Provides access to a UTC clock for the purposes of
347/// keeping it up-to-date with external time sources.
348///
349/// The client does not own the UTC clock, but is given
350/// a lease in order to keep the time synchronized.
351#[derive(Debug)]
352pub enum MaintenanceRequest {
353    /// Retrieve a UTC clock handle with write rights.
354    GetWritableUtcClock { responder: MaintenanceGetWritableUtcClockResponder },
355}
356
357impl MaintenanceRequest {
358    #[allow(irrefutable_let_patterns)]
359    pub fn into_get_writable_utc_clock(self) -> Option<(MaintenanceGetWritableUtcClockResponder)> {
360        if let MaintenanceRequest::GetWritableUtcClock { responder } = self {
361            Some((responder))
362        } else {
363            None
364        }
365    }
366
367    /// Name of the method defined in FIDL
368    pub fn method_name(&self) -> &'static str {
369        match *self {
370            MaintenanceRequest::GetWritableUtcClock { .. } => "get_writable_utc_clock",
371        }
372    }
373}
374
375#[derive(Debug, Clone)]
376pub struct MaintenanceControlHandle {
377    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
378}
379
380impl fidl::endpoints::ControlHandle for MaintenanceControlHandle {
381    fn shutdown(&self) {
382        self.inner.shutdown()
383    }
384
385    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
386        self.inner.shutdown_with_epitaph(status)
387    }
388
389    fn is_closed(&self) -> bool {
390        self.inner.channel().is_closed()
391    }
392    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
393        self.inner.channel().on_closed()
394    }
395
396    #[cfg(target_os = "fuchsia")]
397    fn signal_peer(
398        &self,
399        clear_mask: zx::Signals,
400        set_mask: zx::Signals,
401    ) -> Result<(), zx_status::Status> {
402        use fidl::Peered;
403        self.inner.channel().signal_peer(clear_mask, set_mask)
404    }
405}
406
407impl MaintenanceControlHandle {}
408
409#[must_use = "FIDL methods require a response to be sent"]
410#[derive(Debug)]
411pub struct MaintenanceGetWritableUtcClockResponder {
412    control_handle: std::mem::ManuallyDrop<MaintenanceControlHandle>,
413    tx_id: u32,
414}
415
416/// Set the the channel to be shutdown (see [`MaintenanceControlHandle::shutdown`])
417/// if the responder is dropped without sending a response, so that the client
418/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
419impl std::ops::Drop for MaintenanceGetWritableUtcClockResponder {
420    fn drop(&mut self) {
421        self.control_handle.shutdown();
422        // Safety: drops once, never accessed again
423        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
424    }
425}
426
427impl fidl::endpoints::Responder for MaintenanceGetWritableUtcClockResponder {
428    type ControlHandle = MaintenanceControlHandle;
429
430    fn control_handle(&self) -> &MaintenanceControlHandle {
431        &self.control_handle
432    }
433
434    fn drop_without_shutdown(mut self) {
435        // Safety: drops once, never accessed again due to mem::forget
436        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
437        // Prevent Drop from running (which would shut down the channel)
438        std::mem::forget(self);
439    }
440}
441
442impl MaintenanceGetWritableUtcClockResponder {
443    /// Sends a response to the FIDL transaction.
444    ///
445    /// Sets the channel to shutdown if an error occurs.
446    pub fn send(self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
447        let _result = self.send_raw(utc_clock);
448        if _result.is_err() {
449            self.control_handle.shutdown();
450        }
451        self.drop_without_shutdown();
452        _result
453    }
454
455    /// Similar to "send" but does not shutdown the channel if an error occurs.
456    pub fn send_no_shutdown_on_err(self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
457        let _result = self.send_raw(utc_clock);
458        self.drop_without_shutdown();
459        _result
460    }
461
462    fn send_raw(&self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
463        self.control_handle.inner.send::<MaintenanceGetWritableUtcClockResponse>(
464            (utc_clock,),
465            self.tx_id,
466            0x7e4ff4ceb95bb136,
467            fidl::encoding::DynamicFlags::empty(),
468        )
469    }
470}
471
472mod internal {
473    use super::*;
474
475    impl fidl::encoding::ResourceTypeMarker for MaintenanceGetWritableUtcClockResponse {
476        type Borrowed<'a> = &'a mut Self;
477        fn take_or_borrow<'a>(
478            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
479        ) -> Self::Borrowed<'a> {
480            value
481        }
482    }
483
484    unsafe impl fidl::encoding::TypeMarker for MaintenanceGetWritableUtcClockResponse {
485        type Owned = Self;
486
487        #[inline(always)]
488        fn inline_align(_context: fidl::encoding::Context) -> usize {
489            4
490        }
491
492        #[inline(always)]
493        fn inline_size(_context: fidl::encoding::Context) -> usize {
494            4
495        }
496    }
497
498    unsafe impl
499        fidl::encoding::Encode<
500            MaintenanceGetWritableUtcClockResponse,
501            fidl::encoding::DefaultFuchsiaResourceDialect,
502        > for &mut MaintenanceGetWritableUtcClockResponse
503    {
504        #[inline]
505        unsafe fn encode(
506            self,
507            encoder: &mut fidl::encoding::Encoder<
508                '_,
509                fidl::encoding::DefaultFuchsiaResourceDialect,
510            >,
511            offset: usize,
512            _depth: fidl::encoding::Depth,
513        ) -> fidl::Result<()> {
514            encoder.debug_check_bounds::<MaintenanceGetWritableUtcClockResponse>(offset);
515            // Delegate to tuple encoding.
516            fidl::encoding::Encode::<
517                MaintenanceGetWritableUtcClockResponse,
518                fidl::encoding::DefaultFuchsiaResourceDialect,
519            >::encode(
520                (<fidl::encoding::HandleType<
521                    fidl::Clock,
522                    { fidl::ObjectType::CLOCK.into_raw() },
523                    2147483648,
524                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
525                    &mut self.utc_clock
526                ),),
527                encoder,
528                offset,
529                _depth,
530            )
531        }
532    }
533    unsafe impl<
534        T0: fidl::encoding::Encode<
535                fidl::encoding::HandleType<
536                    fidl::Clock,
537                    { fidl::ObjectType::CLOCK.into_raw() },
538                    2147483648,
539                >,
540                fidl::encoding::DefaultFuchsiaResourceDialect,
541            >,
542    >
543        fidl::encoding::Encode<
544            MaintenanceGetWritableUtcClockResponse,
545            fidl::encoding::DefaultFuchsiaResourceDialect,
546        > for (T0,)
547    {
548        #[inline]
549        unsafe fn encode(
550            self,
551            encoder: &mut fidl::encoding::Encoder<
552                '_,
553                fidl::encoding::DefaultFuchsiaResourceDialect,
554            >,
555            offset: usize,
556            depth: fidl::encoding::Depth,
557        ) -> fidl::Result<()> {
558            encoder.debug_check_bounds::<MaintenanceGetWritableUtcClockResponse>(offset);
559            // Zero out padding regions. There's no need to apply masks
560            // because the unmasked parts will be overwritten by fields.
561            // Write the fields.
562            self.0.encode(encoder, offset + 0, depth)?;
563            Ok(())
564        }
565    }
566
567    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
568        for MaintenanceGetWritableUtcClockResponse
569    {
570        #[inline(always)]
571        fn new_empty() -> Self {
572            Self {
573                utc_clock: fidl::new_empty!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
574            }
575        }
576
577        #[inline]
578        unsafe fn decode(
579            &mut self,
580            decoder: &mut fidl::encoding::Decoder<
581                '_,
582                fidl::encoding::DefaultFuchsiaResourceDialect,
583            >,
584            offset: usize,
585            _depth: fidl::encoding::Depth,
586        ) -> fidl::Result<()> {
587            decoder.debug_check_bounds::<Self>(offset);
588            // Verify that padding bytes are zero.
589            fidl::decode!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.utc_clock, decoder, offset + 0, _depth)?;
590            Ok(())
591        }
592    }
593}