Skip to main content

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