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