fidl_fuchsia_hardware_rtc/
fidl_fuchsia_hardware_rtc.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_hardware_rtc__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18    type Proxy = DeviceProxy;
19    type RequestStream = DeviceRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = DeviceSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.hardware.rtc.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26pub type DeviceGetResult = Result<Time, i32>;
27pub type DeviceSet2Result = Result<(), i32>;
28
29pub trait DeviceProxyInterface: Send + Sync {
30    type GetResponseFut: std::future::Future<Output = Result<DeviceGetResult, fidl::Error>> + Send;
31    fn r#get(&self) -> Self::GetResponseFut;
32    type SetResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
33    fn r#set(&self, rtc: &Time) -> Self::SetResponseFut;
34    type Set2ResponseFut: std::future::Future<Output = Result<DeviceSet2Result, fidl::Error>> + Send;
35    fn r#set2(&self, rtc: &Time) -> Self::Set2ResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct DeviceSynchronousProxy {
40    client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
45    type Proxy = DeviceProxy;
46    type Protocol = DeviceMarker;
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 DeviceSynchronousProxy {
63    pub fn new(channel: fidl::Channel) -> Self {
64        let protocol_name = <DeviceMarker 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<DeviceEvent, fidl::Error> {
78        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
79    }
80
81    /// Get the current RTC time.
82    /// If the driver detects that it does not have a valid time to report, then it will return an
83    /// `ZX_ERR_INTERNAL` error.
84    pub fn r#get(&self, ___deadline: zx::MonotonicInstant) -> Result<DeviceGetResult, fidl::Error> {
85        let _response = self.client.send_query::<
86            fidl::encoding::EmptyPayload,
87            fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
88        >(
89            (),
90            0x27fdad10b3816ff4,
91            fidl::encoding::DynamicFlags::FLEXIBLE,
92            ___deadline,
93        )?
94        .into_result::<DeviceMarker>("get")?;
95        Ok(_response.map(|x| x.rtc))
96    }
97
98    /// Set the RTC time.
99    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
100    ///
101    /// Deprecated, see b/382085965. Do not add new uses of this method, implement Set2() below.
102    pub fn r#set(
103        &self,
104        mut rtc: &Time,
105        ___deadline: zx::MonotonicInstant,
106    ) -> Result<i32, fidl::Error> {
107        let _response = self
108            .client
109            .send_query::<DeviceSetRequest, fidl::encoding::FlexibleType<DeviceSetResponse>>(
110                (rtc,),
111                0x5ff1bca8b571d820,
112                fidl::encoding::DynamicFlags::FLEXIBLE,
113                ___deadline,
114            )?
115            .into_result::<DeviceMarker>("set")?;
116        Ok(_response.status)
117    }
118
119    /// Set the RTC time.
120    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
121    pub fn r#set2(
122        &self,
123        mut rtc: &Time,
124        ___deadline: zx::MonotonicInstant,
125    ) -> Result<DeviceSet2Result, fidl::Error> {
126        let _response = self.client.send_query::<
127            DeviceSet2Request,
128            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
129        >(
130            (rtc,),
131            0x16698df780253ae5,
132            fidl::encoding::DynamicFlags::FLEXIBLE,
133            ___deadline,
134        )?
135        .into_result::<DeviceMarker>("set2")?;
136        Ok(_response.map(|x| x))
137    }
138}
139
140#[cfg(target_os = "fuchsia")]
141impl From<DeviceSynchronousProxy> for zx::Handle {
142    fn from(value: DeviceSynchronousProxy) -> Self {
143        value.into_channel().into()
144    }
145}
146
147#[cfg(target_os = "fuchsia")]
148impl From<fidl::Channel> for DeviceSynchronousProxy {
149    fn from(value: fidl::Channel) -> Self {
150        Self::new(value)
151    }
152}
153
154#[cfg(target_os = "fuchsia")]
155impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
156    type Protocol = DeviceMarker;
157
158    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
159        Self::new(value.into_channel())
160    }
161}
162
163#[derive(Debug, Clone)]
164pub struct DeviceProxy {
165    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
166}
167
168impl fidl::endpoints::Proxy for DeviceProxy {
169    type Protocol = DeviceMarker;
170
171    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
172        Self::new(inner)
173    }
174
175    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
176        self.client.into_channel().map_err(|client| Self { client })
177    }
178
179    fn as_channel(&self) -> &::fidl::AsyncChannel {
180        self.client.as_channel()
181    }
182}
183
184impl DeviceProxy {
185    /// Create a new Proxy for fuchsia.hardware.rtc/Device.
186    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
187        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
188        Self { client: fidl::client::Client::new(channel, protocol_name) }
189    }
190
191    /// Get a Stream of events from the remote end of the protocol.
192    ///
193    /// # Panics
194    ///
195    /// Panics if the event stream was already taken.
196    pub fn take_event_stream(&self) -> DeviceEventStream {
197        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
198    }
199
200    /// Get the current RTC time.
201    /// If the driver detects that it does not have a valid time to report, then it will return an
202    /// `ZX_ERR_INTERNAL` error.
203    pub fn r#get(
204        &self,
205    ) -> fidl::client::QueryResponseFut<
206        DeviceGetResult,
207        fidl::encoding::DefaultFuchsiaResourceDialect,
208    > {
209        DeviceProxyInterface::r#get(self)
210    }
211
212    /// Set the RTC time.
213    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
214    ///
215    /// Deprecated, see b/382085965. Do not add new uses of this method, implement Set2() below.
216    pub fn r#set(
217        &self,
218        mut rtc: &Time,
219    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
220        DeviceProxyInterface::r#set(self, rtc)
221    }
222
223    /// Set the RTC time.
224    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
225    pub fn r#set2(
226        &self,
227        mut rtc: &Time,
228    ) -> fidl::client::QueryResponseFut<
229        DeviceSet2Result,
230        fidl::encoding::DefaultFuchsiaResourceDialect,
231    > {
232        DeviceProxyInterface::r#set2(self, rtc)
233    }
234}
235
236impl DeviceProxyInterface for DeviceProxy {
237    type GetResponseFut = fidl::client::QueryResponseFut<
238        DeviceGetResult,
239        fidl::encoding::DefaultFuchsiaResourceDialect,
240    >;
241    fn r#get(&self) -> Self::GetResponseFut {
242        fn _decode(
243            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
244        ) -> Result<DeviceGetResult, fidl::Error> {
245            let _response = fidl::client::decode_transaction_body::<
246                fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
247                fidl::encoding::DefaultFuchsiaResourceDialect,
248                0x27fdad10b3816ff4,
249            >(_buf?)?
250            .into_result::<DeviceMarker>("get")?;
251            Ok(_response.map(|x| x.rtc))
252        }
253        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetResult>(
254            (),
255            0x27fdad10b3816ff4,
256            fidl::encoding::DynamicFlags::FLEXIBLE,
257            _decode,
258        )
259    }
260
261    type SetResponseFut =
262        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
263    fn r#set(&self, mut rtc: &Time) -> Self::SetResponseFut {
264        fn _decode(
265            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
266        ) -> Result<i32, fidl::Error> {
267            let _response = fidl::client::decode_transaction_body::<
268                fidl::encoding::FlexibleType<DeviceSetResponse>,
269                fidl::encoding::DefaultFuchsiaResourceDialect,
270                0x5ff1bca8b571d820,
271            >(_buf?)?
272            .into_result::<DeviceMarker>("set")?;
273            Ok(_response.status)
274        }
275        self.client.send_query_and_decode::<DeviceSetRequest, i32>(
276            (rtc,),
277            0x5ff1bca8b571d820,
278            fidl::encoding::DynamicFlags::FLEXIBLE,
279            _decode,
280        )
281    }
282
283    type Set2ResponseFut = fidl::client::QueryResponseFut<
284        DeviceSet2Result,
285        fidl::encoding::DefaultFuchsiaResourceDialect,
286    >;
287    fn r#set2(&self, mut rtc: &Time) -> Self::Set2ResponseFut {
288        fn _decode(
289            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
290        ) -> Result<DeviceSet2Result, fidl::Error> {
291            let _response = fidl::client::decode_transaction_body::<
292                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
293                fidl::encoding::DefaultFuchsiaResourceDialect,
294                0x16698df780253ae5,
295            >(_buf?)?
296            .into_result::<DeviceMarker>("set2")?;
297            Ok(_response.map(|x| x))
298        }
299        self.client.send_query_and_decode::<DeviceSet2Request, DeviceSet2Result>(
300            (rtc,),
301            0x16698df780253ae5,
302            fidl::encoding::DynamicFlags::FLEXIBLE,
303            _decode,
304        )
305    }
306}
307
308pub struct DeviceEventStream {
309    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
310}
311
312impl std::marker::Unpin for DeviceEventStream {}
313
314impl futures::stream::FusedStream for DeviceEventStream {
315    fn is_terminated(&self) -> bool {
316        self.event_receiver.is_terminated()
317    }
318}
319
320impl futures::Stream for DeviceEventStream {
321    type Item = Result<DeviceEvent, fidl::Error>;
322
323    fn poll_next(
324        mut self: std::pin::Pin<&mut Self>,
325        cx: &mut std::task::Context<'_>,
326    ) -> std::task::Poll<Option<Self::Item>> {
327        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
328            &mut self.event_receiver,
329            cx
330        )?) {
331            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
332            None => std::task::Poll::Ready(None),
333        }
334    }
335}
336
337#[derive(Debug)]
338pub enum DeviceEvent {
339    #[non_exhaustive]
340    _UnknownEvent {
341        /// Ordinal of the event that was sent.
342        ordinal: u64,
343    },
344}
345
346impl DeviceEvent {
347    /// Decodes a message buffer as a [`DeviceEvent`].
348    fn decode(
349        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
350    ) -> Result<DeviceEvent, fidl::Error> {
351        let (bytes, _handles) = buf.split_mut();
352        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
353        debug_assert_eq!(tx_header.tx_id, 0);
354        match tx_header.ordinal {
355            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
356                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
357            }
358            _ => Err(fidl::Error::UnknownOrdinal {
359                ordinal: tx_header.ordinal,
360                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
361            }),
362        }
363    }
364}
365
366/// A Stream of incoming requests for fuchsia.hardware.rtc/Device.
367pub struct DeviceRequestStream {
368    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
369    is_terminated: bool,
370}
371
372impl std::marker::Unpin for DeviceRequestStream {}
373
374impl futures::stream::FusedStream for DeviceRequestStream {
375    fn is_terminated(&self) -> bool {
376        self.is_terminated
377    }
378}
379
380impl fidl::endpoints::RequestStream for DeviceRequestStream {
381    type Protocol = DeviceMarker;
382    type ControlHandle = DeviceControlHandle;
383
384    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
385        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
386    }
387
388    fn control_handle(&self) -> Self::ControlHandle {
389        DeviceControlHandle { inner: self.inner.clone() }
390    }
391
392    fn into_inner(
393        self,
394    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
395    {
396        (self.inner, self.is_terminated)
397    }
398
399    fn from_inner(
400        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
401        is_terminated: bool,
402    ) -> Self {
403        Self { inner, is_terminated }
404    }
405}
406
407impl futures::Stream for DeviceRequestStream {
408    type Item = Result<DeviceRequest, fidl::Error>;
409
410    fn poll_next(
411        mut self: std::pin::Pin<&mut Self>,
412        cx: &mut std::task::Context<'_>,
413    ) -> std::task::Poll<Option<Self::Item>> {
414        let this = &mut *self;
415        if this.inner.check_shutdown(cx) {
416            this.is_terminated = true;
417            return std::task::Poll::Ready(None);
418        }
419        if this.is_terminated {
420            panic!("polled DeviceRequestStream after completion");
421        }
422        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
423            |bytes, handles| {
424                match this.inner.channel().read_etc(cx, bytes, handles) {
425                    std::task::Poll::Ready(Ok(())) => {}
426                    std::task::Poll::Pending => return std::task::Poll::Pending,
427                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
428                        this.is_terminated = true;
429                        return std::task::Poll::Ready(None);
430                    }
431                    std::task::Poll::Ready(Err(e)) => {
432                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
433                            e.into(),
434                        ))))
435                    }
436                }
437
438                // A message has been received from the channel
439                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
440
441                std::task::Poll::Ready(Some(match header.ordinal {
442                    0x27fdad10b3816ff4 => {
443                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
444                        let mut req = fidl::new_empty!(
445                            fidl::encoding::EmptyPayload,
446                            fidl::encoding::DefaultFuchsiaResourceDialect
447                        );
448                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
449                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
450                        Ok(DeviceRequest::Get {
451                            responder: DeviceGetResponder {
452                                control_handle: std::mem::ManuallyDrop::new(control_handle),
453                                tx_id: header.tx_id,
454                            },
455                        })
456                    }
457                    0x5ff1bca8b571d820 => {
458                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
459                        let mut req = fidl::new_empty!(
460                            DeviceSetRequest,
461                            fidl::encoding::DefaultFuchsiaResourceDialect
462                        );
463                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetRequest>(&header, _body_bytes, handles, &mut req)?;
464                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
465                        Ok(DeviceRequest::Set {
466                            rtc: req.rtc,
467
468                            responder: DeviceSetResponder {
469                                control_handle: std::mem::ManuallyDrop::new(control_handle),
470                                tx_id: header.tx_id,
471                            },
472                        })
473                    }
474                    0x16698df780253ae5 => {
475                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
476                        let mut req = fidl::new_empty!(
477                            DeviceSet2Request,
478                            fidl::encoding::DefaultFuchsiaResourceDialect
479                        );
480                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSet2Request>(&header, _body_bytes, handles, &mut req)?;
481                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
482                        Ok(DeviceRequest::Set2 {
483                            rtc: req.rtc,
484
485                            responder: DeviceSet2Responder {
486                                control_handle: std::mem::ManuallyDrop::new(control_handle),
487                                tx_id: header.tx_id,
488                            },
489                        })
490                    }
491                    _ if header.tx_id == 0
492                        && header
493                            .dynamic_flags()
494                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
495                    {
496                        Ok(DeviceRequest::_UnknownMethod {
497                            ordinal: header.ordinal,
498                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
499                            method_type: fidl::MethodType::OneWay,
500                        })
501                    }
502                    _ if header
503                        .dynamic_flags()
504                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
505                    {
506                        this.inner.send_framework_err(
507                            fidl::encoding::FrameworkErr::UnknownMethod,
508                            header.tx_id,
509                            header.ordinal,
510                            header.dynamic_flags(),
511                            (bytes, handles),
512                        )?;
513                        Ok(DeviceRequest::_UnknownMethod {
514                            ordinal: header.ordinal,
515                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
516                            method_type: fidl::MethodType::TwoWay,
517                        })
518                    }
519                    _ => Err(fidl::Error::UnknownOrdinal {
520                        ordinal: header.ordinal,
521                        protocol_name:
522                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
523                    }),
524                }))
525            },
526        )
527    }
528}
529
530#[derive(Debug)]
531pub enum DeviceRequest {
532    /// Get the current RTC time.
533    /// If the driver detects that it does not have a valid time to report, then it will return an
534    /// `ZX_ERR_INTERNAL` error.
535    Get { responder: DeviceGetResponder },
536    /// Set the RTC time.
537    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
538    ///
539    /// Deprecated, see b/382085965. Do not add new uses of this method, implement Set2() below.
540    Set { rtc: Time, responder: DeviceSetResponder },
541    /// Set the RTC time.
542    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
543    Set2 { rtc: Time, responder: DeviceSet2Responder },
544    /// An interaction was received which does not match any known method.
545    #[non_exhaustive]
546    _UnknownMethod {
547        /// Ordinal of the method that was called.
548        ordinal: u64,
549        control_handle: DeviceControlHandle,
550        method_type: fidl::MethodType,
551    },
552}
553
554impl DeviceRequest {
555    #[allow(irrefutable_let_patterns)]
556    pub fn into_get(self) -> Option<(DeviceGetResponder)> {
557        if let DeviceRequest::Get { responder } = self {
558            Some((responder))
559        } else {
560            None
561        }
562    }
563
564    #[allow(irrefutable_let_patterns)]
565    pub fn into_set(self) -> Option<(Time, DeviceSetResponder)> {
566        if let DeviceRequest::Set { rtc, responder } = self {
567            Some((rtc, responder))
568        } else {
569            None
570        }
571    }
572
573    #[allow(irrefutable_let_patterns)]
574    pub fn into_set2(self) -> Option<(Time, DeviceSet2Responder)> {
575        if let DeviceRequest::Set2 { rtc, responder } = self {
576            Some((rtc, responder))
577        } else {
578            None
579        }
580    }
581
582    /// Name of the method defined in FIDL
583    pub fn method_name(&self) -> &'static str {
584        match *self {
585            DeviceRequest::Get { .. } => "get",
586            DeviceRequest::Set { .. } => "set",
587            DeviceRequest::Set2 { .. } => "set2",
588            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
589                "unknown one-way method"
590            }
591            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
592                "unknown two-way method"
593            }
594        }
595    }
596}
597
598#[derive(Debug, Clone)]
599pub struct DeviceControlHandle {
600    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
601}
602
603impl fidl::endpoints::ControlHandle for DeviceControlHandle {
604    fn shutdown(&self) {
605        self.inner.shutdown()
606    }
607    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
608        self.inner.shutdown_with_epitaph(status)
609    }
610
611    fn is_closed(&self) -> bool {
612        self.inner.channel().is_closed()
613    }
614    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
615        self.inner.channel().on_closed()
616    }
617
618    #[cfg(target_os = "fuchsia")]
619    fn signal_peer(
620        &self,
621        clear_mask: zx::Signals,
622        set_mask: zx::Signals,
623    ) -> Result<(), zx_status::Status> {
624        use fidl::Peered;
625        self.inner.channel().signal_peer(clear_mask, set_mask)
626    }
627}
628
629impl DeviceControlHandle {}
630
631#[must_use = "FIDL methods require a response to be sent"]
632#[derive(Debug)]
633pub struct DeviceGetResponder {
634    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
635    tx_id: u32,
636}
637
638/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
639/// if the responder is dropped without sending a response, so that the client
640/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
641impl std::ops::Drop for DeviceGetResponder {
642    fn drop(&mut self) {
643        self.control_handle.shutdown();
644        // Safety: drops once, never accessed again
645        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
646    }
647}
648
649impl fidl::endpoints::Responder for DeviceGetResponder {
650    type ControlHandle = DeviceControlHandle;
651
652    fn control_handle(&self) -> &DeviceControlHandle {
653        &self.control_handle
654    }
655
656    fn drop_without_shutdown(mut self) {
657        // Safety: drops once, never accessed again due to mem::forget
658        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
659        // Prevent Drop from running (which would shut down the channel)
660        std::mem::forget(self);
661    }
662}
663
664impl DeviceGetResponder {
665    /// Sends a response to the FIDL transaction.
666    ///
667    /// Sets the channel to shutdown if an error occurs.
668    pub fn send(self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
669        let _result = self.send_raw(result);
670        if _result.is_err() {
671            self.control_handle.shutdown();
672        }
673        self.drop_without_shutdown();
674        _result
675    }
676
677    /// Similar to "send" but does not shutdown the channel if an error occurs.
678    pub fn send_no_shutdown_on_err(
679        self,
680        mut result: Result<&Time, i32>,
681    ) -> Result<(), fidl::Error> {
682        let _result = self.send_raw(result);
683        self.drop_without_shutdown();
684        _result
685    }
686
687    fn send_raw(&self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
688        self.control_handle
689            .inner
690            .send::<fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>>(
691                fidl::encoding::FlexibleResult::new(result.map(|rtc| (rtc,))),
692                self.tx_id,
693                0x27fdad10b3816ff4,
694                fidl::encoding::DynamicFlags::FLEXIBLE,
695            )
696    }
697}
698
699#[must_use = "FIDL methods require a response to be sent"]
700#[derive(Debug)]
701pub struct DeviceSetResponder {
702    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
703    tx_id: u32,
704}
705
706/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
707/// if the responder is dropped without sending a response, so that the client
708/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
709impl std::ops::Drop for DeviceSetResponder {
710    fn drop(&mut self) {
711        self.control_handle.shutdown();
712        // Safety: drops once, never accessed again
713        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
714    }
715}
716
717impl fidl::endpoints::Responder for DeviceSetResponder {
718    type ControlHandle = DeviceControlHandle;
719
720    fn control_handle(&self) -> &DeviceControlHandle {
721        &self.control_handle
722    }
723
724    fn drop_without_shutdown(mut self) {
725        // Safety: drops once, never accessed again due to mem::forget
726        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
727        // Prevent Drop from running (which would shut down the channel)
728        std::mem::forget(self);
729    }
730}
731
732impl DeviceSetResponder {
733    /// Sends a response to the FIDL transaction.
734    ///
735    /// Sets the channel to shutdown if an error occurs.
736    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
737        let _result = self.send_raw(status);
738        if _result.is_err() {
739            self.control_handle.shutdown();
740        }
741        self.drop_without_shutdown();
742        _result
743    }
744
745    /// Similar to "send" but does not shutdown the channel if an error occurs.
746    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
747        let _result = self.send_raw(status);
748        self.drop_without_shutdown();
749        _result
750    }
751
752    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
753        self.control_handle.inner.send::<fidl::encoding::FlexibleType<DeviceSetResponse>>(
754            fidl::encoding::Flexible::new((status,)),
755            self.tx_id,
756            0x5ff1bca8b571d820,
757            fidl::encoding::DynamicFlags::FLEXIBLE,
758        )
759    }
760}
761
762#[must_use = "FIDL methods require a response to be sent"]
763#[derive(Debug)]
764pub struct DeviceSet2Responder {
765    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
766    tx_id: u32,
767}
768
769/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
770/// if the responder is dropped without sending a response, so that the client
771/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
772impl std::ops::Drop for DeviceSet2Responder {
773    fn drop(&mut self) {
774        self.control_handle.shutdown();
775        // Safety: drops once, never accessed again
776        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
777    }
778}
779
780impl fidl::endpoints::Responder for DeviceSet2Responder {
781    type ControlHandle = DeviceControlHandle;
782
783    fn control_handle(&self) -> &DeviceControlHandle {
784        &self.control_handle
785    }
786
787    fn drop_without_shutdown(mut self) {
788        // Safety: drops once, never accessed again due to mem::forget
789        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
790        // Prevent Drop from running (which would shut down the channel)
791        std::mem::forget(self);
792    }
793}
794
795impl DeviceSet2Responder {
796    /// Sends a response to the FIDL transaction.
797    ///
798    /// Sets the channel to shutdown if an error occurs.
799    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
800        let _result = self.send_raw(result);
801        if _result.is_err() {
802            self.control_handle.shutdown();
803        }
804        self.drop_without_shutdown();
805        _result
806    }
807
808    /// Similar to "send" but does not shutdown the channel if an error occurs.
809    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
810        let _result = self.send_raw(result);
811        self.drop_without_shutdown();
812        _result
813    }
814
815    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
816        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
817            fidl::encoding::EmptyStruct,
818            i32,
819        >>(
820            fidl::encoding::FlexibleResult::new(result),
821            self.tx_id,
822            0x16698df780253ae5,
823            fidl::encoding::DynamicFlags::FLEXIBLE,
824        )
825    }
826}
827
828#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
829pub struct ServiceMarker;
830
831#[cfg(target_os = "fuchsia")]
832impl fidl::endpoints::ServiceMarker for ServiceMarker {
833    type Proxy = ServiceProxy;
834    type Request = ServiceRequest;
835    const SERVICE_NAME: &'static str = "fuchsia.hardware.rtc.Service";
836}
837
838/// A request for one of the member protocols of Service.
839///
840#[cfg(target_os = "fuchsia")]
841pub enum ServiceRequest {
842    Device(DeviceRequestStream),
843}
844
845#[cfg(target_os = "fuchsia")]
846impl fidl::endpoints::ServiceRequest for ServiceRequest {
847    type Service = ServiceMarker;
848
849    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
850        match name {
851            "device" => Self::Device(
852                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
853            ),
854            _ => panic!("no such member protocol name for service Service"),
855        }
856    }
857
858    fn member_names() -> &'static [&'static str] {
859        &["device"]
860    }
861}
862#[cfg(target_os = "fuchsia")]
863pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
864
865#[cfg(target_os = "fuchsia")]
866impl fidl::endpoints::ServiceProxy for ServiceProxy {
867    type Service = ServiceMarker;
868
869    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
870        Self(opener)
871    }
872}
873
874#[cfg(target_os = "fuchsia")]
875impl ServiceProxy {
876    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
877        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
878        self.connect_channel_to_device(server_end)?;
879        Ok(proxy)
880    }
881
882    /// Like `connect_to_device`, but returns a sync proxy.
883    /// See [`Self::connect_to_device`] for more details.
884    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
885        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
886        self.connect_channel_to_device(server_end)?;
887        Ok(proxy)
888    }
889
890    /// Like `connect_to_device`, but accepts a server end.
891    /// See [`Self::connect_to_device`] for more details.
892    pub fn connect_channel_to_device(
893        &self,
894        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
895    ) -> Result<(), fidl::Error> {
896        self.0.open_member("device", server_end.into_channel())
897    }
898
899    pub fn instance_name(&self) -> &str {
900        self.0.instance_name()
901    }
902}
903
904mod internal {
905    use super::*;
906}