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