fidl_fuchsia_system_state/
fidl_fuchsia_system_state.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13/// The number of variants of `SystemPowerState`.
14pub const MAX_SYSTEM_POWER_STATES: u32 = 8;
15
16#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
17#[repr(u8)]
18pub enum SystemPowerState {
19    FullyOn = 1,
20    Reboot = 2,
21    RebootBootloader = 3,
22    RebootRecovery = 4,
23    Poweroff = 5,
24    Mexec = 6,
25    SuspendRam = 7,
26    RebootKernelInitiated = 8,
27}
28
29impl SystemPowerState {
30    #[inline]
31    pub fn from_primitive(prim: u8) -> Option<Self> {
32        match prim {
33            1 => Some(Self::FullyOn),
34            2 => Some(Self::Reboot),
35            3 => Some(Self::RebootBootloader),
36            4 => Some(Self::RebootRecovery),
37            5 => Some(Self::Poweroff),
38            6 => Some(Self::Mexec),
39            7 => Some(Self::SuspendRam),
40            8 => Some(Self::RebootKernelInitiated),
41            _ => None,
42        }
43    }
44
45    #[inline]
46    pub const fn into_primitive(self) -> u8 {
47        self as u8
48    }
49
50    #[deprecated = "Strict enums should not use `is_unknown`"]
51    #[inline]
52    pub fn is_unknown(&self) -> bool {
53        false
54    }
55}
56
57#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
58pub struct SystemStateTransitionGetTerminationSystemStateResponse {
59    pub state: SystemPowerState,
60}
61
62impl fidl::Persistable for SystemStateTransitionGetTerminationSystemStateResponse {}
63
64#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
65pub struct SystemStateTransitionGetMexecZbisResponse {
66    pub kernel_zbi: fidl::Vmo,
67    pub data_zbi: fidl::Vmo,
68}
69
70impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
71    for SystemStateTransitionGetMexecZbisResponse
72{
73}
74
75#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
76pub struct SystemStateTransitionMarker;
77
78impl fidl::endpoints::ProtocolMarker for SystemStateTransitionMarker {
79    type Proxy = SystemStateTransitionProxy;
80    type RequestStream = SystemStateTransitionRequestStream;
81    #[cfg(target_os = "fuchsia")]
82    type SynchronousProxy = SystemStateTransitionSynchronousProxy;
83
84    const DEBUG_NAME: &'static str = "fuchsia.system.state.SystemStateTransition";
85}
86impl fidl::endpoints::DiscoverableProtocolMarker for SystemStateTransitionMarker {}
87pub type SystemStateTransitionGetMexecZbisResult = Result<(fidl::Vmo, fidl::Vmo), i32>;
88
89pub trait SystemStateTransitionProxyInterface: Send + Sync {
90    type GetTerminationSystemStateResponseFut: std::future::Future<Output = Result<SystemPowerState, fidl::Error>>
91        + Send;
92    fn r#get_termination_system_state(&self) -> Self::GetTerminationSystemStateResponseFut;
93    type GetMexecZbisResponseFut: std::future::Future<Output = Result<SystemStateTransitionGetMexecZbisResult, fidl::Error>>
94        + Send;
95    fn r#get_mexec_zbis(&self) -> Self::GetMexecZbisResponseFut;
96}
97#[derive(Debug)]
98#[cfg(target_os = "fuchsia")]
99pub struct SystemStateTransitionSynchronousProxy {
100    client: fidl::client::sync::Client,
101}
102
103#[cfg(target_os = "fuchsia")]
104impl fidl::endpoints::SynchronousProxy for SystemStateTransitionSynchronousProxy {
105    type Proxy = SystemStateTransitionProxy;
106    type Protocol = SystemStateTransitionMarker;
107
108    fn from_channel(inner: fidl::Channel) -> Self {
109        Self::new(inner)
110    }
111
112    fn into_channel(self) -> fidl::Channel {
113        self.client.into_channel()
114    }
115
116    fn as_channel(&self) -> &fidl::Channel {
117        self.client.as_channel()
118    }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl SystemStateTransitionSynchronousProxy {
123    pub fn new(channel: fidl::Channel) -> Self {
124        let protocol_name =
125            <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
126        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
127    }
128
129    pub fn into_channel(self) -> fidl::Channel {
130        self.client.into_channel()
131    }
132
133    /// Waits until an event arrives and returns it. It is safe for other
134    /// threads to make concurrent requests while waiting for an event.
135    pub fn wait_for_event(
136        &self,
137        deadline: zx::MonotonicInstant,
138    ) -> Result<SystemStateTransitionEvent, fidl::Error> {
139        SystemStateTransitionEvent::decode(self.client.wait_for_event(deadline)?)
140    }
141
142    /// Gets the termination state.
143    pub fn r#get_termination_system_state(
144        &self,
145        ___deadline: zx::MonotonicInstant,
146    ) -> Result<SystemPowerState, fidl::Error> {
147        let _response = self.client.send_query::<
148            fidl::encoding::EmptyPayload,
149            SystemStateTransitionGetTerminationSystemStateResponse,
150        >(
151            (),
152            0x7570e8c601c5e27e,
153            fidl::encoding::DynamicFlags::empty(),
154            ___deadline,
155        )?;
156        Ok(_response.state)
157    }
158
159    /// When the system termination state is MEXEC, in the course of shutting
160    /// down, driver_manager will perform an mexec itself after suspending all
161    /// drivers. This method allows driver manager to fetch the kernel and
162    /// data ZBIs to be passed to zx_system_mexec().
163    ///
164    /// This method only should only be invoked in the case MEXEC shutdown.
165    ///
166    /// It is expected that the ZBI items specified by
167    /// `zx_system_mexec_payload_get()` have not yet been appended to the
168    /// provided data ZBI.
169    ///
170    /// Returns
171    /// * ZX_ERR_BAD_STATE: The termination system state is not set to MEXEC.
172    pub fn r#get_mexec_zbis(
173        &self,
174        ___deadline: zx::MonotonicInstant,
175    ) -> Result<SystemStateTransitionGetMexecZbisResult, fidl::Error> {
176        let _response =
177            self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::ResultType<
178                SystemStateTransitionGetMexecZbisResponse,
179                i32,
180            >>(
181                (),
182                0x4d5efe452f310fef,
183                fidl::encoding::DynamicFlags::empty(),
184                ___deadline,
185            )?;
186        Ok(_response.map(|x| (x.kernel_zbi, x.data_zbi)))
187    }
188}
189
190#[derive(Debug, Clone)]
191pub struct SystemStateTransitionProxy {
192    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
193}
194
195impl fidl::endpoints::Proxy for SystemStateTransitionProxy {
196    type Protocol = SystemStateTransitionMarker;
197
198    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
199        Self::new(inner)
200    }
201
202    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
203        self.client.into_channel().map_err(|client| Self { client })
204    }
205
206    fn as_channel(&self) -> &::fidl::AsyncChannel {
207        self.client.as_channel()
208    }
209}
210
211impl SystemStateTransitionProxy {
212    /// Create a new Proxy for fuchsia.system.state/SystemStateTransition.
213    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
214        let protocol_name =
215            <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
216        Self { client: fidl::client::Client::new(channel, protocol_name) }
217    }
218
219    /// Get a Stream of events from the remote end of the protocol.
220    ///
221    /// # Panics
222    ///
223    /// Panics if the event stream was already taken.
224    pub fn take_event_stream(&self) -> SystemStateTransitionEventStream {
225        SystemStateTransitionEventStream { event_receiver: self.client.take_event_receiver() }
226    }
227
228    /// Gets the termination state.
229    pub fn r#get_termination_system_state(
230        &self,
231    ) -> fidl::client::QueryResponseFut<
232        SystemPowerState,
233        fidl::encoding::DefaultFuchsiaResourceDialect,
234    > {
235        SystemStateTransitionProxyInterface::r#get_termination_system_state(self)
236    }
237
238    /// When the system termination state is MEXEC, in the course of shutting
239    /// down, driver_manager will perform an mexec itself after suspending all
240    /// drivers. This method allows driver manager to fetch the kernel and
241    /// data ZBIs to be passed to zx_system_mexec().
242    ///
243    /// This method only should only be invoked in the case MEXEC shutdown.
244    ///
245    /// It is expected that the ZBI items specified by
246    /// `zx_system_mexec_payload_get()` have not yet been appended to the
247    /// provided data ZBI.
248    ///
249    /// Returns
250    /// * ZX_ERR_BAD_STATE: The termination system state is not set to MEXEC.
251    pub fn r#get_mexec_zbis(
252        &self,
253    ) -> fidl::client::QueryResponseFut<
254        SystemStateTransitionGetMexecZbisResult,
255        fidl::encoding::DefaultFuchsiaResourceDialect,
256    > {
257        SystemStateTransitionProxyInterface::r#get_mexec_zbis(self)
258    }
259}
260
261impl SystemStateTransitionProxyInterface for SystemStateTransitionProxy {
262    type GetTerminationSystemStateResponseFut = fidl::client::QueryResponseFut<
263        SystemPowerState,
264        fidl::encoding::DefaultFuchsiaResourceDialect,
265    >;
266    fn r#get_termination_system_state(&self) -> Self::GetTerminationSystemStateResponseFut {
267        fn _decode(
268            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
269        ) -> Result<SystemPowerState, fidl::Error> {
270            let _response = fidl::client::decode_transaction_body::<
271                SystemStateTransitionGetTerminationSystemStateResponse,
272                fidl::encoding::DefaultFuchsiaResourceDialect,
273                0x7570e8c601c5e27e,
274            >(_buf?)?;
275            Ok(_response.state)
276        }
277        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SystemPowerState>(
278            (),
279            0x7570e8c601c5e27e,
280            fidl::encoding::DynamicFlags::empty(),
281            _decode,
282        )
283    }
284
285    type GetMexecZbisResponseFut = fidl::client::QueryResponseFut<
286        SystemStateTransitionGetMexecZbisResult,
287        fidl::encoding::DefaultFuchsiaResourceDialect,
288    >;
289    fn r#get_mexec_zbis(&self) -> Self::GetMexecZbisResponseFut {
290        fn _decode(
291            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
292        ) -> Result<SystemStateTransitionGetMexecZbisResult, fidl::Error> {
293            let _response = fidl::client::decode_transaction_body::<
294                fidl::encoding::ResultType<SystemStateTransitionGetMexecZbisResponse, i32>,
295                fidl::encoding::DefaultFuchsiaResourceDialect,
296                0x4d5efe452f310fef,
297            >(_buf?)?;
298            Ok(_response.map(|x| (x.kernel_zbi, x.data_zbi)))
299        }
300        self.client.send_query_and_decode::<
301            fidl::encoding::EmptyPayload,
302            SystemStateTransitionGetMexecZbisResult,
303        >(
304            (),
305            0x4d5efe452f310fef,
306            fidl::encoding::DynamicFlags::empty(),
307            _decode,
308        )
309    }
310}
311
312pub struct SystemStateTransitionEventStream {
313    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
314}
315
316impl std::marker::Unpin for SystemStateTransitionEventStream {}
317
318impl futures::stream::FusedStream for SystemStateTransitionEventStream {
319    fn is_terminated(&self) -> bool {
320        self.event_receiver.is_terminated()
321    }
322}
323
324impl futures::Stream for SystemStateTransitionEventStream {
325    type Item = Result<SystemStateTransitionEvent, fidl::Error>;
326
327    fn poll_next(
328        mut self: std::pin::Pin<&mut Self>,
329        cx: &mut std::task::Context<'_>,
330    ) -> std::task::Poll<Option<Self::Item>> {
331        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
332            &mut self.event_receiver,
333            cx
334        )?) {
335            Some(buf) => std::task::Poll::Ready(Some(SystemStateTransitionEvent::decode(buf))),
336            None => std::task::Poll::Ready(None),
337        }
338    }
339}
340
341#[derive(Debug)]
342pub enum SystemStateTransitionEvent {}
343
344impl SystemStateTransitionEvent {
345    /// Decodes a message buffer as a [`SystemStateTransitionEvent`].
346    fn decode(
347        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
348    ) -> Result<SystemStateTransitionEvent, fidl::Error> {
349        let (bytes, _handles) = buf.split_mut();
350        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
351        debug_assert_eq!(tx_header.tx_id, 0);
352        match tx_header.ordinal {
353            _ => Err(fidl::Error::UnknownOrdinal {
354                ordinal: tx_header.ordinal,
355                protocol_name:
356                    <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
357            }),
358        }
359    }
360}
361
362/// A Stream of incoming requests for fuchsia.system.state/SystemStateTransition.
363pub struct SystemStateTransitionRequestStream {
364    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
365    is_terminated: bool,
366}
367
368impl std::marker::Unpin for SystemStateTransitionRequestStream {}
369
370impl futures::stream::FusedStream for SystemStateTransitionRequestStream {
371    fn is_terminated(&self) -> bool {
372        self.is_terminated
373    }
374}
375
376impl fidl::endpoints::RequestStream for SystemStateTransitionRequestStream {
377    type Protocol = SystemStateTransitionMarker;
378    type ControlHandle = SystemStateTransitionControlHandle;
379
380    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
381        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
382    }
383
384    fn control_handle(&self) -> Self::ControlHandle {
385        SystemStateTransitionControlHandle { inner: self.inner.clone() }
386    }
387
388    fn into_inner(
389        self,
390    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
391    {
392        (self.inner, self.is_terminated)
393    }
394
395    fn from_inner(
396        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
397        is_terminated: bool,
398    ) -> Self {
399        Self { inner, is_terminated }
400    }
401}
402
403impl futures::Stream for SystemStateTransitionRequestStream {
404    type Item = Result<SystemStateTransitionRequest, fidl::Error>;
405
406    fn poll_next(
407        mut self: std::pin::Pin<&mut Self>,
408        cx: &mut std::task::Context<'_>,
409    ) -> std::task::Poll<Option<Self::Item>> {
410        let this = &mut *self;
411        if this.inner.check_shutdown(cx) {
412            this.is_terminated = true;
413            return std::task::Poll::Ready(None);
414        }
415        if this.is_terminated {
416            panic!("polled SystemStateTransitionRequestStream after completion");
417        }
418        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
419            |bytes, handles| {
420                match this.inner.channel().read_etc(cx, bytes, handles) {
421                    std::task::Poll::Ready(Ok(())) => {}
422                    std::task::Poll::Pending => return std::task::Poll::Pending,
423                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
424                        this.is_terminated = true;
425                        return std::task::Poll::Ready(None);
426                    }
427                    std::task::Poll::Ready(Err(e)) => {
428                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
429                            e.into(),
430                        ))))
431                    }
432                }
433
434                // A message has been received from the channel
435                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
436
437                std::task::Poll::Ready(Some(match header.ordinal {
438                0x7570e8c601c5e27e => {
439                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
440                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
441                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
442                    let control_handle = SystemStateTransitionControlHandle {
443                        inner: this.inner.clone(),
444                    };
445                    Ok(SystemStateTransitionRequest::GetTerminationSystemState {
446                        responder: SystemStateTransitionGetTerminationSystemStateResponder {
447                            control_handle: std::mem::ManuallyDrop::new(control_handle),
448                            tx_id: header.tx_id,
449                        },
450                    })
451                }
452                0x4d5efe452f310fef => {
453                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
454                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
455                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
456                    let control_handle = SystemStateTransitionControlHandle {
457                        inner: this.inner.clone(),
458                    };
459                    Ok(SystemStateTransitionRequest::GetMexecZbis {
460                        responder: SystemStateTransitionGetMexecZbisResponder {
461                            control_handle: std::mem::ManuallyDrop::new(control_handle),
462                            tx_id: header.tx_id,
463                        },
464                    })
465                }
466                _ => Err(fidl::Error::UnknownOrdinal {
467                    ordinal: header.ordinal,
468                    protocol_name: <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
469                }),
470            }))
471            },
472        )
473    }
474}
475
476/// Provides protocol for fetching relevant information during a system state transition.
477#[derive(Debug)]
478pub enum SystemStateTransitionRequest {
479    /// Gets the termination state.
480    GetTerminationSystemState { responder: SystemStateTransitionGetTerminationSystemStateResponder },
481    /// When the system termination state is MEXEC, in the course of shutting
482    /// down, driver_manager will perform an mexec itself after suspending all
483    /// drivers. This method allows driver manager to fetch the kernel and
484    /// data ZBIs to be passed to zx_system_mexec().
485    ///
486    /// This method only should only be invoked in the case MEXEC shutdown.
487    ///
488    /// It is expected that the ZBI items specified by
489    /// `zx_system_mexec_payload_get()` have not yet been appended to the
490    /// provided data ZBI.
491    ///
492    /// Returns
493    /// * ZX_ERR_BAD_STATE: The termination system state is not set to MEXEC.
494    GetMexecZbis { responder: SystemStateTransitionGetMexecZbisResponder },
495}
496
497impl SystemStateTransitionRequest {
498    #[allow(irrefutable_let_patterns)]
499    pub fn into_get_termination_system_state(
500        self,
501    ) -> Option<(SystemStateTransitionGetTerminationSystemStateResponder)> {
502        if let SystemStateTransitionRequest::GetTerminationSystemState { responder } = self {
503            Some((responder))
504        } else {
505            None
506        }
507    }
508
509    #[allow(irrefutable_let_patterns)]
510    pub fn into_get_mexec_zbis(self) -> Option<(SystemStateTransitionGetMexecZbisResponder)> {
511        if let SystemStateTransitionRequest::GetMexecZbis { responder } = self {
512            Some((responder))
513        } else {
514            None
515        }
516    }
517
518    /// Name of the method defined in FIDL
519    pub fn method_name(&self) -> &'static str {
520        match *self {
521            SystemStateTransitionRequest::GetTerminationSystemState { .. } => {
522                "get_termination_system_state"
523            }
524            SystemStateTransitionRequest::GetMexecZbis { .. } => "get_mexec_zbis",
525        }
526    }
527}
528
529#[derive(Debug, Clone)]
530pub struct SystemStateTransitionControlHandle {
531    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
532}
533
534impl fidl::endpoints::ControlHandle for SystemStateTransitionControlHandle {
535    fn shutdown(&self) {
536        self.inner.shutdown()
537    }
538    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
539        self.inner.shutdown_with_epitaph(status)
540    }
541
542    fn is_closed(&self) -> bool {
543        self.inner.channel().is_closed()
544    }
545    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
546        self.inner.channel().on_closed()
547    }
548
549    #[cfg(target_os = "fuchsia")]
550    fn signal_peer(
551        &self,
552        clear_mask: zx::Signals,
553        set_mask: zx::Signals,
554    ) -> Result<(), zx_status::Status> {
555        use fidl::Peered;
556        self.inner.channel().signal_peer(clear_mask, set_mask)
557    }
558}
559
560impl SystemStateTransitionControlHandle {}
561
562#[must_use = "FIDL methods require a response to be sent"]
563#[derive(Debug)]
564pub struct SystemStateTransitionGetTerminationSystemStateResponder {
565    control_handle: std::mem::ManuallyDrop<SystemStateTransitionControlHandle>,
566    tx_id: u32,
567}
568
569/// Set the the channel to be shutdown (see [`SystemStateTransitionControlHandle::shutdown`])
570/// if the responder is dropped without sending a response, so that the client
571/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
572impl std::ops::Drop for SystemStateTransitionGetTerminationSystemStateResponder {
573    fn drop(&mut self) {
574        self.control_handle.shutdown();
575        // Safety: drops once, never accessed again
576        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
577    }
578}
579
580impl fidl::endpoints::Responder for SystemStateTransitionGetTerminationSystemStateResponder {
581    type ControlHandle = SystemStateTransitionControlHandle;
582
583    fn control_handle(&self) -> &SystemStateTransitionControlHandle {
584        &self.control_handle
585    }
586
587    fn drop_without_shutdown(mut self) {
588        // Safety: drops once, never accessed again due to mem::forget
589        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
590        // Prevent Drop from running (which would shut down the channel)
591        std::mem::forget(self);
592    }
593}
594
595impl SystemStateTransitionGetTerminationSystemStateResponder {
596    /// Sends a response to the FIDL transaction.
597    ///
598    /// Sets the channel to shutdown if an error occurs.
599    pub fn send(self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
600        let _result = self.send_raw(state);
601        if _result.is_err() {
602            self.control_handle.shutdown();
603        }
604        self.drop_without_shutdown();
605        _result
606    }
607
608    /// Similar to "send" but does not shutdown the channel if an error occurs.
609    pub fn send_no_shutdown_on_err(self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
610        let _result = self.send_raw(state);
611        self.drop_without_shutdown();
612        _result
613    }
614
615    fn send_raw(&self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
616        self.control_handle.inner.send::<SystemStateTransitionGetTerminationSystemStateResponse>(
617            (state,),
618            self.tx_id,
619            0x7570e8c601c5e27e,
620            fidl::encoding::DynamicFlags::empty(),
621        )
622    }
623}
624
625#[must_use = "FIDL methods require a response to be sent"]
626#[derive(Debug)]
627pub struct SystemStateTransitionGetMexecZbisResponder {
628    control_handle: std::mem::ManuallyDrop<SystemStateTransitionControlHandle>,
629    tx_id: u32,
630}
631
632/// Set the the channel to be shutdown (see [`SystemStateTransitionControlHandle::shutdown`])
633/// if the responder is dropped without sending a response, so that the client
634/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
635impl std::ops::Drop for SystemStateTransitionGetMexecZbisResponder {
636    fn drop(&mut self) {
637        self.control_handle.shutdown();
638        // Safety: drops once, never accessed again
639        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
640    }
641}
642
643impl fidl::endpoints::Responder for SystemStateTransitionGetMexecZbisResponder {
644    type ControlHandle = SystemStateTransitionControlHandle;
645
646    fn control_handle(&self) -> &SystemStateTransitionControlHandle {
647        &self.control_handle
648    }
649
650    fn drop_without_shutdown(mut self) {
651        // Safety: drops once, never accessed again due to mem::forget
652        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
653        // Prevent Drop from running (which would shut down the channel)
654        std::mem::forget(self);
655    }
656}
657
658impl SystemStateTransitionGetMexecZbisResponder {
659    /// Sends a response to the FIDL transaction.
660    ///
661    /// Sets the channel to shutdown if an error occurs.
662    pub fn send(self, mut result: Result<(fidl::Vmo, fidl::Vmo), i32>) -> Result<(), fidl::Error> {
663        let _result = self.send_raw(result);
664        if _result.is_err() {
665            self.control_handle.shutdown();
666        }
667        self.drop_without_shutdown();
668        _result
669    }
670
671    /// Similar to "send" but does not shutdown the channel if an error occurs.
672    pub fn send_no_shutdown_on_err(
673        self,
674        mut result: Result<(fidl::Vmo, fidl::Vmo), i32>,
675    ) -> Result<(), fidl::Error> {
676        let _result = self.send_raw(result);
677        self.drop_without_shutdown();
678        _result
679    }
680
681    fn send_raw(&self, mut result: Result<(fidl::Vmo, fidl::Vmo), i32>) -> Result<(), fidl::Error> {
682        self.control_handle.inner.send::<fidl::encoding::ResultType<
683            SystemStateTransitionGetMexecZbisResponse,
684            i32,
685        >>(
686            result,
687            self.tx_id,
688            0x4d5efe452f310fef,
689            fidl::encoding::DynamicFlags::empty(),
690        )
691    }
692}
693
694mod internal {
695    use super::*;
696    unsafe impl fidl::encoding::TypeMarker for SystemPowerState {
697        type Owned = Self;
698
699        #[inline(always)]
700        fn inline_align(_context: fidl::encoding::Context) -> usize {
701            std::mem::align_of::<u8>()
702        }
703
704        #[inline(always)]
705        fn inline_size(_context: fidl::encoding::Context) -> usize {
706            std::mem::size_of::<u8>()
707        }
708
709        #[inline(always)]
710        fn encode_is_copy() -> bool {
711            true
712        }
713
714        #[inline(always)]
715        fn decode_is_copy() -> bool {
716            false
717        }
718    }
719
720    impl fidl::encoding::ValueTypeMarker for SystemPowerState {
721        type Borrowed<'a> = Self;
722        #[inline(always)]
723        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
724            *value
725        }
726    }
727
728    unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<Self, D>
729        for SystemPowerState
730    {
731        #[inline]
732        unsafe fn encode(
733            self,
734            encoder: &mut fidl::encoding::Encoder<'_, D>,
735            offset: usize,
736            _depth: fidl::encoding::Depth,
737        ) -> fidl::Result<()> {
738            encoder.debug_check_bounds::<Self>(offset);
739            encoder.write_num(self.into_primitive(), offset);
740            Ok(())
741        }
742    }
743
744    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for SystemPowerState {
745        #[inline(always)]
746        fn new_empty() -> Self {
747            Self::FullyOn
748        }
749
750        #[inline]
751        unsafe fn decode(
752            &mut self,
753            decoder: &mut fidl::encoding::Decoder<'_, D>,
754            offset: usize,
755            _depth: fidl::encoding::Depth,
756        ) -> fidl::Result<()> {
757            decoder.debug_check_bounds::<Self>(offset);
758            let prim = decoder.read_num::<u8>(offset);
759
760            *self = Self::from_primitive(prim).ok_or(fidl::Error::InvalidEnumValue)?;
761            Ok(())
762        }
763    }
764
765    impl fidl::encoding::ValueTypeMarker for SystemStateTransitionGetTerminationSystemStateResponse {
766        type Borrowed<'a> = &'a Self;
767        fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
768            value
769        }
770    }
771
772    unsafe impl fidl::encoding::TypeMarker for SystemStateTransitionGetTerminationSystemStateResponse {
773        type Owned = Self;
774
775        #[inline(always)]
776        fn inline_align(_context: fidl::encoding::Context) -> usize {
777            1
778        }
779
780        #[inline(always)]
781        fn inline_size(_context: fidl::encoding::Context) -> usize {
782            1
783        }
784    }
785
786    unsafe impl<D: fidl::encoding::ResourceDialect>
787        fidl::encoding::Encode<SystemStateTransitionGetTerminationSystemStateResponse, D>
788        for &SystemStateTransitionGetTerminationSystemStateResponse
789    {
790        #[inline]
791        unsafe fn encode(
792            self,
793            encoder: &mut fidl::encoding::Encoder<'_, D>,
794            offset: usize,
795            _depth: fidl::encoding::Depth,
796        ) -> fidl::Result<()> {
797            encoder.debug_check_bounds::<SystemStateTransitionGetTerminationSystemStateResponse>(
798                offset,
799            );
800            // Delegate to tuple encoding.
801            fidl::encoding::Encode::<SystemStateTransitionGetTerminationSystemStateResponse, D>::encode(
802                (
803                    <SystemPowerState as fidl::encoding::ValueTypeMarker>::borrow(&self.state),
804                ),
805                encoder, offset, _depth
806            )
807        }
808    }
809    unsafe impl<D: fidl::encoding::ResourceDialect, T0: fidl::encoding::Encode<SystemPowerState, D>>
810        fidl::encoding::Encode<SystemStateTransitionGetTerminationSystemStateResponse, D> for (T0,)
811    {
812        #[inline]
813        unsafe fn encode(
814            self,
815            encoder: &mut fidl::encoding::Encoder<'_, D>,
816            offset: usize,
817            depth: fidl::encoding::Depth,
818        ) -> fidl::Result<()> {
819            encoder.debug_check_bounds::<SystemStateTransitionGetTerminationSystemStateResponse>(
820                offset,
821            );
822            // Zero out padding regions. There's no need to apply masks
823            // because the unmasked parts will be overwritten by fields.
824            // Write the fields.
825            self.0.encode(encoder, offset + 0, depth)?;
826            Ok(())
827        }
828    }
829
830    impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
831        for SystemStateTransitionGetTerminationSystemStateResponse
832    {
833        #[inline(always)]
834        fn new_empty() -> Self {
835            Self { state: fidl::new_empty!(SystemPowerState, D) }
836        }
837
838        #[inline]
839        unsafe fn decode(
840            &mut self,
841            decoder: &mut fidl::encoding::Decoder<'_, D>,
842            offset: usize,
843            _depth: fidl::encoding::Depth,
844        ) -> fidl::Result<()> {
845            decoder.debug_check_bounds::<Self>(offset);
846            // Verify that padding bytes are zero.
847            fidl::decode!(SystemPowerState, D, &mut self.state, decoder, offset + 0, _depth)?;
848            Ok(())
849        }
850    }
851
852    impl fidl::encoding::ResourceTypeMarker for SystemStateTransitionGetMexecZbisResponse {
853        type Borrowed<'a> = &'a mut Self;
854        fn take_or_borrow<'a>(
855            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
856        ) -> Self::Borrowed<'a> {
857            value
858        }
859    }
860
861    unsafe impl fidl::encoding::TypeMarker for SystemStateTransitionGetMexecZbisResponse {
862        type Owned = Self;
863
864        #[inline(always)]
865        fn inline_align(_context: fidl::encoding::Context) -> usize {
866            4
867        }
868
869        #[inline(always)]
870        fn inline_size(_context: fidl::encoding::Context) -> usize {
871            8
872        }
873    }
874
875    unsafe impl
876        fidl::encoding::Encode<
877            SystemStateTransitionGetMexecZbisResponse,
878            fidl::encoding::DefaultFuchsiaResourceDialect,
879        > for &mut SystemStateTransitionGetMexecZbisResponse
880    {
881        #[inline]
882        unsafe fn encode(
883            self,
884            encoder: &mut fidl::encoding::Encoder<
885                '_,
886                fidl::encoding::DefaultFuchsiaResourceDialect,
887            >,
888            offset: usize,
889            _depth: fidl::encoding::Depth,
890        ) -> fidl::Result<()> {
891            encoder.debug_check_bounds::<SystemStateTransitionGetMexecZbisResponse>(offset);
892            // Delegate to tuple encoding.
893            fidl::encoding::Encode::<
894                SystemStateTransitionGetMexecZbisResponse,
895                fidl::encoding::DefaultFuchsiaResourceDialect,
896            >::encode(
897                (
898                    <fidl::encoding::HandleType<
899                        fidl::Vmo,
900                        { fidl::ObjectType::VMO.into_raw() },
901                        2147483648,
902                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
903                        &mut self.kernel_zbi
904                    ),
905                    <fidl::encoding::HandleType<
906                        fidl::Vmo,
907                        { fidl::ObjectType::VMO.into_raw() },
908                        2147483648,
909                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
910                        &mut self.data_zbi
911                    ),
912                ),
913                encoder,
914                offset,
915                _depth,
916            )
917        }
918    }
919    unsafe impl<
920            T0: fidl::encoding::Encode<
921                fidl::encoding::HandleType<
922                    fidl::Vmo,
923                    { fidl::ObjectType::VMO.into_raw() },
924                    2147483648,
925                >,
926                fidl::encoding::DefaultFuchsiaResourceDialect,
927            >,
928            T1: fidl::encoding::Encode<
929                fidl::encoding::HandleType<
930                    fidl::Vmo,
931                    { fidl::ObjectType::VMO.into_raw() },
932                    2147483648,
933                >,
934                fidl::encoding::DefaultFuchsiaResourceDialect,
935            >,
936        >
937        fidl::encoding::Encode<
938            SystemStateTransitionGetMexecZbisResponse,
939            fidl::encoding::DefaultFuchsiaResourceDialect,
940        > for (T0, T1)
941    {
942        #[inline]
943        unsafe fn encode(
944            self,
945            encoder: &mut fidl::encoding::Encoder<
946                '_,
947                fidl::encoding::DefaultFuchsiaResourceDialect,
948            >,
949            offset: usize,
950            depth: fidl::encoding::Depth,
951        ) -> fidl::Result<()> {
952            encoder.debug_check_bounds::<SystemStateTransitionGetMexecZbisResponse>(offset);
953            // Zero out padding regions. There's no need to apply masks
954            // because the unmasked parts will be overwritten by fields.
955            // Write the fields.
956            self.0.encode(encoder, offset + 0, depth)?;
957            self.1.encode(encoder, offset + 4, depth)?;
958            Ok(())
959        }
960    }
961
962    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
963        for SystemStateTransitionGetMexecZbisResponse
964    {
965        #[inline(always)]
966        fn new_empty() -> Self {
967            Self {
968                kernel_zbi: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
969                data_zbi: fidl::new_empty!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
970            }
971        }
972
973        #[inline]
974        unsafe fn decode(
975            &mut self,
976            decoder: &mut fidl::encoding::Decoder<
977                '_,
978                fidl::encoding::DefaultFuchsiaResourceDialect,
979            >,
980            offset: usize,
981            _depth: fidl::encoding::Depth,
982        ) -> fidl::Result<()> {
983            decoder.debug_check_bounds::<Self>(offset);
984            // Verify that padding bytes are zero.
985            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.kernel_zbi, decoder, offset + 0, _depth)?;
986            fidl::decode!(fidl::encoding::HandleType<fidl::Vmo, { fidl::ObjectType::VMO.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.data_zbi, decoder, offset + 4, _depth)?;
987            Ok(())
988        }
989    }
990}