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