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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
14#[repr(C)]
15pub struct DeviceSetRequest {
16    pub rtc: Time,
17}
18
19impl fidl::Persistable for DeviceSetRequest {}
20
21#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
22#[repr(C)]
23pub struct DeviceGetResponse {
24    pub rtc: Time,
25}
26
27impl fidl::Persistable for DeviceGetResponse {}
28
29#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
30#[repr(C)]
31pub struct DeviceSetResponse {
32    pub status: i32,
33}
34
35impl fidl::Persistable for DeviceSetResponse {}
36
37#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
38#[repr(C)]
39pub struct Time {
40    pub seconds: u8,
41    pub minutes: u8,
42    pub hours: u8,
43    pub day: u8,
44    pub month: u8,
45    pub year: u16,
46}
47
48impl fidl::Persistable for Time {}
49
50#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
51pub struct DeviceMarker;
52
53impl fidl::endpoints::ProtocolMarker for DeviceMarker {
54    type Proxy = DeviceProxy;
55    type RequestStream = DeviceRequestStream;
56    #[cfg(target_os = "fuchsia")]
57    type SynchronousProxy = DeviceSynchronousProxy;
58
59    const DEBUG_NAME: &'static str = "fuchsia.hardware.rtc.Device";
60}
61impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
62pub type DeviceGetResult = Result<Time, i32>;
63
64pub trait DeviceProxyInterface: Send + Sync {
65    type GetResponseFut: std::future::Future<Output = Result<DeviceGetResult, fidl::Error>> + Send;
66    fn r#get(&self) -> Self::GetResponseFut;
67    type SetResponseFut: std::future::Future<Output = Result<i32, fidl::Error>> + Send;
68    fn r#set(&self, rtc: &Time) -> Self::SetResponseFut;
69}
70#[derive(Debug)]
71#[cfg(target_os = "fuchsia")]
72pub struct DeviceSynchronousProxy {
73    client: fidl::client::sync::Client,
74}
75
76#[cfg(target_os = "fuchsia")]
77impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
78    type Proxy = DeviceProxy;
79    type Protocol = DeviceMarker;
80
81    fn from_channel(inner: fidl::Channel) -> Self {
82        Self::new(inner)
83    }
84
85    fn into_channel(self) -> fidl::Channel {
86        self.client.into_channel()
87    }
88
89    fn as_channel(&self) -> &fidl::Channel {
90        self.client.as_channel()
91    }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl DeviceSynchronousProxy {
96    pub fn new(channel: fidl::Channel) -> Self {
97        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
98        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
99    }
100
101    pub fn into_channel(self) -> fidl::Channel {
102        self.client.into_channel()
103    }
104
105    /// Waits until an event arrives and returns it. It is safe for other
106    /// threads to make concurrent requests while waiting for an event.
107    pub fn wait_for_event(
108        &self,
109        deadline: zx::MonotonicInstant,
110    ) -> Result<DeviceEvent, fidl::Error> {
111        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
112    }
113
114    /// Get the current RTC time.
115    /// If the driver detects that it does not have a valid time to report, then it will return an
116    /// `ZX_ERR_INTERNAL` error.
117    pub fn r#get(&self, ___deadline: zx::MonotonicInstant) -> Result<DeviceGetResult, fidl::Error> {
118        let _response = self.client.send_query::<
119            fidl::encoding::EmptyPayload,
120            fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
121        >(
122            (),
123            0x27fdad10b3816ff4,
124            fidl::encoding::DynamicFlags::FLEXIBLE,
125            ___deadline,
126        )?
127        .into_result::<DeviceMarker>("get")?;
128        Ok(_response.map(|x| x.rtc))
129    }
130
131    /// Set the RTC time.
132    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
133    pub fn r#set(
134        &self,
135        mut rtc: &Time,
136        ___deadline: zx::MonotonicInstant,
137    ) -> Result<i32, fidl::Error> {
138        let _response = self
139            .client
140            .send_query::<DeviceSetRequest, fidl::encoding::FlexibleType<DeviceSetResponse>>(
141                (rtc,),
142                0x5ff1bca8b571d820,
143                fidl::encoding::DynamicFlags::FLEXIBLE,
144                ___deadline,
145            )?
146            .into_result::<DeviceMarker>("set")?;
147        Ok(_response.status)
148    }
149}
150
151#[derive(Debug, Clone)]
152pub struct DeviceProxy {
153    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
154}
155
156impl fidl::endpoints::Proxy for DeviceProxy {
157    type Protocol = DeviceMarker;
158
159    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
160        Self::new(inner)
161    }
162
163    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
164        self.client.into_channel().map_err(|client| Self { client })
165    }
166
167    fn as_channel(&self) -> &::fidl::AsyncChannel {
168        self.client.as_channel()
169    }
170}
171
172impl DeviceProxy {
173    /// Create a new Proxy for fuchsia.hardware.rtc/Device.
174    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
175        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
176        Self { client: fidl::client::Client::new(channel, protocol_name) }
177    }
178
179    /// Get a Stream of events from the remote end of the protocol.
180    ///
181    /// # Panics
182    ///
183    /// Panics if the event stream was already taken.
184    pub fn take_event_stream(&self) -> DeviceEventStream {
185        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
186    }
187
188    /// Get the current RTC time.
189    /// If the driver detects that it does not have a valid time to report, then it will return an
190    /// `ZX_ERR_INTERNAL` error.
191    pub fn r#get(
192        &self,
193    ) -> fidl::client::QueryResponseFut<
194        DeviceGetResult,
195        fidl::encoding::DefaultFuchsiaResourceDialect,
196    > {
197        DeviceProxyInterface::r#get(self)
198    }
199
200    /// Set the RTC time.
201    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
202    pub fn r#set(
203        &self,
204        mut rtc: &Time,
205    ) -> fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect> {
206        DeviceProxyInterface::r#set(self, rtc)
207    }
208}
209
210impl DeviceProxyInterface for DeviceProxy {
211    type GetResponseFut = fidl::client::QueryResponseFut<
212        DeviceGetResult,
213        fidl::encoding::DefaultFuchsiaResourceDialect,
214    >;
215    fn r#get(&self) -> Self::GetResponseFut {
216        fn _decode(
217            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
218        ) -> Result<DeviceGetResult, fidl::Error> {
219            let _response = fidl::client::decode_transaction_body::<
220                fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
221                fidl::encoding::DefaultFuchsiaResourceDialect,
222                0x27fdad10b3816ff4,
223            >(_buf?)?
224            .into_result::<DeviceMarker>("get")?;
225            Ok(_response.map(|x| x.rtc))
226        }
227        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetResult>(
228            (),
229            0x27fdad10b3816ff4,
230            fidl::encoding::DynamicFlags::FLEXIBLE,
231            _decode,
232        )
233    }
234
235    type SetResponseFut =
236        fidl::client::QueryResponseFut<i32, fidl::encoding::DefaultFuchsiaResourceDialect>;
237    fn r#set(&self, mut rtc: &Time) -> Self::SetResponseFut {
238        fn _decode(
239            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
240        ) -> Result<i32, fidl::Error> {
241            let _response = fidl::client::decode_transaction_body::<
242                fidl::encoding::FlexibleType<DeviceSetResponse>,
243                fidl::encoding::DefaultFuchsiaResourceDialect,
244                0x5ff1bca8b571d820,
245            >(_buf?)?
246            .into_result::<DeviceMarker>("set")?;
247            Ok(_response.status)
248        }
249        self.client.send_query_and_decode::<DeviceSetRequest, i32>(
250            (rtc,),
251            0x5ff1bca8b571d820,
252            fidl::encoding::DynamicFlags::FLEXIBLE,
253            _decode,
254        )
255    }
256}
257
258pub struct DeviceEventStream {
259    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
260}
261
262impl std::marker::Unpin for DeviceEventStream {}
263
264impl futures::stream::FusedStream for DeviceEventStream {
265    fn is_terminated(&self) -> bool {
266        self.event_receiver.is_terminated()
267    }
268}
269
270impl futures::Stream for DeviceEventStream {
271    type Item = Result<DeviceEvent, fidl::Error>;
272
273    fn poll_next(
274        mut self: std::pin::Pin<&mut Self>,
275        cx: &mut std::task::Context<'_>,
276    ) -> std::task::Poll<Option<Self::Item>> {
277        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
278            &mut self.event_receiver,
279            cx
280        )?) {
281            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
282            None => std::task::Poll::Ready(None),
283        }
284    }
285}
286
287#[derive(Debug)]
288pub enum DeviceEvent {
289    #[non_exhaustive]
290    _UnknownEvent {
291        /// Ordinal of the event that was sent.
292        ordinal: u64,
293    },
294}
295
296impl DeviceEvent {
297    /// Decodes a message buffer as a [`DeviceEvent`].
298    fn decode(
299        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
300    ) -> Result<DeviceEvent, fidl::Error> {
301        let (bytes, _handles) = buf.split_mut();
302        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
303        debug_assert_eq!(tx_header.tx_id, 0);
304        match tx_header.ordinal {
305            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
306                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
307            }
308            _ => Err(fidl::Error::UnknownOrdinal {
309                ordinal: tx_header.ordinal,
310                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
311            }),
312        }
313    }
314}
315
316/// A Stream of incoming requests for fuchsia.hardware.rtc/Device.
317pub struct DeviceRequestStream {
318    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
319    is_terminated: bool,
320}
321
322impl std::marker::Unpin for DeviceRequestStream {}
323
324impl futures::stream::FusedStream for DeviceRequestStream {
325    fn is_terminated(&self) -> bool {
326        self.is_terminated
327    }
328}
329
330impl fidl::endpoints::RequestStream for DeviceRequestStream {
331    type Protocol = DeviceMarker;
332    type ControlHandle = DeviceControlHandle;
333
334    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
335        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
336    }
337
338    fn control_handle(&self) -> Self::ControlHandle {
339        DeviceControlHandle { inner: self.inner.clone() }
340    }
341
342    fn into_inner(
343        self,
344    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
345    {
346        (self.inner, self.is_terminated)
347    }
348
349    fn from_inner(
350        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
351        is_terminated: bool,
352    ) -> Self {
353        Self { inner, is_terminated }
354    }
355}
356
357impl futures::Stream for DeviceRequestStream {
358    type Item = Result<DeviceRequest, fidl::Error>;
359
360    fn poll_next(
361        mut self: std::pin::Pin<&mut Self>,
362        cx: &mut std::task::Context<'_>,
363    ) -> std::task::Poll<Option<Self::Item>> {
364        let this = &mut *self;
365        if this.inner.check_shutdown(cx) {
366            this.is_terminated = true;
367            return std::task::Poll::Ready(None);
368        }
369        if this.is_terminated {
370            panic!("polled DeviceRequestStream after completion");
371        }
372        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
373            |bytes, handles| {
374                match this.inner.channel().read_etc(cx, bytes, handles) {
375                    std::task::Poll::Ready(Ok(())) => {}
376                    std::task::Poll::Pending => return std::task::Poll::Pending,
377                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
378                        this.is_terminated = true;
379                        return std::task::Poll::Ready(None);
380                    }
381                    std::task::Poll::Ready(Err(e)) => {
382                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
383                            e.into(),
384                        ))))
385                    }
386                }
387
388                // A message has been received from the channel
389                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
390
391                std::task::Poll::Ready(Some(match header.ordinal {
392                    0x27fdad10b3816ff4 => {
393                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
394                        let mut req = fidl::new_empty!(
395                            fidl::encoding::EmptyPayload,
396                            fidl::encoding::DefaultFuchsiaResourceDialect
397                        );
398                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
399                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
400                        Ok(DeviceRequest::Get {
401                            responder: DeviceGetResponder {
402                                control_handle: std::mem::ManuallyDrop::new(control_handle),
403                                tx_id: header.tx_id,
404                            },
405                        })
406                    }
407                    0x5ff1bca8b571d820 => {
408                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
409                        let mut req = fidl::new_empty!(
410                            DeviceSetRequest,
411                            fidl::encoding::DefaultFuchsiaResourceDialect
412                        );
413                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetRequest>(&header, _body_bytes, handles, &mut req)?;
414                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
415                        Ok(DeviceRequest::Set {
416                            rtc: req.rtc,
417
418                            responder: DeviceSetResponder {
419                                control_handle: std::mem::ManuallyDrop::new(control_handle),
420                                tx_id: header.tx_id,
421                            },
422                        })
423                    }
424                    _ if header.tx_id == 0
425                        && header
426                            .dynamic_flags()
427                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
428                    {
429                        Ok(DeviceRequest::_UnknownMethod {
430                            ordinal: header.ordinal,
431                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
432                            method_type: fidl::MethodType::OneWay,
433                        })
434                    }
435                    _ if header
436                        .dynamic_flags()
437                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
438                    {
439                        this.inner.send_framework_err(
440                            fidl::encoding::FrameworkErr::UnknownMethod,
441                            header.tx_id,
442                            header.ordinal,
443                            header.dynamic_flags(),
444                            (bytes, handles),
445                        )?;
446                        Ok(DeviceRequest::_UnknownMethod {
447                            ordinal: header.ordinal,
448                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
449                            method_type: fidl::MethodType::TwoWay,
450                        })
451                    }
452                    _ => Err(fidl::Error::UnknownOrdinal {
453                        ordinal: header.ordinal,
454                        protocol_name:
455                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
456                    }),
457                }))
458            },
459        )
460    }
461}
462
463#[derive(Debug)]
464pub enum DeviceRequest {
465    /// Get the current RTC time.
466    /// If the driver detects that it does not have a valid time to report, then it will return an
467    /// `ZX_ERR_INTERNAL` error.
468    Get { responder: DeviceGetResponder },
469    /// Set the RTC time.
470    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
471    Set { rtc: Time, responder: DeviceSetResponder },
472    /// An interaction was received which does not match any known method.
473    #[non_exhaustive]
474    _UnknownMethod {
475        /// Ordinal of the method that was called.
476        ordinal: u64,
477        control_handle: DeviceControlHandle,
478        method_type: fidl::MethodType,
479    },
480}
481
482impl DeviceRequest {
483    #[allow(irrefutable_let_patterns)]
484    pub fn into_get(self) -> Option<(DeviceGetResponder)> {
485        if let DeviceRequest::Get { responder } = self {
486            Some((responder))
487        } else {
488            None
489        }
490    }
491
492    #[allow(irrefutable_let_patterns)]
493    pub fn into_set(self) -> Option<(Time, DeviceSetResponder)> {
494        if let DeviceRequest::Set { rtc, responder } = self {
495            Some((rtc, responder))
496        } else {
497            None
498        }
499    }
500
501    /// Name of the method defined in FIDL
502    pub fn method_name(&self) -> &'static str {
503        match *self {
504            DeviceRequest::Get { .. } => "get",
505            DeviceRequest::Set { .. } => "set",
506            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
507                "unknown one-way method"
508            }
509            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
510                "unknown two-way method"
511            }
512        }
513    }
514}
515
516#[derive(Debug, Clone)]
517pub struct DeviceControlHandle {
518    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
519}
520
521impl fidl::endpoints::ControlHandle for DeviceControlHandle {
522    fn shutdown(&self) {
523        self.inner.shutdown()
524    }
525    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
526        self.inner.shutdown_with_epitaph(status)
527    }
528
529    fn is_closed(&self) -> bool {
530        self.inner.channel().is_closed()
531    }
532    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
533        self.inner.channel().on_closed()
534    }
535
536    #[cfg(target_os = "fuchsia")]
537    fn signal_peer(
538        &self,
539        clear_mask: zx::Signals,
540        set_mask: zx::Signals,
541    ) -> Result<(), zx_status::Status> {
542        use fidl::Peered;
543        self.inner.channel().signal_peer(clear_mask, set_mask)
544    }
545}
546
547impl DeviceControlHandle {}
548
549#[must_use = "FIDL methods require a response to be sent"]
550#[derive(Debug)]
551pub struct DeviceGetResponder {
552    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
553    tx_id: u32,
554}
555
556/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
557/// if the responder is dropped without sending a response, so that the client
558/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
559impl std::ops::Drop for DeviceGetResponder {
560    fn drop(&mut self) {
561        self.control_handle.shutdown();
562        // Safety: drops once, never accessed again
563        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
564    }
565}
566
567impl fidl::endpoints::Responder for DeviceGetResponder {
568    type ControlHandle = DeviceControlHandle;
569
570    fn control_handle(&self) -> &DeviceControlHandle {
571        &self.control_handle
572    }
573
574    fn drop_without_shutdown(mut self) {
575        // Safety: drops once, never accessed again due to mem::forget
576        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
577        // Prevent Drop from running (which would shut down the channel)
578        std::mem::forget(self);
579    }
580}
581
582impl DeviceGetResponder {
583    /// Sends a response to the FIDL transaction.
584    ///
585    /// Sets the channel to shutdown if an error occurs.
586    pub fn send(self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
587        let _result = self.send_raw(result);
588        if _result.is_err() {
589            self.control_handle.shutdown();
590        }
591        self.drop_without_shutdown();
592        _result
593    }
594
595    /// Similar to "send" but does not shutdown the channel if an error occurs.
596    pub fn send_no_shutdown_on_err(
597        self,
598        mut result: Result<&Time, i32>,
599    ) -> Result<(), fidl::Error> {
600        let _result = self.send_raw(result);
601        self.drop_without_shutdown();
602        _result
603    }
604
605    fn send_raw(&self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
606        self.control_handle
607            .inner
608            .send::<fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>>(
609                fidl::encoding::FlexibleResult::new(result.map(|rtc| (rtc,))),
610                self.tx_id,
611                0x27fdad10b3816ff4,
612                fidl::encoding::DynamicFlags::FLEXIBLE,
613            )
614    }
615}
616
617#[must_use = "FIDL methods require a response to be sent"]
618#[derive(Debug)]
619pub struct DeviceSetResponder {
620    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
621    tx_id: u32,
622}
623
624/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
625/// if the responder is dropped without sending a response, so that the client
626/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
627impl std::ops::Drop for DeviceSetResponder {
628    fn drop(&mut self) {
629        self.control_handle.shutdown();
630        // Safety: drops once, never accessed again
631        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
632    }
633}
634
635impl fidl::endpoints::Responder for DeviceSetResponder {
636    type ControlHandle = DeviceControlHandle;
637
638    fn control_handle(&self) -> &DeviceControlHandle {
639        &self.control_handle
640    }
641
642    fn drop_without_shutdown(mut self) {
643        // Safety: drops once, never accessed again due to mem::forget
644        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
645        // Prevent Drop from running (which would shut down the channel)
646        std::mem::forget(self);
647    }
648}
649
650impl DeviceSetResponder {
651    /// Sends a response to the FIDL transaction.
652    ///
653    /// Sets the channel to shutdown if an error occurs.
654    pub fn send(self, mut status: i32) -> Result<(), fidl::Error> {
655        let _result = self.send_raw(status);
656        if _result.is_err() {
657            self.control_handle.shutdown();
658        }
659        self.drop_without_shutdown();
660        _result
661    }
662
663    /// Similar to "send" but does not shutdown the channel if an error occurs.
664    pub fn send_no_shutdown_on_err(self, mut status: i32) -> Result<(), fidl::Error> {
665        let _result = self.send_raw(status);
666        self.drop_without_shutdown();
667        _result
668    }
669
670    fn send_raw(&self, mut status: i32) -> Result<(), fidl::Error> {
671        self.control_handle.inner.send::<fidl::encoding::FlexibleType<DeviceSetResponse>>(
672            fidl::encoding::Flexible::new((status,)),
673            self.tx_id,
674            0x5ff1bca8b571d820,
675            fidl::encoding::DynamicFlags::FLEXIBLE,
676        )
677    }
678}
679
680#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
681pub struct ServiceMarker;
682
683#[cfg(target_os = "fuchsia")]
684impl fidl::endpoints::ServiceMarker for ServiceMarker {
685    type Proxy = ServiceProxy;
686    type Request = ServiceRequest;
687    const SERVICE_NAME: &'static str = "fuchsia.hardware.rtc.Service";
688}
689
690/// A request for one of the member protocols of Service.
691///
692#[cfg(target_os = "fuchsia")]
693pub enum ServiceRequest {
694    Device(DeviceRequestStream),
695}
696
697#[cfg(target_os = "fuchsia")]
698impl fidl::endpoints::ServiceRequest for ServiceRequest {
699    type Service = ServiceMarker;
700
701    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
702        match name {
703            "device" => Self::Device(
704                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
705            ),
706            _ => panic!("no such member protocol name for service Service"),
707        }
708    }
709
710    fn member_names() -> &'static [&'static str] {
711        &["device"]
712    }
713}
714#[cfg(target_os = "fuchsia")]
715pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
716
717#[cfg(target_os = "fuchsia")]
718impl fidl::endpoints::ServiceProxy for ServiceProxy {
719    type Service = ServiceMarker;
720
721    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
722        Self(opener)
723    }
724}
725
726#[cfg(target_os = "fuchsia")]
727impl ServiceProxy {
728    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
729        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
730        self.connect_channel_to_device(server_end)?;
731        Ok(proxy)
732    }
733
734    /// Like `connect_to_device`, but returns a sync proxy.
735    /// See [`Self::connect_to_device`] for more details.
736    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
737        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
738        self.connect_channel_to_device(server_end)?;
739        Ok(proxy)
740    }
741
742    /// Like `connect_to_device`, but accepts a server end.
743    /// See [`Self::connect_to_device`] for more details.
744    pub fn connect_channel_to_device(
745        &self,
746        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
747    ) -> Result<(), fidl::Error> {
748        self.0.open_member("device", server_end.into_channel())
749    }
750
751    pub fn instance_name(&self) -> &str {
752        self.0.instance_name()
753    }
754}
755
756mod internal {
757    use super::*;
758
759    impl fidl::encoding::ValueTypeMarker for DeviceSetRequest {
760        type Borrowed<'a> = &'a Self;
761        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
762            value
763        }
764    }
765
766    unsafe impl fidl::encoding::TypeMarker for DeviceSetRequest {
767        type Owned = Self;
768
769        #[inline(always)]
770        fn inline_align(_context: fidl::encoding::Context) -> usize {
771            2
772        }
773
774        #[inline(always)]
775        fn inline_size(_context: fidl::encoding::Context) -> usize {
776            8
777        }
778    }
779
780    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceSetRequest, D>
781        for &DeviceSetRequest
782    {
783        #[inline]
784        unsafe fn encode(
785            self,
786            encoder: &mut fidl::encoding::Encoder<'_, D>,
787            offset: usize,
788            _depth: fidl::encoding::Depth,
789        ) -> fidl::Result<()> {
790            encoder.debug_check_bounds::<DeviceSetRequest>(offset);
791            unsafe {
792                // Copy the object into the buffer.
793                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
794                (buf_ptr as *mut DeviceSetRequest)
795                    .write_unaligned((self as *const DeviceSetRequest).read());
796                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
797                // done second because the memcpy will write garbage to these bytes.
798                let padding_ptr = buf_ptr.offset(4) as *mut u16;
799                let padding_mask = 0xff00u16;
800                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
801            }
802            Ok(())
803        }
804    }
805    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Time, D>>
806        fidl::encoding::Encode<DeviceSetRequest, D> for (T0,)
807    {
808        #[inline]
809        unsafe fn encode(
810            self,
811            encoder: &mut fidl::encoding::Encoder<'_, D>,
812            offset: usize,
813            depth: fidl::encoding::Depth,
814        ) -> fidl::Result<()> {
815            encoder.debug_check_bounds::<DeviceSetRequest>(offset);
816            // Zero out padding regions. There's no need to apply masks
817            // because the unmasked parts will be overwritten by fields.
818            // Write the fields.
819            self.0.encode(encoder, offset + 0, depth)?;
820            Ok(())
821        }
822    }
823
824    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceSetRequest {
825        #[inline(always)]
826        fn new_empty() -> Self {
827            Self { rtc: fidl::new_empty!(Time, D) }
828        }
829
830        #[inline]
831        unsafe fn decode(
832            &mut self,
833            decoder: &mut fidl::encoding::Decoder<'_, D>,
834            offset: usize,
835            _depth: fidl::encoding::Depth,
836        ) -> fidl::Result<()> {
837            decoder.debug_check_bounds::<Self>(offset);
838            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
839            // Verify that padding bytes are zero.
840            let ptr = unsafe { buf_ptr.offset(4) };
841            let padval = unsafe { (ptr as *const u16).read_unaligned() };
842            let mask = 0xff00u16;
843            let maskedval = padval & mask;
844            if maskedval != 0 {
845                return Err(fidl::Error::NonZeroPadding {
846                    padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
847                });
848            }
849            // Copy from the buffer into the object.
850            unsafe {
851                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
852            }
853            Ok(())
854        }
855    }
856
857    impl fidl::encoding::ValueTypeMarker for DeviceGetResponse {
858        type Borrowed<'a> = &'a Self;
859        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
860            value
861        }
862    }
863
864    unsafe impl fidl::encoding::TypeMarker for DeviceGetResponse {
865        type Owned = Self;
866
867        #[inline(always)]
868        fn inline_align(_context: fidl::encoding::Context) -> usize {
869            2
870        }
871
872        #[inline(always)]
873        fn inline_size(_context: fidl::encoding::Context) -> usize {
874            8
875        }
876    }
877
878    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceGetResponse, D>
879        for &DeviceGetResponse
880    {
881        #[inline]
882        unsafe fn encode(
883            self,
884            encoder: &mut fidl::encoding::Encoder<'_, D>,
885            offset: usize,
886            _depth: fidl::encoding::Depth,
887        ) -> fidl::Result<()> {
888            encoder.debug_check_bounds::<DeviceGetResponse>(offset);
889            unsafe {
890                // Copy the object into the buffer.
891                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
892                (buf_ptr as *mut DeviceGetResponse)
893                    .write_unaligned((self as *const DeviceGetResponse).read());
894                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
895                // done second because the memcpy will write garbage to these bytes.
896                let padding_ptr = buf_ptr.offset(4) as *mut u16;
897                let padding_mask = 0xff00u16;
898                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
899            }
900            Ok(())
901        }
902    }
903    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<Time, D>>
904        fidl::encoding::Encode<DeviceGetResponse, D> for (T0,)
905    {
906        #[inline]
907        unsafe fn encode(
908            self,
909            encoder: &mut fidl::encoding::Encoder<'_, D>,
910            offset: usize,
911            depth: fidl::encoding::Depth,
912        ) -> fidl::Result<()> {
913            encoder.debug_check_bounds::<DeviceGetResponse>(offset);
914            // Zero out padding regions. There's no need to apply masks
915            // because the unmasked parts will be overwritten by fields.
916            // Write the fields.
917            self.0.encode(encoder, offset + 0, depth)?;
918            Ok(())
919        }
920    }
921
922    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceGetResponse {
923        #[inline(always)]
924        fn new_empty() -> Self {
925            Self { rtc: fidl::new_empty!(Time, D) }
926        }
927
928        #[inline]
929        unsafe fn decode(
930            &mut self,
931            decoder: &mut fidl::encoding::Decoder<'_, D>,
932            offset: usize,
933            _depth: fidl::encoding::Depth,
934        ) -> fidl::Result<()> {
935            decoder.debug_check_bounds::<Self>(offset);
936            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
937            // Verify that padding bytes are zero.
938            let ptr = unsafe { buf_ptr.offset(4) };
939            let padval = unsafe { (ptr as *const u16).read_unaligned() };
940            let mask = 0xff00u16;
941            let maskedval = padval & mask;
942            if maskedval != 0 {
943                return Err(fidl::Error::NonZeroPadding {
944                    padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
945                });
946            }
947            // Copy from the buffer into the object.
948            unsafe {
949                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
950            }
951            Ok(())
952        }
953    }
954
955    impl fidl::encoding::ValueTypeMarker for DeviceSetResponse {
956        type Borrowed<'a> = &'a Self;
957        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
958            value
959        }
960    }
961
962    unsafe impl fidl::encoding::TypeMarker for DeviceSetResponse {
963        type Owned = Self;
964
965        #[inline(always)]
966        fn inline_align(_context: fidl::encoding::Context) -> usize {
967            4
968        }
969
970        #[inline(always)]
971        fn inline_size(_context: fidl::encoding::Context) -> usize {
972            4
973        }
974        #[inline(always)]
975        fn encode_is_copy() -> bool {
976            true
977        }
978
979        #[inline(always)]
980        fn decode_is_copy() -> bool {
981            true
982        }
983    }
984
985    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceSetResponse, D>
986        for &DeviceSetResponse
987    {
988        #[inline]
989        unsafe fn encode(
990            self,
991            encoder: &mut fidl::encoding::Encoder<'_, D>,
992            offset: usize,
993            _depth: fidl::encoding::Depth,
994        ) -> fidl::Result<()> {
995            encoder.debug_check_bounds::<DeviceSetResponse>(offset);
996            unsafe {
997                // Copy the object into the buffer.
998                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
999                (buf_ptr as *mut DeviceSetResponse)
1000                    .write_unaligned((self as *const DeviceSetResponse).read());
1001                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
1002                // done second because the memcpy will write garbage to these bytes.
1003            }
1004            Ok(())
1005        }
1006    }
1007    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<i32, D>>
1008        fidl::encoding::Encode<DeviceSetResponse, D> for (T0,)
1009    {
1010        #[inline]
1011        unsafe fn encode(
1012            self,
1013            encoder: &mut fidl::encoding::Encoder<'_, D>,
1014            offset: usize,
1015            depth: fidl::encoding::Depth,
1016        ) -> fidl::Result<()> {
1017            encoder.debug_check_bounds::<DeviceSetResponse>(offset);
1018            // Zero out padding regions. There's no need to apply masks
1019            // because the unmasked parts will be overwritten by fields.
1020            // Write the fields.
1021            self.0.encode(encoder, offset + 0, depth)?;
1022            Ok(())
1023        }
1024    }
1025
1026    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceSetResponse {
1027        #[inline(always)]
1028        fn new_empty() -> Self {
1029            Self { status: fidl::new_empty!(i32, D) }
1030        }
1031
1032        #[inline]
1033        unsafe fn decode(
1034            &mut self,
1035            decoder: &mut fidl::encoding::Decoder<'_, D>,
1036            offset: usize,
1037            _depth: fidl::encoding::Depth,
1038        ) -> fidl::Result<()> {
1039            decoder.debug_check_bounds::<Self>(offset);
1040            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
1041            // Verify that padding bytes are zero.
1042            // Copy from the buffer into the object.
1043            unsafe {
1044                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 4);
1045            }
1046            Ok(())
1047        }
1048    }
1049
1050    impl fidl::encoding::ValueTypeMarker for Time {
1051        type Borrowed<'a> = &'a Self;
1052        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
1053            value
1054        }
1055    }
1056
1057    unsafe impl fidl::encoding::TypeMarker for Time {
1058        type Owned = Self;
1059
1060        #[inline(always)]
1061        fn inline_align(_context: fidl::encoding::Context) -> usize {
1062            2
1063        }
1064
1065        #[inline(always)]
1066        fn inline_size(_context: fidl::encoding::Context) -> usize {
1067            8
1068        }
1069    }
1070
1071    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Time, D> for &Time {
1072        #[inline]
1073        unsafe fn encode(
1074            self,
1075            encoder: &mut fidl::encoding::Encoder<'_, D>,
1076            offset: usize,
1077            _depth: fidl::encoding::Depth,
1078        ) -> fidl::Result<()> {
1079            encoder.debug_check_bounds::<Time>(offset);
1080            unsafe {
1081                // Copy the object into the buffer.
1082                let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
1083                (buf_ptr as *mut Time).write_unaligned((self as *const Time).read());
1084                // Zero out padding regions. Unlike `fidl_struct_impl_noncopy!`, this must be
1085                // done second because the memcpy will write garbage to these bytes.
1086                let padding_ptr = buf_ptr.offset(4) as *mut u16;
1087                let padding_mask = 0xff00u16;
1088                padding_ptr.write_unaligned(padding_ptr.read_unaligned() & !padding_mask);
1089            }
1090            Ok(())
1091        }
1092    }
1093    unsafe impl<
1094            D: fidl::encoding::ResourceDialect,
1095            T0: fidl::encoding::Encode<u8, D>,
1096            T1: fidl::encoding::Encode<u8, D>,
1097            T2: fidl::encoding::Encode<u8, D>,
1098            T3: fidl::encoding::Encode<u8, D>,
1099            T4: fidl::encoding::Encode<u8, D>,
1100            T5: fidl::encoding::Encode<u16, D>,
1101        > fidl::encoding::Encode<Time, D> for (T0, T1, T2, T3, T4, T5)
1102    {
1103        #[inline]
1104        unsafe fn encode(
1105            self,
1106            encoder: &mut fidl::encoding::Encoder<'_, D>,
1107            offset: usize,
1108            depth: fidl::encoding::Depth,
1109        ) -> fidl::Result<()> {
1110            encoder.debug_check_bounds::<Time>(offset);
1111            // Zero out padding regions. There's no need to apply masks
1112            // because the unmasked parts will be overwritten by fields.
1113            unsafe {
1114                let ptr = encoder.buf.as_mut_ptr().add(offset).offset(4);
1115                (ptr as *mut u16).write_unaligned(0);
1116            }
1117            // Write the fields.
1118            self.0.encode(encoder, offset + 0, depth)?;
1119            self.1.encode(encoder, offset + 1, depth)?;
1120            self.2.encode(encoder, offset + 2, depth)?;
1121            self.3.encode(encoder, offset + 3, depth)?;
1122            self.4.encode(encoder, offset + 4, depth)?;
1123            self.5.encode(encoder, offset + 6, depth)?;
1124            Ok(())
1125        }
1126    }
1127
1128    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for Time {
1129        #[inline(always)]
1130        fn new_empty() -> Self {
1131            Self {
1132                seconds: fidl::new_empty!(u8, D),
1133                minutes: fidl::new_empty!(u8, D),
1134                hours: fidl::new_empty!(u8, D),
1135                day: fidl::new_empty!(u8, D),
1136                month: fidl::new_empty!(u8, D),
1137                year: fidl::new_empty!(u16, D),
1138            }
1139        }
1140
1141        #[inline]
1142        unsafe fn decode(
1143            &mut self,
1144            decoder: &mut fidl::encoding::Decoder<'_, D>,
1145            offset: usize,
1146            _depth: fidl::encoding::Depth,
1147        ) -> fidl::Result<()> {
1148            decoder.debug_check_bounds::<Self>(offset);
1149            let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
1150            // Verify that padding bytes are zero.
1151            let ptr = unsafe { buf_ptr.offset(4) };
1152            let padval = unsafe { (ptr as *const u16).read_unaligned() };
1153            let mask = 0xff00u16;
1154            let maskedval = padval & mask;
1155            if maskedval != 0 {
1156                return Err(fidl::Error::NonZeroPadding {
1157                    padding_start: offset + 4 + ((mask as u64).trailing_zeros() / 8) as usize,
1158                });
1159            }
1160            // Copy from the buffer into the object.
1161            unsafe {
1162                std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
1163            }
1164            Ok(())
1165        }
1166    }
1167}