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::Handle {
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    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
385        self.inner.shutdown_with_epitaph(status)
386    }
387
388    fn is_closed(&self) -> bool {
389        self.inner.channel().is_closed()
390    }
391    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
392        self.inner.channel().on_closed()
393    }
394
395    #[cfg(target_os = "fuchsia")]
396    fn signal_peer(
397        &self,
398        clear_mask: zx::Signals,
399        set_mask: zx::Signals,
400    ) -> Result<(), zx_status::Status> {
401        use fidl::Peered;
402        self.inner.channel().signal_peer(clear_mask, set_mask)
403    }
404}
405
406impl MaintenanceControlHandle {}
407
408#[must_use = "FIDL methods require a response to be sent"]
409#[derive(Debug)]
410pub struct MaintenanceGetWritableUtcClockResponder {
411    control_handle: std::mem::ManuallyDrop<MaintenanceControlHandle>,
412    tx_id: u32,
413}
414
415/// Set the the channel to be shutdown (see [`MaintenanceControlHandle::shutdown`])
416/// if the responder is dropped without sending a response, so that the client
417/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
418impl std::ops::Drop for MaintenanceGetWritableUtcClockResponder {
419    fn drop(&mut self) {
420        self.control_handle.shutdown();
421        // Safety: drops once, never accessed again
422        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
423    }
424}
425
426impl fidl::endpoints::Responder for MaintenanceGetWritableUtcClockResponder {
427    type ControlHandle = MaintenanceControlHandle;
428
429    fn control_handle(&self) -> &MaintenanceControlHandle {
430        &self.control_handle
431    }
432
433    fn drop_without_shutdown(mut self) {
434        // Safety: drops once, never accessed again due to mem::forget
435        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
436        // Prevent Drop from running (which would shut down the channel)
437        std::mem::forget(self);
438    }
439}
440
441impl MaintenanceGetWritableUtcClockResponder {
442    /// Sends a response to the FIDL transaction.
443    ///
444    /// Sets the channel to shutdown if an error occurs.
445    pub fn send(self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
446        let _result = self.send_raw(utc_clock);
447        if _result.is_err() {
448            self.control_handle.shutdown();
449        }
450        self.drop_without_shutdown();
451        _result
452    }
453
454    /// Similar to "send" but does not shutdown the channel if an error occurs.
455    pub fn send_no_shutdown_on_err(self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
456        let _result = self.send_raw(utc_clock);
457        self.drop_without_shutdown();
458        _result
459    }
460
461    fn send_raw(&self, mut utc_clock: fidl::Clock) -> Result<(), fidl::Error> {
462        self.control_handle.inner.send::<MaintenanceGetWritableUtcClockResponse>(
463            (utc_clock,),
464            self.tx_id,
465            0x7e4ff4ceb95bb136,
466            fidl::encoding::DynamicFlags::empty(),
467        )
468    }
469}
470
471mod internal {
472    use super::*;
473
474    impl fidl::encoding::ResourceTypeMarker for MaintenanceGetWritableUtcClockResponse {
475        type Borrowed<'a> = &'a mut Self;
476        fn take_or_borrow<'a>(
477            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
478        ) -> Self::Borrowed<'a> {
479            value
480        }
481    }
482
483    unsafe impl fidl::encoding::TypeMarker for MaintenanceGetWritableUtcClockResponse {
484        type Owned = Self;
485
486        #[inline(always)]
487        fn inline_align(_context: fidl::encoding::Context) -> usize {
488            4
489        }
490
491        #[inline(always)]
492        fn inline_size(_context: fidl::encoding::Context) -> usize {
493            4
494        }
495    }
496
497    unsafe impl
498        fidl::encoding::Encode<
499            MaintenanceGetWritableUtcClockResponse,
500            fidl::encoding::DefaultFuchsiaResourceDialect,
501        > for &mut MaintenanceGetWritableUtcClockResponse
502    {
503        #[inline]
504        unsafe fn encode(
505            self,
506            encoder: &mut fidl::encoding::Encoder<
507                '_,
508                fidl::encoding::DefaultFuchsiaResourceDialect,
509            >,
510            offset: usize,
511            _depth: fidl::encoding::Depth,
512        ) -> fidl::Result<()> {
513            encoder.debug_check_bounds::<MaintenanceGetWritableUtcClockResponse>(offset);
514            // Delegate to tuple encoding.
515            fidl::encoding::Encode::<
516                MaintenanceGetWritableUtcClockResponse,
517                fidl::encoding::DefaultFuchsiaResourceDialect,
518            >::encode(
519                (<fidl::encoding::HandleType<
520                    fidl::Clock,
521                    { fidl::ObjectType::CLOCK.into_raw() },
522                    2147483648,
523                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
524                    &mut self.utc_clock
525                ),),
526                encoder,
527                offset,
528                _depth,
529            )
530        }
531    }
532    unsafe impl<
533            T0: fidl::encoding::Encode<
534                fidl::encoding::HandleType<
535                    fidl::Clock,
536                    { fidl::ObjectType::CLOCK.into_raw() },
537                    2147483648,
538                >,
539                fidl::encoding::DefaultFuchsiaResourceDialect,
540            >,
541        >
542        fidl::encoding::Encode<
543            MaintenanceGetWritableUtcClockResponse,
544            fidl::encoding::DefaultFuchsiaResourceDialect,
545        > for (T0,)
546    {
547        #[inline]
548        unsafe fn encode(
549            self,
550            encoder: &mut fidl::encoding::Encoder<
551                '_,
552                fidl::encoding::DefaultFuchsiaResourceDialect,
553            >,
554            offset: usize,
555            depth: fidl::encoding::Depth,
556        ) -> fidl::Result<()> {
557            encoder.debug_check_bounds::<MaintenanceGetWritableUtcClockResponse>(offset);
558            // Zero out padding regions. There's no need to apply masks
559            // because the unmasked parts will be overwritten by fields.
560            // Write the fields.
561            self.0.encode(encoder, offset + 0, depth)?;
562            Ok(())
563        }
564    }
565
566    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
567        for MaintenanceGetWritableUtcClockResponse
568    {
569        #[inline(always)]
570        fn new_empty() -> Self {
571            Self {
572                utc_clock: fidl::new_empty!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
573            }
574        }
575
576        #[inline]
577        unsafe fn decode(
578            &mut self,
579            decoder: &mut fidl::encoding::Decoder<
580                '_,
581                fidl::encoding::DefaultFuchsiaResourceDialect,
582            >,
583            offset: usize,
584            _depth: fidl::encoding::Depth,
585        ) -> fidl::Result<()> {
586            decoder.debug_check_bounds::<Self>(offset);
587            // Verify that padding bytes are zero.
588            fidl::decode!(fidl::encoding::HandleType<fidl::Clock, { fidl::ObjectType::CLOCK.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.utc_clock, decoder, offset + 0, _depth)?;
589            Ok(())
590        }
591    }
592}