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 Set2ResponseFut: std::future::Future<Output = Result<DeviceSet2Result, fidl::Error>> + Send;
33    fn r#set2(&self, rtc: &Time) -> Self::Set2ResponseFut;
34}
35#[derive(Debug)]
36#[cfg(target_os = "fuchsia")]
37pub struct DeviceSynchronousProxy {
38    client: fidl::client::sync::Client,
39}
40
41#[cfg(target_os = "fuchsia")]
42impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
43    type Proxy = DeviceProxy;
44    type Protocol = DeviceMarker;
45
46    fn from_channel(inner: fidl::Channel) -> Self {
47        Self::new(inner)
48    }
49
50    fn into_channel(self) -> fidl::Channel {
51        self.client.into_channel()
52    }
53
54    fn as_channel(&self) -> &fidl::Channel {
55        self.client.as_channel()
56    }
57}
58
59#[cfg(target_os = "fuchsia")]
60impl DeviceSynchronousProxy {
61    pub fn new(channel: fidl::Channel) -> Self {
62        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
63        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
64    }
65
66    pub fn into_channel(self) -> fidl::Channel {
67        self.client.into_channel()
68    }
69
70    /// Waits until an event arrives and returns it. It is safe for other
71    /// threads to make concurrent requests while waiting for an event.
72    pub fn wait_for_event(
73        &self,
74        deadline: zx::MonotonicInstant,
75    ) -> Result<DeviceEvent, fidl::Error> {
76        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
77    }
78
79    /// Get the current RTC time.
80    /// If the driver detects that it does not have a valid time to report, then it will return an
81    /// `ZX_ERR_INTERNAL` error.
82    pub fn r#get(&self, ___deadline: zx::MonotonicInstant) -> Result<DeviceGetResult, fidl::Error> {
83        let _response = self.client.send_query::<
84            fidl::encoding::EmptyPayload,
85            fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
86        >(
87            (),
88            0x27fdad10b3816ff4,
89            fidl::encoding::DynamicFlags::FLEXIBLE,
90            ___deadline,
91        )?
92        .into_result::<DeviceMarker>("get")?;
93        Ok(_response.map(|x| x.rtc))
94    }
95
96    /// Set the RTC time.
97    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
98    pub fn r#set2(
99        &self,
100        mut rtc: &Time,
101        ___deadline: zx::MonotonicInstant,
102    ) -> Result<DeviceSet2Result, fidl::Error> {
103        let _response = self.client.send_query::<
104            DeviceSet2Request,
105            fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
106        >(
107            (rtc,),
108            0x16698df780253ae5,
109            fidl::encoding::DynamicFlags::FLEXIBLE,
110            ___deadline,
111        )?
112        .into_result::<DeviceMarker>("set2")?;
113        Ok(_response.map(|x| x))
114    }
115}
116
117#[cfg(target_os = "fuchsia")]
118impl From<DeviceSynchronousProxy> for zx::NullableHandle {
119    fn from(value: DeviceSynchronousProxy) -> Self {
120        value.into_channel().into()
121    }
122}
123
124#[cfg(target_os = "fuchsia")]
125impl From<fidl::Channel> for DeviceSynchronousProxy {
126    fn from(value: fidl::Channel) -> Self {
127        Self::new(value)
128    }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
133    type Protocol = DeviceMarker;
134
135    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
136        Self::new(value.into_channel())
137    }
138}
139
140#[derive(Debug, Clone)]
141pub struct DeviceProxy {
142    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
143}
144
145impl fidl::endpoints::Proxy for DeviceProxy {
146    type Protocol = DeviceMarker;
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 DeviceProxy {
162    /// Create a new Proxy for fuchsia.hardware.rtc/Device.
163    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
164        let protocol_name = <DeviceMarker 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) -> DeviceEventStream {
174        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
175    }
176
177    /// Get the current RTC time.
178    /// If the driver detects that it does not have a valid time to report, then it will return an
179    /// `ZX_ERR_INTERNAL` error.
180    pub fn r#get(
181        &self,
182    ) -> fidl::client::QueryResponseFut<
183        DeviceGetResult,
184        fidl::encoding::DefaultFuchsiaResourceDialect,
185    > {
186        DeviceProxyInterface::r#get(self)
187    }
188
189    /// Set the RTC time.
190    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
191    pub fn r#set2(
192        &self,
193        mut rtc: &Time,
194    ) -> fidl::client::QueryResponseFut<
195        DeviceSet2Result,
196        fidl::encoding::DefaultFuchsiaResourceDialect,
197    > {
198        DeviceProxyInterface::r#set2(self, rtc)
199    }
200}
201
202impl DeviceProxyInterface for DeviceProxy {
203    type GetResponseFut = fidl::client::QueryResponseFut<
204        DeviceGetResult,
205        fidl::encoding::DefaultFuchsiaResourceDialect,
206    >;
207    fn r#get(&self) -> Self::GetResponseFut {
208        fn _decode(
209            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
210        ) -> Result<DeviceGetResult, fidl::Error> {
211            let _response = fidl::client::decode_transaction_body::<
212                fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>,
213                fidl::encoding::DefaultFuchsiaResourceDialect,
214                0x27fdad10b3816ff4,
215            >(_buf?)?
216            .into_result::<DeviceMarker>("get")?;
217            Ok(_response.map(|x| x.rtc))
218        }
219        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetResult>(
220            (),
221            0x27fdad10b3816ff4,
222            fidl::encoding::DynamicFlags::FLEXIBLE,
223            _decode,
224        )
225    }
226
227    type Set2ResponseFut = fidl::client::QueryResponseFut<
228        DeviceSet2Result,
229        fidl::encoding::DefaultFuchsiaResourceDialect,
230    >;
231    fn r#set2(&self, mut rtc: &Time) -> Self::Set2ResponseFut {
232        fn _decode(
233            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
234        ) -> Result<DeviceSet2Result, fidl::Error> {
235            let _response = fidl::client::decode_transaction_body::<
236                fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
237                fidl::encoding::DefaultFuchsiaResourceDialect,
238                0x16698df780253ae5,
239            >(_buf?)?
240            .into_result::<DeviceMarker>("set2")?;
241            Ok(_response.map(|x| x))
242        }
243        self.client.send_query_and_decode::<DeviceSet2Request, DeviceSet2Result>(
244            (rtc,),
245            0x16698df780253ae5,
246            fidl::encoding::DynamicFlags::FLEXIBLE,
247            _decode,
248        )
249    }
250}
251
252pub struct DeviceEventStream {
253    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
254}
255
256impl std::marker::Unpin for DeviceEventStream {}
257
258impl futures::stream::FusedStream for DeviceEventStream {
259    fn is_terminated(&self) -> bool {
260        self.event_receiver.is_terminated()
261    }
262}
263
264impl futures::Stream for DeviceEventStream {
265    type Item = Result<DeviceEvent, fidl::Error>;
266
267    fn poll_next(
268        mut self: std::pin::Pin<&mut Self>,
269        cx: &mut std::task::Context<'_>,
270    ) -> std::task::Poll<Option<Self::Item>> {
271        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
272            &mut self.event_receiver,
273            cx
274        )?) {
275            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
276            None => std::task::Poll::Ready(None),
277        }
278    }
279}
280
281#[derive(Debug)]
282pub enum DeviceEvent {
283    #[non_exhaustive]
284    _UnknownEvent {
285        /// Ordinal of the event that was sent.
286        ordinal: u64,
287    },
288}
289
290impl DeviceEvent {
291    /// Decodes a message buffer as a [`DeviceEvent`].
292    fn decode(
293        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
294    ) -> Result<DeviceEvent, fidl::Error> {
295        let (bytes, _handles) = buf.split_mut();
296        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
297        debug_assert_eq!(tx_header.tx_id, 0);
298        match tx_header.ordinal {
299            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
300                Ok(DeviceEvent::_UnknownEvent { ordinal: tx_header.ordinal })
301            }
302            _ => Err(fidl::Error::UnknownOrdinal {
303                ordinal: tx_header.ordinal,
304                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
305            }),
306        }
307    }
308}
309
310/// A Stream of incoming requests for fuchsia.hardware.rtc/Device.
311pub struct DeviceRequestStream {
312    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
313    is_terminated: bool,
314}
315
316impl std::marker::Unpin for DeviceRequestStream {}
317
318impl futures::stream::FusedStream for DeviceRequestStream {
319    fn is_terminated(&self) -> bool {
320        self.is_terminated
321    }
322}
323
324impl fidl::endpoints::RequestStream for DeviceRequestStream {
325    type Protocol = DeviceMarker;
326    type ControlHandle = DeviceControlHandle;
327
328    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
329        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
330    }
331
332    fn control_handle(&self) -> Self::ControlHandle {
333        DeviceControlHandle { inner: self.inner.clone() }
334    }
335
336    fn into_inner(
337        self,
338    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
339    {
340        (self.inner, self.is_terminated)
341    }
342
343    fn from_inner(
344        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
345        is_terminated: bool,
346    ) -> Self {
347        Self { inner, is_terminated }
348    }
349}
350
351impl futures::Stream for DeviceRequestStream {
352    type Item = Result<DeviceRequest, fidl::Error>;
353
354    fn poll_next(
355        mut self: std::pin::Pin<&mut Self>,
356        cx: &mut std::task::Context<'_>,
357    ) -> std::task::Poll<Option<Self::Item>> {
358        let this = &mut *self;
359        if this.inner.check_shutdown(cx) {
360            this.is_terminated = true;
361            return std::task::Poll::Ready(None);
362        }
363        if this.is_terminated {
364            panic!("polled DeviceRequestStream after completion");
365        }
366        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
367            |bytes, handles| {
368                match this.inner.channel().read_etc(cx, bytes, handles) {
369                    std::task::Poll::Ready(Ok(())) => {}
370                    std::task::Poll::Pending => return std::task::Poll::Pending,
371                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
372                        this.is_terminated = true;
373                        return std::task::Poll::Ready(None);
374                    }
375                    std::task::Poll::Ready(Err(e)) => {
376                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
377                            e.into(),
378                        ))));
379                    }
380                }
381
382                // A message has been received from the channel
383                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
384
385                std::task::Poll::Ready(Some(match header.ordinal {
386                    0x27fdad10b3816ff4 => {
387                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
388                        let mut req = fidl::new_empty!(
389                            fidl::encoding::EmptyPayload,
390                            fidl::encoding::DefaultFuchsiaResourceDialect
391                        );
392                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
393                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
394                        Ok(DeviceRequest::Get {
395                            responder: DeviceGetResponder {
396                                control_handle: std::mem::ManuallyDrop::new(control_handle),
397                                tx_id: header.tx_id,
398                            },
399                        })
400                    }
401                    0x16698df780253ae5 => {
402                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
403                        let mut req = fidl::new_empty!(
404                            DeviceSet2Request,
405                            fidl::encoding::DefaultFuchsiaResourceDialect
406                        );
407                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSet2Request>(&header, _body_bytes, handles, &mut req)?;
408                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
409                        Ok(DeviceRequest::Set2 {
410                            rtc: req.rtc,
411
412                            responder: DeviceSet2Responder {
413                                control_handle: std::mem::ManuallyDrop::new(control_handle),
414                                tx_id: header.tx_id,
415                            },
416                        })
417                    }
418                    _ if header.tx_id == 0
419                        && header
420                            .dynamic_flags()
421                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
422                    {
423                        Ok(DeviceRequest::_UnknownMethod {
424                            ordinal: header.ordinal,
425                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
426                            method_type: fidl::MethodType::OneWay,
427                        })
428                    }
429                    _ if header
430                        .dynamic_flags()
431                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
432                    {
433                        this.inner.send_framework_err(
434                            fidl::encoding::FrameworkErr::UnknownMethod,
435                            header.tx_id,
436                            header.ordinal,
437                            header.dynamic_flags(),
438                            (bytes, handles),
439                        )?;
440                        Ok(DeviceRequest::_UnknownMethod {
441                            ordinal: header.ordinal,
442                            control_handle: DeviceControlHandle { inner: this.inner.clone() },
443                            method_type: fidl::MethodType::TwoWay,
444                        })
445                    }
446                    _ => Err(fidl::Error::UnknownOrdinal {
447                        ordinal: header.ordinal,
448                        protocol_name:
449                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
450                    }),
451                }))
452            },
453        )
454    }
455}
456
457#[derive(Debug)]
458pub enum DeviceRequest {
459    /// Get the current RTC time.
460    /// If the driver detects that it does not have a valid time to report, then it will return an
461    /// `ZX_ERR_INTERNAL` error.
462    Get { responder: DeviceGetResponder },
463    /// Set the RTC time.
464    /// If the RTC time is not valid, the driver will return an `ZX_ERR_OUT_OF_RANGE` error.
465    Set2 { rtc: Time, responder: DeviceSet2Responder },
466    /// An interaction was received which does not match any known method.
467    #[non_exhaustive]
468    _UnknownMethod {
469        /// Ordinal of the method that was called.
470        ordinal: u64,
471        control_handle: DeviceControlHandle,
472        method_type: fidl::MethodType,
473    },
474}
475
476impl DeviceRequest {
477    #[allow(irrefutable_let_patterns)]
478    pub fn into_get(self) -> Option<(DeviceGetResponder)> {
479        if let DeviceRequest::Get { responder } = self { Some((responder)) } else { None }
480    }
481
482    #[allow(irrefutable_let_patterns)]
483    pub fn into_set2(self) -> Option<(Time, DeviceSet2Responder)> {
484        if let DeviceRequest::Set2 { rtc, responder } = self {
485            Some((rtc, responder))
486        } else {
487            None
488        }
489    }
490
491    /// Name of the method defined in FIDL
492    pub fn method_name(&self) -> &'static str {
493        match *self {
494            DeviceRequest::Get { .. } => "get",
495            DeviceRequest::Set2 { .. } => "set2",
496            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
497                "unknown one-way method"
498            }
499            DeviceRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
500                "unknown two-way method"
501            }
502        }
503    }
504}
505
506#[derive(Debug, Clone)]
507pub struct DeviceControlHandle {
508    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
509}
510
511impl fidl::endpoints::ControlHandle for DeviceControlHandle {
512    fn shutdown(&self) {
513        self.inner.shutdown()
514    }
515
516    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
517        self.inner.shutdown_with_epitaph(status)
518    }
519
520    fn is_closed(&self) -> bool {
521        self.inner.channel().is_closed()
522    }
523    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
524        self.inner.channel().on_closed()
525    }
526
527    #[cfg(target_os = "fuchsia")]
528    fn signal_peer(
529        &self,
530        clear_mask: zx::Signals,
531        set_mask: zx::Signals,
532    ) -> Result<(), zx_status::Status> {
533        use fidl::Peered;
534        self.inner.channel().signal_peer(clear_mask, set_mask)
535    }
536}
537
538impl DeviceControlHandle {}
539
540#[must_use = "FIDL methods require a response to be sent"]
541#[derive(Debug)]
542pub struct DeviceGetResponder {
543    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
544    tx_id: u32,
545}
546
547/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
548/// if the responder is dropped without sending a response, so that the client
549/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
550impl std::ops::Drop for DeviceGetResponder {
551    fn drop(&mut self) {
552        self.control_handle.shutdown();
553        // Safety: drops once, never accessed again
554        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
555    }
556}
557
558impl fidl::endpoints::Responder for DeviceGetResponder {
559    type ControlHandle = DeviceControlHandle;
560
561    fn control_handle(&self) -> &DeviceControlHandle {
562        &self.control_handle
563    }
564
565    fn drop_without_shutdown(mut self) {
566        // Safety: drops once, never accessed again due to mem::forget
567        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
568        // Prevent Drop from running (which would shut down the channel)
569        std::mem::forget(self);
570    }
571}
572
573impl DeviceGetResponder {
574    /// Sends a response to the FIDL transaction.
575    ///
576    /// Sets the channel to shutdown if an error occurs.
577    pub fn send(self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
578        let _result = self.send_raw(result);
579        if _result.is_err() {
580            self.control_handle.shutdown();
581        }
582        self.drop_without_shutdown();
583        _result
584    }
585
586    /// Similar to "send" but does not shutdown the channel if an error occurs.
587    pub fn send_no_shutdown_on_err(
588        self,
589        mut result: Result<&Time, i32>,
590    ) -> Result<(), fidl::Error> {
591        let _result = self.send_raw(result);
592        self.drop_without_shutdown();
593        _result
594    }
595
596    fn send_raw(&self, mut result: Result<&Time, i32>) -> Result<(), fidl::Error> {
597        self.control_handle
598            .inner
599            .send::<fidl::encoding::FlexibleResultType<DeviceGetResponse, i32>>(
600                fidl::encoding::FlexibleResult::new(result.map(|rtc| (rtc,))),
601                self.tx_id,
602                0x27fdad10b3816ff4,
603                fidl::encoding::DynamicFlags::FLEXIBLE,
604            )
605    }
606}
607
608#[must_use = "FIDL methods require a response to be sent"]
609#[derive(Debug)]
610pub struct DeviceSet2Responder {
611    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
612    tx_id: u32,
613}
614
615/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
616/// if the responder is dropped without sending a response, so that the client
617/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
618impl std::ops::Drop for DeviceSet2Responder {
619    fn drop(&mut self) {
620        self.control_handle.shutdown();
621        // Safety: drops once, never accessed again
622        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
623    }
624}
625
626impl fidl::endpoints::Responder for DeviceSet2Responder {
627    type ControlHandle = DeviceControlHandle;
628
629    fn control_handle(&self) -> &DeviceControlHandle {
630        &self.control_handle
631    }
632
633    fn drop_without_shutdown(mut self) {
634        // Safety: drops once, never accessed again due to mem::forget
635        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
636        // Prevent Drop from running (which would shut down the channel)
637        std::mem::forget(self);
638    }
639}
640
641impl DeviceSet2Responder {
642    /// Sends a response to the FIDL transaction.
643    ///
644    /// Sets the channel to shutdown if an error occurs.
645    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
646        let _result = self.send_raw(result);
647        if _result.is_err() {
648            self.control_handle.shutdown();
649        }
650        self.drop_without_shutdown();
651        _result
652    }
653
654    /// Similar to "send" but does not shutdown the channel if an error occurs.
655    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
656        let _result = self.send_raw(result);
657        self.drop_without_shutdown();
658        _result
659    }
660
661    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
662        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
663            fidl::encoding::EmptyStruct,
664            i32,
665        >>(
666            fidl::encoding::FlexibleResult::new(result),
667            self.tx_id,
668            0x16698df780253ae5,
669            fidl::encoding::DynamicFlags::FLEXIBLE,
670        )
671    }
672}
673
674#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
675pub struct ServiceMarker;
676
677#[cfg(target_os = "fuchsia")]
678impl fidl::endpoints::ServiceMarker for ServiceMarker {
679    type Proxy = ServiceProxy;
680    type Request = ServiceRequest;
681    const SERVICE_NAME: &'static str = "fuchsia.hardware.rtc.Service";
682}
683
684/// A request for one of the member protocols of Service.
685///
686#[cfg(target_os = "fuchsia")]
687pub enum ServiceRequest {
688    Device(DeviceRequestStream),
689}
690
691#[cfg(target_os = "fuchsia")]
692impl fidl::endpoints::ServiceRequest for ServiceRequest {
693    type Service = ServiceMarker;
694
695    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
696        match name {
697            "device" => Self::Device(
698                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
699            ),
700            _ => panic!("no such member protocol name for service Service"),
701        }
702    }
703
704    fn member_names() -> &'static [&'static str] {
705        &["device"]
706    }
707}
708#[cfg(target_os = "fuchsia")]
709pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
710
711#[cfg(target_os = "fuchsia")]
712impl fidl::endpoints::ServiceProxy for ServiceProxy {
713    type Service = ServiceMarker;
714
715    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
716        Self(opener)
717    }
718}
719
720#[cfg(target_os = "fuchsia")]
721impl ServiceProxy {
722    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
723        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
724        self.connect_channel_to_device(server_end)?;
725        Ok(proxy)
726    }
727
728    /// Like `connect_to_device`, but returns a sync proxy.
729    /// See [`Self::connect_to_device`] for more details.
730    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
731        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
732        self.connect_channel_to_device(server_end)?;
733        Ok(proxy)
734    }
735
736    /// Like `connect_to_device`, but accepts a server end.
737    /// See [`Self::connect_to_device`] for more details.
738    pub fn connect_channel_to_device(
739        &self,
740        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
741    ) -> Result<(), fidl::Error> {
742        self.0.open_member("device", server_end.into_channel())
743    }
744
745    pub fn instance_name(&self) -> &str {
746        self.0.instance_name()
747    }
748}
749
750mod internal {
751    use super::*;
752}