fidl_fuchsia_time_external/
fidl_fuchsia_time_external.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_external_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct AdjustMarker;
16
17impl fidl::endpoints::ProtocolMarker for AdjustMarker {
18    type Proxy = AdjustProxy;
19    type RequestStream = AdjustRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = AdjustSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.time.external.Adjust";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for AdjustMarker {}
26pub type AdjustReportBootToUtcMappingResult = Result<(), Error>;
27
28pub trait AdjustProxyInterface: Send + Sync {
29    type ReportBootToUtcMappingResponseFut: std::future::Future<Output = Result<AdjustReportBootToUtcMappingResult, fidl::Error>>
30        + Send;
31    fn r#report_boot_to_utc_mapping(
32        &self,
33        boot_reference: fidl::BootInstant,
34        utc_reference: i64,
35    ) -> Self::ReportBootToUtcMappingResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct AdjustSynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for AdjustSynchronousProxy {
45    type Proxy = AdjustProxy;
46    type Protocol = AdjustMarker;
47
48    fn from_channel(inner: fidl::Channel) -> Self {
49        Self::new(inner)
50    }
51
52    fn into_channel(self) -> fidl::Channel {
53        self.client.into_channel()
54    }
55
56    fn as_channel(&self) -> &fidl::Channel {
57        self.client.as_channel()
58    }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl AdjustSynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <AdjustMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66    }
67
68    pub fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    /// Waits until an event arrives and returns it. It is safe for other
73    /// threads to make concurrent requests while waiting for an event.
74    pub fn wait_for_event(
75        &self,
76        deadline: zx::MonotonicInstant,
77    ) -> Result<AdjustEvent, fidl::Error> {
78        AdjustEvent::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    /// Requests that the callee changes its UTC time estimate.
82    ///
83    /// Reports the caller's desired correspondence between the boot timeline,
84    /// and the UTC timeline.
85    ///
86    /// The caller is required to provide both reference points so that any
87    /// FIDL round-trip delays do not affect the callee's interpretation of
88    /// the caller's intentions.  For example, were the callee to use its own
89    /// `boot_reference` value instead of a caller-provided one, long wall time
90    /// delays between the caller's and the callee's sampling of `boot_reference`
91    /// would introduce a skew.  While this is unlikely to happen on a device to
92    /// a meaningful extent, we established that this is the correct way to
93    /// transmit such information.
94    ///
95    /// To wit, we have observed delays in test environments. This is likely
96    /// because test environments run on emulators in shared-resource
97    /// settings, where unusually long delays are relatively common.
98    pub fn r#report_boot_to_utc_mapping(
99        &self,
100        mut boot_reference: fidl::BootInstant,
101        mut utc_reference: i64,
102        ___deadline: zx::MonotonicInstant,
103    ) -> Result<AdjustReportBootToUtcMappingResult, fidl::Error> {
104        let _response = self.client.send_query::<
105            AdjustReportBootToUtcMappingRequest,
106            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
107        >(
108            (boot_reference, utc_reference,),
109            0x1186fc4a8c7f7fbe,
110            fidl::encoding::DynamicFlags::empty(),
111            ___deadline,
112        )?;
113        Ok(_response.map(|x| x))
114    }
115}
116
117#[derive(Debug, Clone)]
118pub struct AdjustProxy {
119    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
120}
121
122impl fidl::endpoints::Proxy for AdjustProxy {
123    type Protocol = AdjustMarker;
124
125    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
126        Self::new(inner)
127    }
128
129    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
130        self.client.into_channel().map_err(|client| Self { client })
131    }
132
133    fn as_channel(&self) -> &::fidl::AsyncChannel {
134        self.client.as_channel()
135    }
136}
137
138impl AdjustProxy {
139    /// Create a new Proxy for fuchsia.time.external/Adjust.
140    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
141        let protocol_name = <AdjustMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
142        Self { client: fidl::client::Client::new(channel, protocol_name) }
143    }
144
145    /// Get a Stream of events from the remote end of the protocol.
146    ///
147    /// # Panics
148    ///
149    /// Panics if the event stream was already taken.
150    pub fn take_event_stream(&self) -> AdjustEventStream {
151        AdjustEventStream { event_receiver: self.client.take_event_receiver() }
152    }
153
154    /// Requests that the callee changes its UTC time estimate.
155    ///
156    /// Reports the caller's desired correspondence between the boot timeline,
157    /// and the UTC timeline.
158    ///
159    /// The caller is required to provide both reference points so that any
160    /// FIDL round-trip delays do not affect the callee's interpretation of
161    /// the caller's intentions.  For example, were the callee to use its own
162    /// `boot_reference` value instead of a caller-provided one, long wall time
163    /// delays between the caller's and the callee's sampling of `boot_reference`
164    /// would introduce a skew.  While this is unlikely to happen on a device to
165    /// a meaningful extent, we established that this is the correct way to
166    /// transmit such information.
167    ///
168    /// To wit, we have observed delays in test environments. This is likely
169    /// because test environments run on emulators in shared-resource
170    /// settings, where unusually long delays are relatively common.
171    pub fn r#report_boot_to_utc_mapping(
172        &self,
173        mut boot_reference: fidl::BootInstant,
174        mut utc_reference: i64,
175    ) -> fidl::client::QueryResponseFut<
176        AdjustReportBootToUtcMappingResult,
177        fidl::encoding::DefaultFuchsiaResourceDialect,
178    > {
179        AdjustProxyInterface::r#report_boot_to_utc_mapping(self, boot_reference, utc_reference)
180    }
181}
182
183impl AdjustProxyInterface for AdjustProxy {
184    type ReportBootToUtcMappingResponseFut = fidl::client::QueryResponseFut<
185        AdjustReportBootToUtcMappingResult,
186        fidl::encoding::DefaultFuchsiaResourceDialect,
187    >;
188    fn r#report_boot_to_utc_mapping(
189        &self,
190        mut boot_reference: fidl::BootInstant,
191        mut utc_reference: i64,
192    ) -> Self::ReportBootToUtcMappingResponseFut {
193        fn _decode(
194            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
195        ) -> Result<AdjustReportBootToUtcMappingResult, fidl::Error> {
196            let _response = fidl::client::decode_transaction_body::<
197                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
198                fidl::encoding::DefaultFuchsiaResourceDialect,
199                0x1186fc4a8c7f7fbe,
200            >(_buf?)?;
201            Ok(_response.map(|x| x))
202        }
203        self.client.send_query_and_decode::<
204            AdjustReportBootToUtcMappingRequest,
205            AdjustReportBootToUtcMappingResult,
206        >(
207            (boot_reference, utc_reference,),
208            0x1186fc4a8c7f7fbe,
209            fidl::encoding::DynamicFlags::empty(),
210            _decode,
211        )
212    }
213}
214
215pub struct AdjustEventStream {
216    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
217}
218
219impl std::marker::Unpin for AdjustEventStream {}
220
221impl futures::stream::FusedStream for AdjustEventStream {
222    fn is_terminated(&self) -> bool {
223        self.event_receiver.is_terminated()
224    }
225}
226
227impl futures::Stream for AdjustEventStream {
228    type Item = Result<AdjustEvent, fidl::Error>;
229
230    fn poll_next(
231        mut self: std::pin::Pin<&mut Self>,
232        cx: &mut std::task::Context<'_>,
233    ) -> std::task::Poll<Option<Self::Item>> {
234        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
235            &mut self.event_receiver,
236            cx
237        )?) {
238            Some(buf) => std::task::Poll::Ready(Some(AdjustEvent::decode(buf))),
239            None => std::task::Poll::Ready(None),
240        }
241    }
242}
243
244#[derive(Debug)]
245pub enum AdjustEvent {}
246
247impl AdjustEvent {
248    /// Decodes a message buffer as a [`AdjustEvent`].
249    fn decode(
250        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
251    ) -> Result<AdjustEvent, fidl::Error> {
252        let (bytes, _handles) = buf.split_mut();
253        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
254        debug_assert_eq!(tx_header.tx_id, 0);
255        match tx_header.ordinal {
256            _ => Err(fidl::Error::UnknownOrdinal {
257                ordinal: tx_header.ordinal,
258                protocol_name: <AdjustMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
259            }),
260        }
261    }
262}
263
264/// A Stream of incoming requests for fuchsia.time.external/Adjust.
265pub struct AdjustRequestStream {
266    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
267    is_terminated: bool,
268}
269
270impl std::marker::Unpin for AdjustRequestStream {}
271
272impl futures::stream::FusedStream for AdjustRequestStream {
273    fn is_terminated(&self) -> bool {
274        self.is_terminated
275    }
276}
277
278impl fidl::endpoints::RequestStream for AdjustRequestStream {
279    type Protocol = AdjustMarker;
280    type ControlHandle = AdjustControlHandle;
281
282    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
283        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
284    }
285
286    fn control_handle(&self) -> Self::ControlHandle {
287        AdjustControlHandle { inner: self.inner.clone() }
288    }
289
290    fn into_inner(
291        self,
292    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
293    {
294        (self.inner, self.is_terminated)
295    }
296
297    fn from_inner(
298        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
299        is_terminated: bool,
300    ) -> Self {
301        Self { inner, is_terminated }
302    }
303}
304
305impl futures::Stream for AdjustRequestStream {
306    type Item = Result<AdjustRequest, fidl::Error>;
307
308    fn poll_next(
309        mut self: std::pin::Pin<&mut Self>,
310        cx: &mut std::task::Context<'_>,
311    ) -> std::task::Poll<Option<Self::Item>> {
312        let this = &mut *self;
313        if this.inner.check_shutdown(cx) {
314            this.is_terminated = true;
315            return std::task::Poll::Ready(None);
316        }
317        if this.is_terminated {
318            panic!("polled AdjustRequestStream after completion");
319        }
320        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
321            |bytes, handles| {
322                match this.inner.channel().read_etc(cx, bytes, handles) {
323                    std::task::Poll::Ready(Ok(())) => {}
324                    std::task::Poll::Pending => return std::task::Poll::Pending,
325                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
326                        this.is_terminated = true;
327                        return std::task::Poll::Ready(None);
328                    }
329                    std::task::Poll::Ready(Err(e)) => {
330                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
331                            e.into(),
332                        ))))
333                    }
334                }
335
336                // A message has been received from the channel
337                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
338
339                std::task::Poll::Ready(Some(match header.ordinal {
340                    0x1186fc4a8c7f7fbe => {
341                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
342                        let mut req = fidl::new_empty!(
343                            AdjustReportBootToUtcMappingRequest,
344                            fidl::encoding::DefaultFuchsiaResourceDialect
345                        );
346                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<AdjustReportBootToUtcMappingRequest>(&header, _body_bytes, handles, &mut req)?;
347                        let control_handle = AdjustControlHandle { inner: this.inner.clone() };
348                        Ok(AdjustRequest::ReportBootToUtcMapping {
349                            boot_reference: req.boot_reference,
350                            utc_reference: req.utc_reference,
351
352                            responder: AdjustReportBootToUtcMappingResponder {
353                                control_handle: std::mem::ManuallyDrop::new(control_handle),
354                                tx_id: header.tx_id,
355                            },
356                        })
357                    }
358                    _ => Err(fidl::Error::UnknownOrdinal {
359                        ordinal: header.ordinal,
360                        protocol_name:
361                            <AdjustMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
362                    }),
363                }))
364            },
365        )
366    }
367}
368
369/// Report UTC reference adjustment.
370///
371/// Allows components to request corrections to the reported UTC time.  Very few
372/// components should be expected to have access to this capability.
373#[derive(Debug)]
374pub enum AdjustRequest {
375    /// Requests that the callee changes its UTC time estimate.
376    ///
377    /// Reports the caller's desired correspondence between the boot timeline,
378    /// and the UTC timeline.
379    ///
380    /// The caller is required to provide both reference points so that any
381    /// FIDL round-trip delays do not affect the callee's interpretation of
382    /// the caller's intentions.  For example, were the callee to use its own
383    /// `boot_reference` value instead of a caller-provided one, long wall time
384    /// delays between the caller's and the callee's sampling of `boot_reference`
385    /// would introduce a skew.  While this is unlikely to happen on a device to
386    /// a meaningful extent, we established that this is the correct way to
387    /// transmit such information.
388    ///
389    /// To wit, we have observed delays in test environments. This is likely
390    /// because test environments run on emulators in shared-resource
391    /// settings, where unusually long delays are relatively common.
392    ReportBootToUtcMapping {
393        boot_reference: fidl::BootInstant,
394        utc_reference: i64,
395        responder: AdjustReportBootToUtcMappingResponder,
396    },
397}
398
399impl AdjustRequest {
400    #[allow(irrefutable_let_patterns)]
401    pub fn into_report_boot_to_utc_mapping(
402        self,
403    ) -> Option<(fidl::BootInstant, i64, AdjustReportBootToUtcMappingResponder)> {
404        if let AdjustRequest::ReportBootToUtcMapping { boot_reference, utc_reference, responder } =
405            self
406        {
407            Some((boot_reference, utc_reference, responder))
408        } else {
409            None
410        }
411    }
412
413    /// Name of the method defined in FIDL
414    pub fn method_name(&self) -> &'static str {
415        match *self {
416            AdjustRequest::ReportBootToUtcMapping { .. } => "report_boot_to_utc_mapping",
417        }
418    }
419}
420
421#[derive(Debug, Clone)]
422pub struct AdjustControlHandle {
423    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
424}
425
426impl fidl::endpoints::ControlHandle for AdjustControlHandle {
427    fn shutdown(&self) {
428        self.inner.shutdown()
429    }
430    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
431        self.inner.shutdown_with_epitaph(status)
432    }
433
434    fn is_closed(&self) -> bool {
435        self.inner.channel().is_closed()
436    }
437    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
438        self.inner.channel().on_closed()
439    }
440
441    #[cfg(target_os = "fuchsia")]
442    fn signal_peer(
443        &self,
444        clear_mask: zx::Signals,
445        set_mask: zx::Signals,
446    ) -> Result<(), zx_status::Status> {
447        use fidl::Peered;
448        self.inner.channel().signal_peer(clear_mask, set_mask)
449    }
450}
451
452impl AdjustControlHandle {}
453
454#[must_use = "FIDL methods require a response to be sent"]
455#[derive(Debug)]
456pub struct AdjustReportBootToUtcMappingResponder {
457    control_handle: std::mem::ManuallyDrop<AdjustControlHandle>,
458    tx_id: u32,
459}
460
461/// Set the the channel to be shutdown (see [`AdjustControlHandle::shutdown`])
462/// if the responder is dropped without sending a response, so that the client
463/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
464impl std::ops::Drop for AdjustReportBootToUtcMappingResponder {
465    fn drop(&mut self) {
466        self.control_handle.shutdown();
467        // Safety: drops once, never accessed again
468        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
469    }
470}
471
472impl fidl::endpoints::Responder for AdjustReportBootToUtcMappingResponder {
473    type ControlHandle = AdjustControlHandle;
474
475    fn control_handle(&self) -> &AdjustControlHandle {
476        &self.control_handle
477    }
478
479    fn drop_without_shutdown(mut self) {
480        // Safety: drops once, never accessed again due to mem::forget
481        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
482        // Prevent Drop from running (which would shut down the channel)
483        std::mem::forget(self);
484    }
485}
486
487impl AdjustReportBootToUtcMappingResponder {
488    /// Sends a response to the FIDL transaction.
489    ///
490    /// Sets the channel to shutdown if an error occurs.
491    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
492        let _result = self.send_raw(result);
493        if _result.is_err() {
494            self.control_handle.shutdown();
495        }
496        self.drop_without_shutdown();
497        _result
498    }
499
500    /// Similar to "send" but does not shutdown the channel if an error occurs.
501    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
502        let _result = self.send_raw(result);
503        self.drop_without_shutdown();
504        _result
505    }
506
507    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
508        self.control_handle
509            .inner
510            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
511                result,
512                self.tx_id,
513                0x1186fc4a8c7f7fbe,
514                fidl::encoding::DynamicFlags::empty(),
515            )
516    }
517}
518
519#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
520pub struct PullSourceMarker;
521
522impl fidl::endpoints::ProtocolMarker for PullSourceMarker {
523    type Proxy = PullSourceProxy;
524    type RequestStream = PullSourceRequestStream;
525    #[cfg(target_os = "fuchsia")]
526    type SynchronousProxy = PullSourceSynchronousProxy;
527
528    const DEBUG_NAME: &'static str = "fuchsia.time.external.PullSource";
529}
530impl fidl::endpoints::DiscoverableProtocolMarker for PullSourceMarker {}
531pub type PullSourceSampleResult = Result<TimeSample, Error>;
532
533pub trait PullSourceProxyInterface: Send + Sync {
534    fn r#update_device_properties(&self, properties: &Properties) -> Result<(), fidl::Error>;
535    type SampleResponseFut: std::future::Future<Output = Result<PullSourceSampleResult, fidl::Error>>
536        + Send;
537    fn r#sample(&self, urgency: Urgency) -> Self::SampleResponseFut;
538    type NextPossibleSampleTimeResponseFut: std::future::Future<Output = Result<i64, fidl::Error>>
539        + Send;
540    fn r#next_possible_sample_time(&self) -> Self::NextPossibleSampleTimeResponseFut;
541}
542#[derive(Debug)]
543#[cfg(target_os = "fuchsia")]
544pub struct PullSourceSynchronousProxy {
545    client: fidl::client::sync::Client,
546}
547
548#[cfg(target_os = "fuchsia")]
549impl fidl::endpoints::SynchronousProxy for PullSourceSynchronousProxy {
550    type Proxy = PullSourceProxy;
551    type Protocol = PullSourceMarker;
552
553    fn from_channel(inner: fidl::Channel) -> Self {
554        Self::new(inner)
555    }
556
557    fn into_channel(self) -> fidl::Channel {
558        self.client.into_channel()
559    }
560
561    fn as_channel(&self) -> &fidl::Channel {
562        self.client.as_channel()
563    }
564}
565
566#[cfg(target_os = "fuchsia")]
567impl PullSourceSynchronousProxy {
568    pub fn new(channel: fidl::Channel) -> Self {
569        let protocol_name = <PullSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
570        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
571    }
572
573    pub fn into_channel(self) -> fidl::Channel {
574        self.client.into_channel()
575    }
576
577    /// Waits until an event arrives and returns it. It is safe for other
578    /// threads to make concurrent requests while waiting for an event.
579    pub fn wait_for_event(
580        &self,
581        deadline: zx::MonotonicInstant,
582    ) -> Result<PullSourceEvent, fidl::Error> {
583        PullSourceEvent::decode(self.client.wait_for_event(deadline)?)
584    }
585
586    /// Notifies the time source of changes to global properties of the device
587    /// that it may use to increase accuracy of time measurements.
588    pub fn r#update_device_properties(
589        &self,
590        mut properties: &Properties,
591    ) -> Result<(), fidl::Error> {
592        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
593            (properties,),
594            0x63704f8bd0962f00,
595            fidl::encoding::DynamicFlags::empty(),
596        )
597    }
598
599    /// Produce a new time sample.
600    ///
601    /// The server may consider the supplied urgency and will potentially
602    /// produce a sample more quickly but with lower accuracy when a request
603    /// is marked urgent.
604    ///
605    /// The server will return an error for permanent errors but will block
606    /// on conditions that are not known to be permanent (e.g. network not
607    /// connected).
608    ///
609    /// The server will return a RATE_LIMITED error if the client should wait
610    /// before requesting another sample. In this case the client may call
611    /// `NextPossibleSampleTime` to determine when the time source will be
612    /// willing to produce another sample.
613    pub fn r#sample(
614        &self,
615        mut urgency: Urgency,
616        ___deadline: zx::MonotonicInstant,
617    ) -> Result<PullSourceSampleResult, fidl::Error> {
618        let _response = self.client.send_query::<
619            PullSourceSampleRequest,
620            fidl::encoding::ResultType<PullSourceSampleResponse, Error>,
621        >(
622            (urgency,),
623            0x2d29007d8c9cb45a,
624            fidl::encoding::DynamicFlags::empty(),
625            ___deadline,
626        )?;
627        Ok(_response.map(|x| x.sample))
628    }
629
630    /// Returns the monotonic time at which the PullSource is willing to produce
631    /// another sample. If the PullSource is not rate limited it will return a
632    /// time less than or equal to current monotonic time.
633    pub fn r#next_possible_sample_time(
634        &self,
635        ___deadline: zx::MonotonicInstant,
636    ) -> Result<i64, fidl::Error> {
637        let _response = self
638            .client
639            .send_query::<fidl::encoding::EmptyPayload, PullSourceNextPossibleSampleTimeResponse>(
640                (),
641                0x69ca2b1fd63e88a5,
642                fidl::encoding::DynamicFlags::empty(),
643                ___deadline,
644            )?;
645        Ok(_response.next_possible_time)
646    }
647}
648
649#[derive(Debug, Clone)]
650pub struct PullSourceProxy {
651    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
652}
653
654impl fidl::endpoints::Proxy for PullSourceProxy {
655    type Protocol = PullSourceMarker;
656
657    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
658        Self::new(inner)
659    }
660
661    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
662        self.client.into_channel().map_err(|client| Self { client })
663    }
664
665    fn as_channel(&self) -> &::fidl::AsyncChannel {
666        self.client.as_channel()
667    }
668}
669
670impl PullSourceProxy {
671    /// Create a new Proxy for fuchsia.time.external/PullSource.
672    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
673        let protocol_name = <PullSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
674        Self { client: fidl::client::Client::new(channel, protocol_name) }
675    }
676
677    /// Get a Stream of events from the remote end of the protocol.
678    ///
679    /// # Panics
680    ///
681    /// Panics if the event stream was already taken.
682    pub fn take_event_stream(&self) -> PullSourceEventStream {
683        PullSourceEventStream { event_receiver: self.client.take_event_receiver() }
684    }
685
686    /// Notifies the time source of changes to global properties of the device
687    /// that it may use to increase accuracy of time measurements.
688    pub fn r#update_device_properties(
689        &self,
690        mut properties: &Properties,
691    ) -> Result<(), fidl::Error> {
692        PullSourceProxyInterface::r#update_device_properties(self, properties)
693    }
694
695    /// Produce a new time sample.
696    ///
697    /// The server may consider the supplied urgency and will potentially
698    /// produce a sample more quickly but with lower accuracy when a request
699    /// is marked urgent.
700    ///
701    /// The server will return an error for permanent errors but will block
702    /// on conditions that are not known to be permanent (e.g. network not
703    /// connected).
704    ///
705    /// The server will return a RATE_LIMITED error if the client should wait
706    /// before requesting another sample. In this case the client may call
707    /// `NextPossibleSampleTime` to determine when the time source will be
708    /// willing to produce another sample.
709    pub fn r#sample(
710        &self,
711        mut urgency: Urgency,
712    ) -> fidl::client::QueryResponseFut<
713        PullSourceSampleResult,
714        fidl::encoding::DefaultFuchsiaResourceDialect,
715    > {
716        PullSourceProxyInterface::r#sample(self, urgency)
717    }
718
719    /// Returns the monotonic time at which the PullSource is willing to produce
720    /// another sample. If the PullSource is not rate limited it will return a
721    /// time less than or equal to current monotonic time.
722    pub fn r#next_possible_sample_time(
723        &self,
724    ) -> fidl::client::QueryResponseFut<i64, fidl::encoding::DefaultFuchsiaResourceDialect> {
725        PullSourceProxyInterface::r#next_possible_sample_time(self)
726    }
727}
728
729impl PullSourceProxyInterface for PullSourceProxy {
730    fn r#update_device_properties(&self, mut properties: &Properties) -> Result<(), fidl::Error> {
731        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
732            (properties,),
733            0x63704f8bd0962f00,
734            fidl::encoding::DynamicFlags::empty(),
735        )
736    }
737
738    type SampleResponseFut = fidl::client::QueryResponseFut<
739        PullSourceSampleResult,
740        fidl::encoding::DefaultFuchsiaResourceDialect,
741    >;
742    fn r#sample(&self, mut urgency: Urgency) -> Self::SampleResponseFut {
743        fn _decode(
744            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
745        ) -> Result<PullSourceSampleResult, fidl::Error> {
746            let _response = fidl::client::decode_transaction_body::<
747                fidl::encoding::ResultType<PullSourceSampleResponse, Error>,
748                fidl::encoding::DefaultFuchsiaResourceDialect,
749                0x2d29007d8c9cb45a,
750            >(_buf?)?;
751            Ok(_response.map(|x| x.sample))
752        }
753        self.client.send_query_and_decode::<PullSourceSampleRequest, PullSourceSampleResult>(
754            (urgency,),
755            0x2d29007d8c9cb45a,
756            fidl::encoding::DynamicFlags::empty(),
757            _decode,
758        )
759    }
760
761    type NextPossibleSampleTimeResponseFut =
762        fidl::client::QueryResponseFut<i64, fidl::encoding::DefaultFuchsiaResourceDialect>;
763    fn r#next_possible_sample_time(&self) -> Self::NextPossibleSampleTimeResponseFut {
764        fn _decode(
765            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
766        ) -> Result<i64, fidl::Error> {
767            let _response = fidl::client::decode_transaction_body::<
768                PullSourceNextPossibleSampleTimeResponse,
769                fidl::encoding::DefaultFuchsiaResourceDialect,
770                0x69ca2b1fd63e88a5,
771            >(_buf?)?;
772            Ok(_response.next_possible_time)
773        }
774        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, i64>(
775            (),
776            0x69ca2b1fd63e88a5,
777            fidl::encoding::DynamicFlags::empty(),
778            _decode,
779        )
780    }
781}
782
783pub struct PullSourceEventStream {
784    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
785}
786
787impl std::marker::Unpin for PullSourceEventStream {}
788
789impl futures::stream::FusedStream for PullSourceEventStream {
790    fn is_terminated(&self) -> bool {
791        self.event_receiver.is_terminated()
792    }
793}
794
795impl futures::Stream for PullSourceEventStream {
796    type Item = Result<PullSourceEvent, fidl::Error>;
797
798    fn poll_next(
799        mut self: std::pin::Pin<&mut Self>,
800        cx: &mut std::task::Context<'_>,
801    ) -> std::task::Poll<Option<Self::Item>> {
802        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
803            &mut self.event_receiver,
804            cx
805        )?) {
806            Some(buf) => std::task::Poll::Ready(Some(PullSourceEvent::decode(buf))),
807            None => std::task::Poll::Ready(None),
808        }
809    }
810}
811
812#[derive(Debug)]
813pub enum PullSourceEvent {}
814
815impl PullSourceEvent {
816    /// Decodes a message buffer as a [`PullSourceEvent`].
817    fn decode(
818        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
819    ) -> Result<PullSourceEvent, fidl::Error> {
820        let (bytes, _handles) = buf.split_mut();
821        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
822        debug_assert_eq!(tx_header.tx_id, 0);
823        match tx_header.ordinal {
824            _ => Err(fidl::Error::UnknownOrdinal {
825                ordinal: tx_header.ordinal,
826                protocol_name: <PullSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
827            }),
828        }
829    }
830}
831
832/// A Stream of incoming requests for fuchsia.time.external/PullSource.
833pub struct PullSourceRequestStream {
834    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
835    is_terminated: bool,
836}
837
838impl std::marker::Unpin for PullSourceRequestStream {}
839
840impl futures::stream::FusedStream for PullSourceRequestStream {
841    fn is_terminated(&self) -> bool {
842        self.is_terminated
843    }
844}
845
846impl fidl::endpoints::RequestStream for PullSourceRequestStream {
847    type Protocol = PullSourceMarker;
848    type ControlHandle = PullSourceControlHandle;
849
850    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
851        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
852    }
853
854    fn control_handle(&self) -> Self::ControlHandle {
855        PullSourceControlHandle { inner: self.inner.clone() }
856    }
857
858    fn into_inner(
859        self,
860    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
861    {
862        (self.inner, self.is_terminated)
863    }
864
865    fn from_inner(
866        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
867        is_terminated: bool,
868    ) -> Self {
869        Self { inner, is_terminated }
870    }
871}
872
873impl futures::Stream for PullSourceRequestStream {
874    type Item = Result<PullSourceRequest, fidl::Error>;
875
876    fn poll_next(
877        mut self: std::pin::Pin<&mut Self>,
878        cx: &mut std::task::Context<'_>,
879    ) -> std::task::Poll<Option<Self::Item>> {
880        let this = &mut *self;
881        if this.inner.check_shutdown(cx) {
882            this.is_terminated = true;
883            return std::task::Poll::Ready(None);
884        }
885        if this.is_terminated {
886            panic!("polled PullSourceRequestStream after completion");
887        }
888        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
889            |bytes, handles| {
890                match this.inner.channel().read_etc(cx, bytes, handles) {
891                    std::task::Poll::Ready(Ok(())) => {}
892                    std::task::Poll::Pending => return std::task::Poll::Pending,
893                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
894                        this.is_terminated = true;
895                        return std::task::Poll::Ready(None);
896                    }
897                    std::task::Poll::Ready(Err(e)) => {
898                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
899                            e.into(),
900                        ))))
901                    }
902                }
903
904                // A message has been received from the channel
905                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
906
907                std::task::Poll::Ready(Some(match header.ordinal {
908                    0x63704f8bd0962f00 => {
909                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
910                        let mut req = fidl::new_empty!(
911                            TimeSourceUpdateDevicePropertiesRequest,
912                            fidl::encoding::DefaultFuchsiaResourceDialect
913                        );
914                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TimeSourceUpdateDevicePropertiesRequest>(&header, _body_bytes, handles, &mut req)?;
915                        let control_handle = PullSourceControlHandle { inner: this.inner.clone() };
916                        Ok(PullSourceRequest::UpdateDeviceProperties {
917                            properties: req.properties,
918
919                            control_handle,
920                        })
921                    }
922                    0x2d29007d8c9cb45a => {
923                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
924                        let mut req = fidl::new_empty!(
925                            PullSourceSampleRequest,
926                            fidl::encoding::DefaultFuchsiaResourceDialect
927                        );
928                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PullSourceSampleRequest>(&header, _body_bytes, handles, &mut req)?;
929                        let control_handle = PullSourceControlHandle { inner: this.inner.clone() };
930                        Ok(PullSourceRequest::Sample {
931                            urgency: req.urgency,
932
933                            responder: PullSourceSampleResponder {
934                                control_handle: std::mem::ManuallyDrop::new(control_handle),
935                                tx_id: header.tx_id,
936                            },
937                        })
938                    }
939                    0x69ca2b1fd63e88a5 => {
940                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
941                        let mut req = fidl::new_empty!(
942                            fidl::encoding::EmptyPayload,
943                            fidl::encoding::DefaultFuchsiaResourceDialect
944                        );
945                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
946                        let control_handle = PullSourceControlHandle { inner: this.inner.clone() };
947                        Ok(PullSourceRequest::NextPossibleSampleTime {
948                            responder: PullSourceNextPossibleSampleTimeResponder {
949                                control_handle: std::mem::ManuallyDrop::new(control_handle),
950                                tx_id: header.tx_id,
951                            },
952                        })
953                    }
954                    _ => Err(fidl::Error::UnknownOrdinal {
955                        ordinal: header.ordinal,
956                        protocol_name:
957                            <PullSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
958                    }),
959                }))
960            },
961        )
962    }
963}
964
965/// A protocol for time sources that produce time samples on demand.
966#[derive(Debug)]
967pub enum PullSourceRequest {
968    /// Notifies the time source of changes to global properties of the device
969    /// that it may use to increase accuracy of time measurements.
970    UpdateDeviceProperties { properties: Properties, control_handle: PullSourceControlHandle },
971    /// Produce a new time sample.
972    ///
973    /// The server may consider the supplied urgency and will potentially
974    /// produce a sample more quickly but with lower accuracy when a request
975    /// is marked urgent.
976    ///
977    /// The server will return an error for permanent errors but will block
978    /// on conditions that are not known to be permanent (e.g. network not
979    /// connected).
980    ///
981    /// The server will return a RATE_LIMITED error if the client should wait
982    /// before requesting another sample. In this case the client may call
983    /// `NextPossibleSampleTime` to determine when the time source will be
984    /// willing to produce another sample.
985    Sample { urgency: Urgency, responder: PullSourceSampleResponder },
986    /// Returns the monotonic time at which the PullSource is willing to produce
987    /// another sample. If the PullSource is not rate limited it will return a
988    /// time less than or equal to current monotonic time.
989    NextPossibleSampleTime { responder: PullSourceNextPossibleSampleTimeResponder },
990}
991
992impl PullSourceRequest {
993    #[allow(irrefutable_let_patterns)]
994    pub fn into_update_device_properties(self) -> Option<(Properties, PullSourceControlHandle)> {
995        if let PullSourceRequest::UpdateDeviceProperties { properties, control_handle } = self {
996            Some((properties, control_handle))
997        } else {
998            None
999        }
1000    }
1001
1002    #[allow(irrefutable_let_patterns)]
1003    pub fn into_sample(self) -> Option<(Urgency, PullSourceSampleResponder)> {
1004        if let PullSourceRequest::Sample { urgency, responder } = self {
1005            Some((urgency, responder))
1006        } else {
1007            None
1008        }
1009    }
1010
1011    #[allow(irrefutable_let_patterns)]
1012    pub fn into_next_possible_sample_time(
1013        self,
1014    ) -> Option<(PullSourceNextPossibleSampleTimeResponder)> {
1015        if let PullSourceRequest::NextPossibleSampleTime { responder } = self {
1016            Some((responder))
1017        } else {
1018            None
1019        }
1020    }
1021
1022    /// Name of the method defined in FIDL
1023    pub fn method_name(&self) -> &'static str {
1024        match *self {
1025            PullSourceRequest::UpdateDeviceProperties { .. } => "update_device_properties",
1026            PullSourceRequest::Sample { .. } => "sample",
1027            PullSourceRequest::NextPossibleSampleTime { .. } => "next_possible_sample_time",
1028        }
1029    }
1030}
1031
1032#[derive(Debug, Clone)]
1033pub struct PullSourceControlHandle {
1034    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1035}
1036
1037impl fidl::endpoints::ControlHandle for PullSourceControlHandle {
1038    fn shutdown(&self) {
1039        self.inner.shutdown()
1040    }
1041    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1042        self.inner.shutdown_with_epitaph(status)
1043    }
1044
1045    fn is_closed(&self) -> bool {
1046        self.inner.channel().is_closed()
1047    }
1048    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1049        self.inner.channel().on_closed()
1050    }
1051
1052    #[cfg(target_os = "fuchsia")]
1053    fn signal_peer(
1054        &self,
1055        clear_mask: zx::Signals,
1056        set_mask: zx::Signals,
1057    ) -> Result<(), zx_status::Status> {
1058        use fidl::Peered;
1059        self.inner.channel().signal_peer(clear_mask, set_mask)
1060    }
1061}
1062
1063impl PullSourceControlHandle {}
1064
1065#[must_use = "FIDL methods require a response to be sent"]
1066#[derive(Debug)]
1067pub struct PullSourceSampleResponder {
1068    control_handle: std::mem::ManuallyDrop<PullSourceControlHandle>,
1069    tx_id: u32,
1070}
1071
1072/// Set the the channel to be shutdown (see [`PullSourceControlHandle::shutdown`])
1073/// if the responder is dropped without sending a response, so that the client
1074/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1075impl std::ops::Drop for PullSourceSampleResponder {
1076    fn drop(&mut self) {
1077        self.control_handle.shutdown();
1078        // Safety: drops once, never accessed again
1079        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1080    }
1081}
1082
1083impl fidl::endpoints::Responder for PullSourceSampleResponder {
1084    type ControlHandle = PullSourceControlHandle;
1085
1086    fn control_handle(&self) -> &PullSourceControlHandle {
1087        &self.control_handle
1088    }
1089
1090    fn drop_without_shutdown(mut self) {
1091        // Safety: drops once, never accessed again due to mem::forget
1092        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1093        // Prevent Drop from running (which would shut down the channel)
1094        std::mem::forget(self);
1095    }
1096}
1097
1098impl PullSourceSampleResponder {
1099    /// Sends a response to the FIDL transaction.
1100    ///
1101    /// Sets the channel to shutdown if an error occurs.
1102    pub fn send(self, mut result: Result<&TimeSample, Error>) -> Result<(), fidl::Error> {
1103        let _result = self.send_raw(result);
1104        if _result.is_err() {
1105            self.control_handle.shutdown();
1106        }
1107        self.drop_without_shutdown();
1108        _result
1109    }
1110
1111    /// Similar to "send" but does not shutdown the channel if an error occurs.
1112    pub fn send_no_shutdown_on_err(
1113        self,
1114        mut result: Result<&TimeSample, Error>,
1115    ) -> Result<(), fidl::Error> {
1116        let _result = self.send_raw(result);
1117        self.drop_without_shutdown();
1118        _result
1119    }
1120
1121    fn send_raw(&self, mut result: Result<&TimeSample, Error>) -> Result<(), fidl::Error> {
1122        self.control_handle
1123            .inner
1124            .send::<fidl::encoding::ResultType<PullSourceSampleResponse, Error>>(
1125                result.map(|sample| (sample,)),
1126                self.tx_id,
1127                0x2d29007d8c9cb45a,
1128                fidl::encoding::DynamicFlags::empty(),
1129            )
1130    }
1131}
1132
1133#[must_use = "FIDL methods require a response to be sent"]
1134#[derive(Debug)]
1135pub struct PullSourceNextPossibleSampleTimeResponder {
1136    control_handle: std::mem::ManuallyDrop<PullSourceControlHandle>,
1137    tx_id: u32,
1138}
1139
1140/// Set the the channel to be shutdown (see [`PullSourceControlHandle::shutdown`])
1141/// if the responder is dropped without sending a response, so that the client
1142/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1143impl std::ops::Drop for PullSourceNextPossibleSampleTimeResponder {
1144    fn drop(&mut self) {
1145        self.control_handle.shutdown();
1146        // Safety: drops once, never accessed again
1147        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1148    }
1149}
1150
1151impl fidl::endpoints::Responder for PullSourceNextPossibleSampleTimeResponder {
1152    type ControlHandle = PullSourceControlHandle;
1153
1154    fn control_handle(&self) -> &PullSourceControlHandle {
1155        &self.control_handle
1156    }
1157
1158    fn drop_without_shutdown(mut self) {
1159        // Safety: drops once, never accessed again due to mem::forget
1160        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1161        // Prevent Drop from running (which would shut down the channel)
1162        std::mem::forget(self);
1163    }
1164}
1165
1166impl PullSourceNextPossibleSampleTimeResponder {
1167    /// Sends a response to the FIDL transaction.
1168    ///
1169    /// Sets the channel to shutdown if an error occurs.
1170    pub fn send(self, mut next_possible_time: i64) -> Result<(), fidl::Error> {
1171        let _result = self.send_raw(next_possible_time);
1172        if _result.is_err() {
1173            self.control_handle.shutdown();
1174        }
1175        self.drop_without_shutdown();
1176        _result
1177    }
1178
1179    /// Similar to "send" but does not shutdown the channel if an error occurs.
1180    pub fn send_no_shutdown_on_err(self, mut next_possible_time: i64) -> Result<(), fidl::Error> {
1181        let _result = self.send_raw(next_possible_time);
1182        self.drop_without_shutdown();
1183        _result
1184    }
1185
1186    fn send_raw(&self, mut next_possible_time: i64) -> Result<(), fidl::Error> {
1187        self.control_handle.inner.send::<PullSourceNextPossibleSampleTimeResponse>(
1188            (next_possible_time,),
1189            self.tx_id,
1190            0x69ca2b1fd63e88a5,
1191            fidl::encoding::DynamicFlags::empty(),
1192        )
1193    }
1194}
1195
1196#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1197pub struct PushSourceMarker;
1198
1199impl fidl::endpoints::ProtocolMarker for PushSourceMarker {
1200    type Proxy = PushSourceProxy;
1201    type RequestStream = PushSourceRequestStream;
1202    #[cfg(target_os = "fuchsia")]
1203    type SynchronousProxy = PushSourceSynchronousProxy;
1204
1205    const DEBUG_NAME: &'static str = "fuchsia.time.external.PushSource";
1206}
1207impl fidl::endpoints::DiscoverableProtocolMarker for PushSourceMarker {}
1208
1209pub trait PushSourceProxyInterface: Send + Sync {
1210    fn r#update_device_properties(&self, properties: &Properties) -> Result<(), fidl::Error>;
1211    type WatchSampleResponseFut: std::future::Future<Output = Result<TimeSample, fidl::Error>>
1212        + Send;
1213    fn r#watch_sample(&self) -> Self::WatchSampleResponseFut;
1214    type WatchStatusResponseFut: std::future::Future<Output = Result<Status, fidl::Error>> + Send;
1215    fn r#watch_status(&self) -> Self::WatchStatusResponseFut;
1216}
1217#[derive(Debug)]
1218#[cfg(target_os = "fuchsia")]
1219pub struct PushSourceSynchronousProxy {
1220    client: fidl::client::sync::Client,
1221}
1222
1223#[cfg(target_os = "fuchsia")]
1224impl fidl::endpoints::SynchronousProxy for PushSourceSynchronousProxy {
1225    type Proxy = PushSourceProxy;
1226    type Protocol = PushSourceMarker;
1227
1228    fn from_channel(inner: fidl::Channel) -> Self {
1229        Self::new(inner)
1230    }
1231
1232    fn into_channel(self) -> fidl::Channel {
1233        self.client.into_channel()
1234    }
1235
1236    fn as_channel(&self) -> &fidl::Channel {
1237        self.client.as_channel()
1238    }
1239}
1240
1241#[cfg(target_os = "fuchsia")]
1242impl PushSourceSynchronousProxy {
1243    pub fn new(channel: fidl::Channel) -> Self {
1244        let protocol_name = <PushSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1245        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1246    }
1247
1248    pub fn into_channel(self) -> fidl::Channel {
1249        self.client.into_channel()
1250    }
1251
1252    /// Waits until an event arrives and returns it. It is safe for other
1253    /// threads to make concurrent requests while waiting for an event.
1254    pub fn wait_for_event(
1255        &self,
1256        deadline: zx::MonotonicInstant,
1257    ) -> Result<PushSourceEvent, fidl::Error> {
1258        PushSourceEvent::decode(self.client.wait_for_event(deadline)?)
1259    }
1260
1261    /// Notifies the time source of changes to global properties of the device
1262    /// that it may use to increase accuracy of time measurements.
1263    pub fn r#update_device_properties(
1264        &self,
1265        mut properties: &Properties,
1266    ) -> Result<(), fidl::Error> {
1267        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
1268            (properties,),
1269            0x63704f8bd0962f00,
1270            fidl::encoding::DynamicFlags::empty(),
1271        )
1272    }
1273
1274    /// Watch for new time samples from the time source. This method is a
1275    /// hanging get and returns the latest time sample if one is available and
1276    /// has not already been returned to the client. If no such sample is
1277    /// available, the method will hang until one is produced and return it
1278    /// then.
1279    ///
1280    /// Note that it is entirely at the discretion of the PushSource
1281    /// implementation when to produce a sample; a call to WatchSample does
1282    /// not necessarily trigger sample collection.
1283    ///
1284    /// In the case a client sends a second WatchSample request while another
1285    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1286    /// epitaph.
1287    pub fn r#watch_sample(
1288        &self,
1289        ___deadline: zx::MonotonicInstant,
1290    ) -> Result<TimeSample, fidl::Error> {
1291        let _response =
1292            self.client.send_query::<fidl::encoding::EmptyPayload, PushSourceWatchSampleResponse>(
1293                (),
1294                0x44d515a56e8304dc,
1295                fidl::encoding::DynamicFlags::empty(),
1296                ___deadline,
1297            )?;
1298        Ok(_response.sample)
1299    }
1300
1301    /// Watch for changes in the status of the time source.
1302    ///
1303    /// This method is a hanging get that returns when the status changes from
1304    /// the last status reported to the client.
1305    ///
1306    /// In the case a client sends a second WatchStatus request while another
1307    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1308    /// epitaph.
1309    pub fn r#watch_status(&self, ___deadline: zx::MonotonicInstant) -> Result<Status, fidl::Error> {
1310        let _response =
1311            self.client.send_query::<fidl::encoding::EmptyPayload, PushSourceWatchStatusResponse>(
1312                (),
1313                0x60621a545f488bb1,
1314                fidl::encoding::DynamicFlags::empty(),
1315                ___deadline,
1316            )?;
1317        Ok(_response.status)
1318    }
1319}
1320
1321#[derive(Debug, Clone)]
1322pub struct PushSourceProxy {
1323    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1324}
1325
1326impl fidl::endpoints::Proxy for PushSourceProxy {
1327    type Protocol = PushSourceMarker;
1328
1329    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1330        Self::new(inner)
1331    }
1332
1333    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1334        self.client.into_channel().map_err(|client| Self { client })
1335    }
1336
1337    fn as_channel(&self) -> &::fidl::AsyncChannel {
1338        self.client.as_channel()
1339    }
1340}
1341
1342impl PushSourceProxy {
1343    /// Create a new Proxy for fuchsia.time.external/PushSource.
1344    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1345        let protocol_name = <PushSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1346        Self { client: fidl::client::Client::new(channel, protocol_name) }
1347    }
1348
1349    /// Get a Stream of events from the remote end of the protocol.
1350    ///
1351    /// # Panics
1352    ///
1353    /// Panics if the event stream was already taken.
1354    pub fn take_event_stream(&self) -> PushSourceEventStream {
1355        PushSourceEventStream { event_receiver: self.client.take_event_receiver() }
1356    }
1357
1358    /// Notifies the time source of changes to global properties of the device
1359    /// that it may use to increase accuracy of time measurements.
1360    pub fn r#update_device_properties(
1361        &self,
1362        mut properties: &Properties,
1363    ) -> Result<(), fidl::Error> {
1364        PushSourceProxyInterface::r#update_device_properties(self, properties)
1365    }
1366
1367    /// Watch for new time samples from the time source. This method is a
1368    /// hanging get and returns the latest time sample if one is available and
1369    /// has not already been returned to the client. If no such sample is
1370    /// available, the method will hang until one is produced and return it
1371    /// then.
1372    ///
1373    /// Note that it is entirely at the discretion of the PushSource
1374    /// implementation when to produce a sample; a call to WatchSample does
1375    /// not necessarily trigger sample collection.
1376    ///
1377    /// In the case a client sends a second WatchSample request while another
1378    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1379    /// epitaph.
1380    pub fn r#watch_sample(
1381        &self,
1382    ) -> fidl::client::QueryResponseFut<TimeSample, fidl::encoding::DefaultFuchsiaResourceDialect>
1383    {
1384        PushSourceProxyInterface::r#watch_sample(self)
1385    }
1386
1387    /// Watch for changes in the status of the time source.
1388    ///
1389    /// This method is a hanging get that returns when the status changes from
1390    /// the last status reported to the client.
1391    ///
1392    /// In the case a client sends a second WatchStatus request while another
1393    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1394    /// epitaph.
1395    pub fn r#watch_status(
1396        &self,
1397    ) -> fidl::client::QueryResponseFut<Status, fidl::encoding::DefaultFuchsiaResourceDialect> {
1398        PushSourceProxyInterface::r#watch_status(self)
1399    }
1400}
1401
1402impl PushSourceProxyInterface for PushSourceProxy {
1403    fn r#update_device_properties(&self, mut properties: &Properties) -> Result<(), fidl::Error> {
1404        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
1405            (properties,),
1406            0x63704f8bd0962f00,
1407            fidl::encoding::DynamicFlags::empty(),
1408        )
1409    }
1410
1411    type WatchSampleResponseFut =
1412        fidl::client::QueryResponseFut<TimeSample, fidl::encoding::DefaultFuchsiaResourceDialect>;
1413    fn r#watch_sample(&self) -> Self::WatchSampleResponseFut {
1414        fn _decode(
1415            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1416        ) -> Result<TimeSample, fidl::Error> {
1417            let _response = fidl::client::decode_transaction_body::<
1418                PushSourceWatchSampleResponse,
1419                fidl::encoding::DefaultFuchsiaResourceDialect,
1420                0x44d515a56e8304dc,
1421            >(_buf?)?;
1422            Ok(_response.sample)
1423        }
1424        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, TimeSample>(
1425            (),
1426            0x44d515a56e8304dc,
1427            fidl::encoding::DynamicFlags::empty(),
1428            _decode,
1429        )
1430    }
1431
1432    type WatchStatusResponseFut =
1433        fidl::client::QueryResponseFut<Status, fidl::encoding::DefaultFuchsiaResourceDialect>;
1434    fn r#watch_status(&self) -> Self::WatchStatusResponseFut {
1435        fn _decode(
1436            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1437        ) -> Result<Status, fidl::Error> {
1438            let _response = fidl::client::decode_transaction_body::<
1439                PushSourceWatchStatusResponse,
1440                fidl::encoding::DefaultFuchsiaResourceDialect,
1441                0x60621a545f488bb1,
1442            >(_buf?)?;
1443            Ok(_response.status)
1444        }
1445        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Status>(
1446            (),
1447            0x60621a545f488bb1,
1448            fidl::encoding::DynamicFlags::empty(),
1449            _decode,
1450        )
1451    }
1452}
1453
1454pub struct PushSourceEventStream {
1455    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1456}
1457
1458impl std::marker::Unpin for PushSourceEventStream {}
1459
1460impl futures::stream::FusedStream for PushSourceEventStream {
1461    fn is_terminated(&self) -> bool {
1462        self.event_receiver.is_terminated()
1463    }
1464}
1465
1466impl futures::Stream for PushSourceEventStream {
1467    type Item = Result<PushSourceEvent, fidl::Error>;
1468
1469    fn poll_next(
1470        mut self: std::pin::Pin<&mut Self>,
1471        cx: &mut std::task::Context<'_>,
1472    ) -> std::task::Poll<Option<Self::Item>> {
1473        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1474            &mut self.event_receiver,
1475            cx
1476        )?) {
1477            Some(buf) => std::task::Poll::Ready(Some(PushSourceEvent::decode(buf))),
1478            None => std::task::Poll::Ready(None),
1479        }
1480    }
1481}
1482
1483#[derive(Debug)]
1484pub enum PushSourceEvent {}
1485
1486impl PushSourceEvent {
1487    /// Decodes a message buffer as a [`PushSourceEvent`].
1488    fn decode(
1489        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1490    ) -> Result<PushSourceEvent, fidl::Error> {
1491        let (bytes, _handles) = buf.split_mut();
1492        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1493        debug_assert_eq!(tx_header.tx_id, 0);
1494        match tx_header.ordinal {
1495            _ => Err(fidl::Error::UnknownOrdinal {
1496                ordinal: tx_header.ordinal,
1497                protocol_name: <PushSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1498            }),
1499        }
1500    }
1501}
1502
1503/// A Stream of incoming requests for fuchsia.time.external/PushSource.
1504pub struct PushSourceRequestStream {
1505    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1506    is_terminated: bool,
1507}
1508
1509impl std::marker::Unpin for PushSourceRequestStream {}
1510
1511impl futures::stream::FusedStream for PushSourceRequestStream {
1512    fn is_terminated(&self) -> bool {
1513        self.is_terminated
1514    }
1515}
1516
1517impl fidl::endpoints::RequestStream for PushSourceRequestStream {
1518    type Protocol = PushSourceMarker;
1519    type ControlHandle = PushSourceControlHandle;
1520
1521    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1522        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1523    }
1524
1525    fn control_handle(&self) -> Self::ControlHandle {
1526        PushSourceControlHandle { inner: self.inner.clone() }
1527    }
1528
1529    fn into_inner(
1530        self,
1531    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1532    {
1533        (self.inner, self.is_terminated)
1534    }
1535
1536    fn from_inner(
1537        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1538        is_terminated: bool,
1539    ) -> Self {
1540        Self { inner, is_terminated }
1541    }
1542}
1543
1544impl futures::Stream for PushSourceRequestStream {
1545    type Item = Result<PushSourceRequest, fidl::Error>;
1546
1547    fn poll_next(
1548        mut self: std::pin::Pin<&mut Self>,
1549        cx: &mut std::task::Context<'_>,
1550    ) -> std::task::Poll<Option<Self::Item>> {
1551        let this = &mut *self;
1552        if this.inner.check_shutdown(cx) {
1553            this.is_terminated = true;
1554            return std::task::Poll::Ready(None);
1555        }
1556        if this.is_terminated {
1557            panic!("polled PushSourceRequestStream after completion");
1558        }
1559        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1560            |bytes, handles| {
1561                match this.inner.channel().read_etc(cx, bytes, handles) {
1562                    std::task::Poll::Ready(Ok(())) => {}
1563                    std::task::Poll::Pending => return std::task::Poll::Pending,
1564                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1565                        this.is_terminated = true;
1566                        return std::task::Poll::Ready(None);
1567                    }
1568                    std::task::Poll::Ready(Err(e)) => {
1569                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1570                            e.into(),
1571                        ))))
1572                    }
1573                }
1574
1575                // A message has been received from the channel
1576                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1577
1578                std::task::Poll::Ready(Some(match header.ordinal {
1579                    0x63704f8bd0962f00 => {
1580                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
1581                        let mut req = fidl::new_empty!(
1582                            TimeSourceUpdateDevicePropertiesRequest,
1583                            fidl::encoding::DefaultFuchsiaResourceDialect
1584                        );
1585                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TimeSourceUpdateDevicePropertiesRequest>(&header, _body_bytes, handles, &mut req)?;
1586                        let control_handle = PushSourceControlHandle { inner: this.inner.clone() };
1587                        Ok(PushSourceRequest::UpdateDeviceProperties {
1588                            properties: req.properties,
1589
1590                            control_handle,
1591                        })
1592                    }
1593                    0x44d515a56e8304dc => {
1594                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1595                        let mut req = fidl::new_empty!(
1596                            fidl::encoding::EmptyPayload,
1597                            fidl::encoding::DefaultFuchsiaResourceDialect
1598                        );
1599                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1600                        let control_handle = PushSourceControlHandle { inner: this.inner.clone() };
1601                        Ok(PushSourceRequest::WatchSample {
1602                            responder: PushSourceWatchSampleResponder {
1603                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1604                                tx_id: header.tx_id,
1605                            },
1606                        })
1607                    }
1608                    0x60621a545f488bb1 => {
1609                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1610                        let mut req = fidl::new_empty!(
1611                            fidl::encoding::EmptyPayload,
1612                            fidl::encoding::DefaultFuchsiaResourceDialect
1613                        );
1614                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1615                        let control_handle = PushSourceControlHandle { inner: this.inner.clone() };
1616                        Ok(PushSourceRequest::WatchStatus {
1617                            responder: PushSourceWatchStatusResponder {
1618                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1619                                tx_id: header.tx_id,
1620                            },
1621                        })
1622                    }
1623                    _ => Err(fidl::Error::UnknownOrdinal {
1624                        ordinal: header.ordinal,
1625                        protocol_name:
1626                            <PushSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1627                    }),
1628                }))
1629            },
1630        )
1631    }
1632}
1633
1634/// A protocol for time sources that produce time samples on a schedule that it
1635/// dictates. A PushSource does not report errors to clients as it is
1636/// responsible for handling them internally. Instead, a PushSource reports a
1637/// general health indication through the `WatchHealth` method to reflect
1638/// whether or not it expects to successfully produce time samples.
1639#[derive(Debug)]
1640pub enum PushSourceRequest {
1641    /// Notifies the time source of changes to global properties of the device
1642    /// that it may use to increase accuracy of time measurements.
1643    UpdateDeviceProperties { properties: Properties, control_handle: PushSourceControlHandle },
1644    /// Watch for new time samples from the time source. This method is a
1645    /// hanging get and returns the latest time sample if one is available and
1646    /// has not already been returned to the client. If no such sample is
1647    /// available, the method will hang until one is produced and return it
1648    /// then.
1649    ///
1650    /// Note that it is entirely at the discretion of the PushSource
1651    /// implementation when to produce a sample; a call to WatchSample does
1652    /// not necessarily trigger sample collection.
1653    ///
1654    /// In the case a client sends a second WatchSample request while another
1655    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1656    /// epitaph.
1657    WatchSample { responder: PushSourceWatchSampleResponder },
1658    /// Watch for changes in the status of the time source.
1659    ///
1660    /// This method is a hanging get that returns when the status changes from
1661    /// the last status reported to the client.
1662    ///
1663    /// In the case a client sends a second WatchStatus request while another
1664    /// request is active, the channel is closed with a ZX_ERR_BAD_STATE
1665    /// epitaph.
1666    WatchStatus { responder: PushSourceWatchStatusResponder },
1667}
1668
1669impl PushSourceRequest {
1670    #[allow(irrefutable_let_patterns)]
1671    pub fn into_update_device_properties(self) -> Option<(Properties, PushSourceControlHandle)> {
1672        if let PushSourceRequest::UpdateDeviceProperties { properties, control_handle } = self {
1673            Some((properties, control_handle))
1674        } else {
1675            None
1676        }
1677    }
1678
1679    #[allow(irrefutable_let_patterns)]
1680    pub fn into_watch_sample(self) -> Option<(PushSourceWatchSampleResponder)> {
1681        if let PushSourceRequest::WatchSample { responder } = self {
1682            Some((responder))
1683        } else {
1684            None
1685        }
1686    }
1687
1688    #[allow(irrefutable_let_patterns)]
1689    pub fn into_watch_status(self) -> Option<(PushSourceWatchStatusResponder)> {
1690        if let PushSourceRequest::WatchStatus { responder } = self {
1691            Some((responder))
1692        } else {
1693            None
1694        }
1695    }
1696
1697    /// Name of the method defined in FIDL
1698    pub fn method_name(&self) -> &'static str {
1699        match *self {
1700            PushSourceRequest::UpdateDeviceProperties { .. } => "update_device_properties",
1701            PushSourceRequest::WatchSample { .. } => "watch_sample",
1702            PushSourceRequest::WatchStatus { .. } => "watch_status",
1703        }
1704    }
1705}
1706
1707#[derive(Debug, Clone)]
1708pub struct PushSourceControlHandle {
1709    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1710}
1711
1712impl fidl::endpoints::ControlHandle for PushSourceControlHandle {
1713    fn shutdown(&self) {
1714        self.inner.shutdown()
1715    }
1716    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1717        self.inner.shutdown_with_epitaph(status)
1718    }
1719
1720    fn is_closed(&self) -> bool {
1721        self.inner.channel().is_closed()
1722    }
1723    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1724        self.inner.channel().on_closed()
1725    }
1726
1727    #[cfg(target_os = "fuchsia")]
1728    fn signal_peer(
1729        &self,
1730        clear_mask: zx::Signals,
1731        set_mask: zx::Signals,
1732    ) -> Result<(), zx_status::Status> {
1733        use fidl::Peered;
1734        self.inner.channel().signal_peer(clear_mask, set_mask)
1735    }
1736}
1737
1738impl PushSourceControlHandle {}
1739
1740#[must_use = "FIDL methods require a response to be sent"]
1741#[derive(Debug)]
1742pub struct PushSourceWatchSampleResponder {
1743    control_handle: std::mem::ManuallyDrop<PushSourceControlHandle>,
1744    tx_id: u32,
1745}
1746
1747/// Set the the channel to be shutdown (see [`PushSourceControlHandle::shutdown`])
1748/// if the responder is dropped without sending a response, so that the client
1749/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1750impl std::ops::Drop for PushSourceWatchSampleResponder {
1751    fn drop(&mut self) {
1752        self.control_handle.shutdown();
1753        // Safety: drops once, never accessed again
1754        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1755    }
1756}
1757
1758impl fidl::endpoints::Responder for PushSourceWatchSampleResponder {
1759    type ControlHandle = PushSourceControlHandle;
1760
1761    fn control_handle(&self) -> &PushSourceControlHandle {
1762        &self.control_handle
1763    }
1764
1765    fn drop_without_shutdown(mut self) {
1766        // Safety: drops once, never accessed again due to mem::forget
1767        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1768        // Prevent Drop from running (which would shut down the channel)
1769        std::mem::forget(self);
1770    }
1771}
1772
1773impl PushSourceWatchSampleResponder {
1774    /// Sends a response to the FIDL transaction.
1775    ///
1776    /// Sets the channel to shutdown if an error occurs.
1777    pub fn send(self, mut sample: &TimeSample) -> Result<(), fidl::Error> {
1778        let _result = self.send_raw(sample);
1779        if _result.is_err() {
1780            self.control_handle.shutdown();
1781        }
1782        self.drop_without_shutdown();
1783        _result
1784    }
1785
1786    /// Similar to "send" but does not shutdown the channel if an error occurs.
1787    pub fn send_no_shutdown_on_err(self, mut sample: &TimeSample) -> Result<(), fidl::Error> {
1788        let _result = self.send_raw(sample);
1789        self.drop_without_shutdown();
1790        _result
1791    }
1792
1793    fn send_raw(&self, mut sample: &TimeSample) -> Result<(), fidl::Error> {
1794        self.control_handle.inner.send::<PushSourceWatchSampleResponse>(
1795            (sample,),
1796            self.tx_id,
1797            0x44d515a56e8304dc,
1798            fidl::encoding::DynamicFlags::empty(),
1799        )
1800    }
1801}
1802
1803#[must_use = "FIDL methods require a response to be sent"]
1804#[derive(Debug)]
1805pub struct PushSourceWatchStatusResponder {
1806    control_handle: std::mem::ManuallyDrop<PushSourceControlHandle>,
1807    tx_id: u32,
1808}
1809
1810/// Set the the channel to be shutdown (see [`PushSourceControlHandle::shutdown`])
1811/// if the responder is dropped without sending a response, so that the client
1812/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1813impl std::ops::Drop for PushSourceWatchStatusResponder {
1814    fn drop(&mut self) {
1815        self.control_handle.shutdown();
1816        // Safety: drops once, never accessed again
1817        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1818    }
1819}
1820
1821impl fidl::endpoints::Responder for PushSourceWatchStatusResponder {
1822    type ControlHandle = PushSourceControlHandle;
1823
1824    fn control_handle(&self) -> &PushSourceControlHandle {
1825        &self.control_handle
1826    }
1827
1828    fn drop_without_shutdown(mut self) {
1829        // Safety: drops once, never accessed again due to mem::forget
1830        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1831        // Prevent Drop from running (which would shut down the channel)
1832        std::mem::forget(self);
1833    }
1834}
1835
1836impl PushSourceWatchStatusResponder {
1837    /// Sends a response to the FIDL transaction.
1838    ///
1839    /// Sets the channel to shutdown if an error occurs.
1840    pub fn send(self, mut status: Status) -> Result<(), fidl::Error> {
1841        let _result = self.send_raw(status);
1842        if _result.is_err() {
1843            self.control_handle.shutdown();
1844        }
1845        self.drop_without_shutdown();
1846        _result
1847    }
1848
1849    /// Similar to "send" but does not shutdown the channel if an error occurs.
1850    pub fn send_no_shutdown_on_err(self, mut status: Status) -> Result<(), fidl::Error> {
1851        let _result = self.send_raw(status);
1852        self.drop_without_shutdown();
1853        _result
1854    }
1855
1856    fn send_raw(&self, mut status: Status) -> Result<(), fidl::Error> {
1857        self.control_handle.inner.send::<PushSourceWatchStatusResponse>(
1858            (status,),
1859            self.tx_id,
1860            0x60621a545f488bb1,
1861            fidl::encoding::DynamicFlags::empty(),
1862        )
1863    }
1864}
1865
1866#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1867pub struct TimeSourceMarker;
1868
1869impl fidl::endpoints::ProtocolMarker for TimeSourceMarker {
1870    type Proxy = TimeSourceProxy;
1871    type RequestStream = TimeSourceRequestStream;
1872    #[cfg(target_os = "fuchsia")]
1873    type SynchronousProxy = TimeSourceSynchronousProxy;
1874
1875    const DEBUG_NAME: &'static str = "(anonymous) TimeSource";
1876}
1877
1878pub trait TimeSourceProxyInterface: Send + Sync {
1879    fn r#update_device_properties(&self, properties: &Properties) -> Result<(), fidl::Error>;
1880}
1881#[derive(Debug)]
1882#[cfg(target_os = "fuchsia")]
1883pub struct TimeSourceSynchronousProxy {
1884    client: fidl::client::sync::Client,
1885}
1886
1887#[cfg(target_os = "fuchsia")]
1888impl fidl::endpoints::SynchronousProxy for TimeSourceSynchronousProxy {
1889    type Proxy = TimeSourceProxy;
1890    type Protocol = TimeSourceMarker;
1891
1892    fn from_channel(inner: fidl::Channel) -> Self {
1893        Self::new(inner)
1894    }
1895
1896    fn into_channel(self) -> fidl::Channel {
1897        self.client.into_channel()
1898    }
1899
1900    fn as_channel(&self) -> &fidl::Channel {
1901        self.client.as_channel()
1902    }
1903}
1904
1905#[cfg(target_os = "fuchsia")]
1906impl TimeSourceSynchronousProxy {
1907    pub fn new(channel: fidl::Channel) -> Self {
1908        let protocol_name = <TimeSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1909        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1910    }
1911
1912    pub fn into_channel(self) -> fidl::Channel {
1913        self.client.into_channel()
1914    }
1915
1916    /// Waits until an event arrives and returns it. It is safe for other
1917    /// threads to make concurrent requests while waiting for an event.
1918    pub fn wait_for_event(
1919        &self,
1920        deadline: zx::MonotonicInstant,
1921    ) -> Result<TimeSourceEvent, fidl::Error> {
1922        TimeSourceEvent::decode(self.client.wait_for_event(deadline)?)
1923    }
1924
1925    /// Notifies the time source of changes to global properties of the device
1926    /// that it may use to increase accuracy of time measurements.
1927    pub fn r#update_device_properties(
1928        &self,
1929        mut properties: &Properties,
1930    ) -> Result<(), fidl::Error> {
1931        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
1932            (properties,),
1933            0x63704f8bd0962f00,
1934            fidl::encoding::DynamicFlags::empty(),
1935        )
1936    }
1937}
1938
1939#[derive(Debug, Clone)]
1940pub struct TimeSourceProxy {
1941    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1942}
1943
1944impl fidl::endpoints::Proxy for TimeSourceProxy {
1945    type Protocol = TimeSourceMarker;
1946
1947    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1948        Self::new(inner)
1949    }
1950
1951    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1952        self.client.into_channel().map_err(|client| Self { client })
1953    }
1954
1955    fn as_channel(&self) -> &::fidl::AsyncChannel {
1956        self.client.as_channel()
1957    }
1958}
1959
1960impl TimeSourceProxy {
1961    /// Create a new Proxy for fuchsia.time.external/TimeSource.
1962    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1963        let protocol_name = <TimeSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1964        Self { client: fidl::client::Client::new(channel, protocol_name) }
1965    }
1966
1967    /// Get a Stream of events from the remote end of the protocol.
1968    ///
1969    /// # Panics
1970    ///
1971    /// Panics if the event stream was already taken.
1972    pub fn take_event_stream(&self) -> TimeSourceEventStream {
1973        TimeSourceEventStream { event_receiver: self.client.take_event_receiver() }
1974    }
1975
1976    /// Notifies the time source of changes to global properties of the device
1977    /// that it may use to increase accuracy of time measurements.
1978    pub fn r#update_device_properties(
1979        &self,
1980        mut properties: &Properties,
1981    ) -> Result<(), fidl::Error> {
1982        TimeSourceProxyInterface::r#update_device_properties(self, properties)
1983    }
1984}
1985
1986impl TimeSourceProxyInterface for TimeSourceProxy {
1987    fn r#update_device_properties(&self, mut properties: &Properties) -> Result<(), fidl::Error> {
1988        self.client.send::<TimeSourceUpdateDevicePropertiesRequest>(
1989            (properties,),
1990            0x63704f8bd0962f00,
1991            fidl::encoding::DynamicFlags::empty(),
1992        )
1993    }
1994}
1995
1996pub struct TimeSourceEventStream {
1997    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1998}
1999
2000impl std::marker::Unpin for TimeSourceEventStream {}
2001
2002impl futures::stream::FusedStream for TimeSourceEventStream {
2003    fn is_terminated(&self) -> bool {
2004        self.event_receiver.is_terminated()
2005    }
2006}
2007
2008impl futures::Stream for TimeSourceEventStream {
2009    type Item = Result<TimeSourceEvent, fidl::Error>;
2010
2011    fn poll_next(
2012        mut self: std::pin::Pin<&mut Self>,
2013        cx: &mut std::task::Context<'_>,
2014    ) -> std::task::Poll<Option<Self::Item>> {
2015        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
2016            &mut self.event_receiver,
2017            cx
2018        )?) {
2019            Some(buf) => std::task::Poll::Ready(Some(TimeSourceEvent::decode(buf))),
2020            None => std::task::Poll::Ready(None),
2021        }
2022    }
2023}
2024
2025#[derive(Debug)]
2026pub enum TimeSourceEvent {}
2027
2028impl TimeSourceEvent {
2029    /// Decodes a message buffer as a [`TimeSourceEvent`].
2030    fn decode(
2031        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
2032    ) -> Result<TimeSourceEvent, fidl::Error> {
2033        let (bytes, _handles) = buf.split_mut();
2034        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
2035        debug_assert_eq!(tx_header.tx_id, 0);
2036        match tx_header.ordinal {
2037            _ => Err(fidl::Error::UnknownOrdinal {
2038                ordinal: tx_header.ordinal,
2039                protocol_name: <TimeSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
2040            }),
2041        }
2042    }
2043}
2044
2045/// A Stream of incoming requests for fuchsia.time.external/TimeSource.
2046pub struct TimeSourceRequestStream {
2047    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2048    is_terminated: bool,
2049}
2050
2051impl std::marker::Unpin for TimeSourceRequestStream {}
2052
2053impl futures::stream::FusedStream for TimeSourceRequestStream {
2054    fn is_terminated(&self) -> bool {
2055        self.is_terminated
2056    }
2057}
2058
2059impl fidl::endpoints::RequestStream for TimeSourceRequestStream {
2060    type Protocol = TimeSourceMarker;
2061    type ControlHandle = TimeSourceControlHandle;
2062
2063    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
2064        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
2065    }
2066
2067    fn control_handle(&self) -> Self::ControlHandle {
2068        TimeSourceControlHandle { inner: self.inner.clone() }
2069    }
2070
2071    fn into_inner(
2072        self,
2073    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
2074    {
2075        (self.inner, self.is_terminated)
2076    }
2077
2078    fn from_inner(
2079        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2080        is_terminated: bool,
2081    ) -> Self {
2082        Self { inner, is_terminated }
2083    }
2084}
2085
2086impl futures::Stream for TimeSourceRequestStream {
2087    type Item = Result<TimeSourceRequest, fidl::Error>;
2088
2089    fn poll_next(
2090        mut self: std::pin::Pin<&mut Self>,
2091        cx: &mut std::task::Context<'_>,
2092    ) -> std::task::Poll<Option<Self::Item>> {
2093        let this = &mut *self;
2094        if this.inner.check_shutdown(cx) {
2095            this.is_terminated = true;
2096            return std::task::Poll::Ready(None);
2097        }
2098        if this.is_terminated {
2099            panic!("polled TimeSourceRequestStream after completion");
2100        }
2101        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
2102            |bytes, handles| {
2103                match this.inner.channel().read_etc(cx, bytes, handles) {
2104                    std::task::Poll::Ready(Ok(())) => {}
2105                    std::task::Poll::Pending => return std::task::Poll::Pending,
2106                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
2107                        this.is_terminated = true;
2108                        return std::task::Poll::Ready(None);
2109                    }
2110                    std::task::Poll::Ready(Err(e)) => {
2111                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
2112                            e.into(),
2113                        ))))
2114                    }
2115                }
2116
2117                // A message has been received from the channel
2118                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
2119
2120                std::task::Poll::Ready(Some(match header.ordinal {
2121                    0x63704f8bd0962f00 => {
2122                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
2123                        let mut req = fidl::new_empty!(
2124                            TimeSourceUpdateDevicePropertiesRequest,
2125                            fidl::encoding::DefaultFuchsiaResourceDialect
2126                        );
2127                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<TimeSourceUpdateDevicePropertiesRequest>(&header, _body_bytes, handles, &mut req)?;
2128                        let control_handle = TimeSourceControlHandle { inner: this.inner.clone() };
2129                        Ok(TimeSourceRequest::UpdateDeviceProperties {
2130                            properties: req.properties,
2131
2132                            control_handle,
2133                        })
2134                    }
2135                    _ => Err(fidl::Error::UnknownOrdinal {
2136                        ordinal: header.ordinal,
2137                        protocol_name:
2138                            <TimeSourceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
2139                    }),
2140                }))
2141            },
2142        )
2143    }
2144}
2145
2146/// A protocol which defines common methods for all time sources. Should not be
2147/// implemented directly.
2148#[derive(Debug)]
2149pub enum TimeSourceRequest {
2150    /// Notifies the time source of changes to global properties of the device
2151    /// that it may use to increase accuracy of time measurements.
2152    UpdateDeviceProperties { properties: Properties, control_handle: TimeSourceControlHandle },
2153}
2154
2155impl TimeSourceRequest {
2156    #[allow(irrefutable_let_patterns)]
2157    pub fn into_update_device_properties(self) -> Option<(Properties, TimeSourceControlHandle)> {
2158        if let TimeSourceRequest::UpdateDeviceProperties { properties, control_handle } = self {
2159            Some((properties, control_handle))
2160        } else {
2161            None
2162        }
2163    }
2164
2165    /// Name of the method defined in FIDL
2166    pub fn method_name(&self) -> &'static str {
2167        match *self {
2168            TimeSourceRequest::UpdateDeviceProperties { .. } => "update_device_properties",
2169        }
2170    }
2171}
2172
2173#[derive(Debug, Clone)]
2174pub struct TimeSourceControlHandle {
2175    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
2176}
2177
2178impl fidl::endpoints::ControlHandle for TimeSourceControlHandle {
2179    fn shutdown(&self) {
2180        self.inner.shutdown()
2181    }
2182    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
2183        self.inner.shutdown_with_epitaph(status)
2184    }
2185
2186    fn is_closed(&self) -> bool {
2187        self.inner.channel().is_closed()
2188    }
2189    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
2190        self.inner.channel().on_closed()
2191    }
2192
2193    #[cfg(target_os = "fuchsia")]
2194    fn signal_peer(
2195        &self,
2196        clear_mask: zx::Signals,
2197        set_mask: zx::Signals,
2198    ) -> Result<(), zx_status::Status> {
2199        use fidl::Peered;
2200        self.inner.channel().signal_peer(clear_mask, set_mask)
2201    }
2202}
2203
2204impl TimeSourceControlHandle {}
2205
2206mod internal {
2207    use super::*;
2208}