Skip to main content

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 _};
10pub use fidl_fuchsia_system_state_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct SystemStateTransitionMarker;
16
17impl fidl::endpoints::ProtocolMarker for SystemStateTransitionMarker {
18    type Proxy = SystemStateTransitionProxy;
19    type RequestStream = SystemStateTransitionRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = SystemStateTransitionSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.system.state.SystemStateTransition";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for SystemStateTransitionMarker {}
26
27pub trait SystemStateTransitionProxyInterface: Send + Sync {
28    type GetTerminationSystemStateResponseFut: std::future::Future<Output = Result<SystemPowerState, fidl::Error>>
29        + Send;
30    fn r#get_termination_system_state(&self) -> Self::GetTerminationSystemStateResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct SystemStateTransitionSynchronousProxy {
35    client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for SystemStateTransitionSynchronousProxy {
40    type Proxy = SystemStateTransitionProxy;
41    type Protocol = SystemStateTransitionMarker;
42
43    fn from_channel(inner: fidl::Channel) -> Self {
44        Self::new(inner)
45    }
46
47    fn into_channel(self) -> fidl::Channel {
48        self.client.into_channel()
49    }
50
51    fn as_channel(&self) -> &fidl::Channel {
52        self.client.as_channel()
53    }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl SystemStateTransitionSynchronousProxy {
58    pub fn new(channel: fidl::Channel) -> Self {
59        Self { client: fidl::client::sync::Client::new(channel) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<SystemStateTransitionEvent, fidl::Error> {
72        SystemStateTransitionEvent::decode(
73            self.client.wait_for_event::<SystemStateTransitionMarker>(deadline)?,
74        )
75    }
76
77    /// Gets the termination state.
78    pub fn r#get_termination_system_state(
79        &self,
80        ___deadline: zx::MonotonicInstant,
81    ) -> Result<SystemPowerState, fidl::Error> {
82        let _response = self.client.send_query::<
83            fidl::encoding::EmptyPayload,
84            SystemStateTransitionGetTerminationSystemStateResponse,
85            SystemStateTransitionMarker,
86        >(
87            (),
88            0x7570e8c601c5e27e,
89            fidl::encoding::DynamicFlags::empty(),
90            ___deadline,
91        )?;
92        Ok(_response.state)
93    }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<SystemStateTransitionSynchronousProxy> for zx::NullableHandle {
98    fn from(value: SystemStateTransitionSynchronousProxy) -> Self {
99        value.into_channel().into()
100    }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for SystemStateTransitionSynchronousProxy {
105    fn from(value: fidl::Channel) -> Self {
106        Self::new(value)
107    }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for SystemStateTransitionSynchronousProxy {
112    type Protocol = SystemStateTransitionMarker;
113
114    fn from_client(value: fidl::endpoints::ClientEnd<SystemStateTransitionMarker>) -> Self {
115        Self::new(value.into_channel())
116    }
117}
118
119#[derive(Debug, Clone)]
120pub struct SystemStateTransitionProxy {
121    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for SystemStateTransitionProxy {
125    type Protocol = SystemStateTransitionMarker;
126
127    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128        Self::new(inner)
129    }
130
131    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132        self.client.into_channel().map_err(|client| Self { client })
133    }
134
135    fn as_channel(&self) -> &::fidl::AsyncChannel {
136        self.client.as_channel()
137    }
138}
139
140impl SystemStateTransitionProxy {
141    /// Create a new Proxy for fuchsia.system.state/SystemStateTransition.
142    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143        let protocol_name =
144            <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
145        Self { client: fidl::client::Client::new(channel, protocol_name) }
146    }
147
148    /// Get a Stream of events from the remote end of the protocol.
149    ///
150    /// # Panics
151    ///
152    /// Panics if the event stream was already taken.
153    pub fn take_event_stream(&self) -> SystemStateTransitionEventStream {
154        SystemStateTransitionEventStream { event_receiver: self.client.take_event_receiver() }
155    }
156
157    /// Gets the termination state.
158    pub fn r#get_termination_system_state(
159        &self,
160    ) -> fidl::client::QueryResponseFut<
161        SystemPowerState,
162        fidl::encoding::DefaultFuchsiaResourceDialect,
163    > {
164        SystemStateTransitionProxyInterface::r#get_termination_system_state(self)
165    }
166}
167
168impl SystemStateTransitionProxyInterface for SystemStateTransitionProxy {
169    type GetTerminationSystemStateResponseFut = fidl::client::QueryResponseFut<
170        SystemPowerState,
171        fidl::encoding::DefaultFuchsiaResourceDialect,
172    >;
173    fn r#get_termination_system_state(&self) -> Self::GetTerminationSystemStateResponseFut {
174        fn _decode(
175            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
176        ) -> Result<SystemPowerState, fidl::Error> {
177            let _response = fidl::client::decode_transaction_body::<
178                SystemStateTransitionGetTerminationSystemStateResponse,
179                fidl::encoding::DefaultFuchsiaResourceDialect,
180                0x7570e8c601c5e27e,
181            >(_buf?)?;
182            Ok(_response.state)
183        }
184        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, SystemPowerState>(
185            (),
186            0x7570e8c601c5e27e,
187            fidl::encoding::DynamicFlags::empty(),
188            _decode,
189        )
190    }
191}
192
193pub struct SystemStateTransitionEventStream {
194    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
195}
196
197impl std::marker::Unpin for SystemStateTransitionEventStream {}
198
199impl futures::stream::FusedStream for SystemStateTransitionEventStream {
200    fn is_terminated(&self) -> bool {
201        self.event_receiver.is_terminated()
202    }
203}
204
205impl futures::Stream for SystemStateTransitionEventStream {
206    type Item = Result<SystemStateTransitionEvent, fidl::Error>;
207
208    fn poll_next(
209        mut self: std::pin::Pin<&mut Self>,
210        cx: &mut std::task::Context<'_>,
211    ) -> std::task::Poll<Option<Self::Item>> {
212        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
213            &mut self.event_receiver,
214            cx
215        )?) {
216            Some(buf) => std::task::Poll::Ready(Some(SystemStateTransitionEvent::decode(buf))),
217            None => std::task::Poll::Ready(None),
218        }
219    }
220}
221
222#[derive(Debug)]
223pub enum SystemStateTransitionEvent {}
224
225impl SystemStateTransitionEvent {
226    /// Decodes a message buffer as a [`SystemStateTransitionEvent`].
227    fn decode(
228        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
229    ) -> Result<SystemStateTransitionEvent, fidl::Error> {
230        let (bytes, _handles) = buf.split_mut();
231        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
232        debug_assert_eq!(tx_header.tx_id, 0);
233        match tx_header.ordinal {
234            _ => Err(fidl::Error::UnknownOrdinal {
235                ordinal: tx_header.ordinal,
236                protocol_name:
237                    <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
238            }),
239        }
240    }
241}
242
243/// A Stream of incoming requests for fuchsia.system.state/SystemStateTransition.
244pub struct SystemStateTransitionRequestStream {
245    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
246    is_terminated: bool,
247}
248
249impl std::marker::Unpin for SystemStateTransitionRequestStream {}
250
251impl futures::stream::FusedStream for SystemStateTransitionRequestStream {
252    fn is_terminated(&self) -> bool {
253        self.is_terminated
254    }
255}
256
257impl fidl::endpoints::RequestStream for SystemStateTransitionRequestStream {
258    type Protocol = SystemStateTransitionMarker;
259    type ControlHandle = SystemStateTransitionControlHandle;
260
261    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
262        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
263    }
264
265    fn control_handle(&self) -> Self::ControlHandle {
266        SystemStateTransitionControlHandle { inner: self.inner.clone() }
267    }
268
269    fn into_inner(
270        self,
271    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
272    {
273        (self.inner, self.is_terminated)
274    }
275
276    fn from_inner(
277        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
278        is_terminated: bool,
279    ) -> Self {
280        Self { inner, is_terminated }
281    }
282}
283
284impl futures::Stream for SystemStateTransitionRequestStream {
285    type Item = Result<SystemStateTransitionRequest, fidl::Error>;
286
287    fn poll_next(
288        mut self: std::pin::Pin<&mut Self>,
289        cx: &mut std::task::Context<'_>,
290    ) -> std::task::Poll<Option<Self::Item>> {
291        let this = &mut *self;
292        if this.inner.check_shutdown(cx) {
293            this.is_terminated = true;
294            return std::task::Poll::Ready(None);
295        }
296        if this.is_terminated {
297            panic!("polled SystemStateTransitionRequestStream after completion");
298        }
299        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
300            |bytes, handles| {
301                match this.inner.channel().read_etc(cx, bytes, handles) {
302                    std::task::Poll::Ready(Ok(())) => {}
303                    std::task::Poll::Pending => return std::task::Poll::Pending,
304                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
305                        this.is_terminated = true;
306                        return std::task::Poll::Ready(None);
307                    }
308                    std::task::Poll::Ready(Err(e)) => {
309                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
310                            e.into(),
311                        ))));
312                    }
313                }
314
315                // A message has been received from the channel
316                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
317
318                std::task::Poll::Ready(Some(match header.ordinal {
319                0x7570e8c601c5e27e => {
320                    header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
321                    let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
322                    fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
323                    let control_handle = SystemStateTransitionControlHandle {
324                        inner: this.inner.clone(),
325                    };
326                    Ok(SystemStateTransitionRequest::GetTerminationSystemState {
327                        responder: SystemStateTransitionGetTerminationSystemStateResponder {
328                            control_handle: std::mem::ManuallyDrop::new(control_handle),
329                            tx_id: header.tx_id,
330                        },
331                    })
332                }
333                _ => Err(fidl::Error::UnknownOrdinal {
334                    ordinal: header.ordinal,
335                    protocol_name: <SystemStateTransitionMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
336                }),
337            }))
338            },
339        )
340    }
341}
342
343/// Provides protocol for fetching relevant information during a system state transition.
344#[derive(Debug)]
345pub enum SystemStateTransitionRequest {
346    /// Gets the termination state.
347    GetTerminationSystemState { responder: SystemStateTransitionGetTerminationSystemStateResponder },
348}
349
350impl SystemStateTransitionRequest {
351    #[allow(irrefutable_let_patterns)]
352    pub fn into_get_termination_system_state(
353        self,
354    ) -> Option<(SystemStateTransitionGetTerminationSystemStateResponder)> {
355        if let SystemStateTransitionRequest::GetTerminationSystemState { responder } = self {
356            Some((responder))
357        } else {
358            None
359        }
360    }
361
362    /// Name of the method defined in FIDL
363    pub fn method_name(&self) -> &'static str {
364        match *self {
365            SystemStateTransitionRequest::GetTerminationSystemState { .. } => {
366                "get_termination_system_state"
367            }
368        }
369    }
370}
371
372#[derive(Debug, Clone)]
373pub struct SystemStateTransitionControlHandle {
374    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
375}
376
377impl SystemStateTransitionControlHandle {
378    pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
379        self.inner.shutdown_with_epitaph(status.into())
380    }
381}
382
383impl fidl::endpoints::ControlHandle for SystemStateTransitionControlHandle {
384    fn shutdown(&self) {
385        self.inner.shutdown()
386    }
387
388    fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
389        self.inner.shutdown_with_epitaph(status)
390    }
391
392    fn is_closed(&self) -> bool {
393        self.inner.channel().is_closed()
394    }
395    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
396        self.inner.channel().on_closed()
397    }
398
399    #[cfg(target_os = "fuchsia")]
400    fn signal_peer(
401        &self,
402        clear_mask: zx::Signals,
403        set_mask: zx::Signals,
404    ) -> Result<(), zx_status::Status> {
405        use fidl::Peered;
406        self.inner.channel().signal_peer(clear_mask, set_mask)
407    }
408}
409
410impl SystemStateTransitionControlHandle {}
411
412#[must_use = "FIDL methods require a response to be sent"]
413#[derive(Debug)]
414pub struct SystemStateTransitionGetTerminationSystemStateResponder {
415    control_handle: std::mem::ManuallyDrop<SystemStateTransitionControlHandle>,
416    tx_id: u32,
417}
418
419/// Set the the channel to be shutdown (see [`SystemStateTransitionControlHandle::shutdown`])
420/// if the responder is dropped without sending a response, so that the client
421/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
422impl std::ops::Drop for SystemStateTransitionGetTerminationSystemStateResponder {
423    fn drop(&mut self) {
424        self.control_handle.shutdown();
425        // Safety: drops once, never accessed again
426        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
427    }
428}
429
430impl fidl::endpoints::Responder for SystemStateTransitionGetTerminationSystemStateResponder {
431    type ControlHandle = SystemStateTransitionControlHandle;
432
433    fn control_handle(&self) -> &SystemStateTransitionControlHandle {
434        &self.control_handle
435    }
436
437    fn drop_without_shutdown(mut self) {
438        // Safety: drops once, never accessed again due to mem::forget
439        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
440        // Prevent Drop from running (which would shut down the channel)
441        std::mem::forget(self);
442    }
443}
444
445impl SystemStateTransitionGetTerminationSystemStateResponder {
446    /// Sends a response to the FIDL transaction.
447    ///
448    /// Sets the channel to shutdown if an error occurs.
449    pub fn send(self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
450        let _result = self.send_raw(state);
451        if _result.is_err() {
452            self.control_handle.shutdown();
453        }
454        self.drop_without_shutdown();
455        _result
456    }
457
458    /// Similar to "send" but does not shutdown the channel if an error occurs.
459    pub fn send_no_shutdown_on_err(self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
460        let _result = self.send_raw(state);
461        self.drop_without_shutdown();
462        _result
463    }
464
465    fn send_raw(&self, mut state: SystemPowerState) -> Result<(), fidl::Error> {
466        self.control_handle.inner.send::<SystemStateTransitionGetTerminationSystemStateResponse>(
467            (state,),
468            self.tx_id,
469            0x7570e8c601c5e27e,
470            fidl::encoding::DynamicFlags::empty(),
471        )
472    }
473}
474
475mod internal {
476    use super::*;
477}