Skip to main content

fidl_test_sagcontrol/
fidl_test_sagcontrol.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_sagcontrol__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct StateMarker;
16
17impl fidl::endpoints::ProtocolMarker for StateMarker {
18    type Proxy = StateProxy;
19    type RequestStream = StateRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = StateSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "test.sagcontrol.State";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for StateMarker {}
26pub type StateSetResult = Result<(), SetSystemActivityGovernorStateError>;
27
28pub trait StateProxyInterface: Send + Sync {
29    type SetResponseFut: std::future::Future<Output = Result<StateSetResult, fidl::Error>> + Send;
30    fn r#set(&self, payload: &SystemActivityGovernorState) -> Self::SetResponseFut;
31    type GetResponseFut: std::future::Future<Output = Result<SystemActivityGovernorState, fidl::Error>>
32        + Send;
33    fn r#get(&self) -> Self::GetResponseFut;
34    type SetBootCompleteResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
35    fn r#set_boot_complete(&self) -> Self::SetBootCompleteResponseFut;
36    type WatchResponseFut: std::future::Future<Output = Result<SystemActivityGovernorState, fidl::Error>>
37        + Send;
38    fn r#watch(&self) -> Self::WatchResponseFut;
39}
40#[derive(Debug)]
41#[cfg(target_os = "fuchsia")]
42pub struct StateSynchronousProxy {
43    client: fidl::client::sync::Client,
44}
45
46#[cfg(target_os = "fuchsia")]
47impl fidl::endpoints::SynchronousProxy for StateSynchronousProxy {
48    type Proxy = StateProxy;
49    type Protocol = StateMarker;
50
51    fn from_channel(inner: fidl::Channel) -> Self {
52        Self::new(inner)
53    }
54
55    fn into_channel(self) -> fidl::Channel {
56        self.client.into_channel()
57    }
58
59    fn as_channel(&self) -> &fidl::Channel {
60        self.client.as_channel()
61    }
62}
63
64#[cfg(target_os = "fuchsia")]
65impl StateSynchronousProxy {
66    pub fn new(channel: fidl::Channel) -> Self {
67        Self { client: fidl::client::sync::Client::new(channel) }
68    }
69
70    pub fn into_channel(self) -> fidl::Channel {
71        self.client.into_channel()
72    }
73
74    /// Waits until an event arrives and returns it. It is safe for other
75    /// threads to make concurrent requests while waiting for an event.
76    pub fn wait_for_event(
77        &self,
78        deadline: zx::MonotonicInstant,
79    ) -> Result<StateEvent, fidl::Error> {
80        StateEvent::decode(self.client.wait_for_event::<StateMarker>(deadline)?)
81    }
82
83    /// Sets the power elements to specific states supported by SAG.
84    ///
85    /// The initial state of SAG is (2, 0). Boot complete logic is ignored in this protocol.
86    ///
87    /// In SystemActivityGovernorState, omitting specifying a power element's state will preserve
88    /// its existing state.
89    pub fn r#set(
90        &self,
91        mut payload: &SystemActivityGovernorState,
92        ___deadline: zx::MonotonicInstant,
93    ) -> Result<StateSetResult, fidl::Error> {
94        let _response =
95            self.client.send_query::<SystemActivityGovernorState, fidl::encoding::ResultType<
96                fidl::encoding::EmptyStruct,
97                SetSystemActivityGovernorStateError,
98            >, StateMarker>(
99                payload,
100                0x212842d46b8459f8,
101                fidl::encoding::DynamicFlags::empty(),
102                ___deadline,
103            )?;
104        Ok(_response.map(|x| x))
105    }
106
107    /// Return immediately with the current state of SAG.
108    pub fn r#get(
109        &self,
110        ___deadline: zx::MonotonicInstant,
111    ) -> Result<SystemActivityGovernorState, fidl::Error> {
112        let _response = self
113            .client
114            .send_query::<fidl::encoding::EmptyPayload, SystemActivityGovernorState, StateMarker>(
115                (),
116                0x65b19621b5644fdb,
117                fidl::encoding::DynamicFlags::empty(),
118                ___deadline,
119            )?;
120        Ok(_response)
121    }
122
123    /// Inform the Fake SAG to pass through the call and also change state.
124    pub fn r#set_boot_complete(
125        &self,
126        ___deadline: zx::MonotonicInstant,
127    ) -> Result<(), fidl::Error> {
128        let _response = self
129            .client
130            .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload, StateMarker>(
131                (),
132                0x7dded2028ad39365,
133                fidl::encoding::DynamicFlags::empty(),
134                ___deadline,
135            )?;
136        Ok(_response)
137    }
138
139    /// On a given connection, the first call will return immediately with SAG's
140    /// current state. Subsequent `Watch` requests will only
141    /// return if and only if a `test.sagcontrol.State.Set` call sends a request and SAG's
142    /// state has changed to the requested supported state.
143    ///
144    /// For example, if the current state of SAG is (1, 0), the first
145    /// `Watch` will return (1, 0). If a `test.sagcontrol.State.Set`
146    /// call sends a request to change state to (2, 1), the next `Watch`
147    /// will return when the SAG's state has fully transitioned to (2, 1),
148    /// any intermediate transient state (in this example, (2, 0),
149    /// will not be returned.
150    ///
151    /// Clients should use this to synchronize SAG states.
152    pub fn r#watch(
153        &self,
154        ___deadline: zx::MonotonicInstant,
155    ) -> Result<SystemActivityGovernorState, fidl::Error> {
156        let _response = self
157            .client
158            .send_query::<fidl::encoding::EmptyPayload, SystemActivityGovernorState, StateMarker>(
159                (),
160                0x434b0aa4bbac7965,
161                fidl::encoding::DynamicFlags::empty(),
162                ___deadline,
163            )?;
164        Ok(_response)
165    }
166}
167
168#[cfg(target_os = "fuchsia")]
169impl From<StateSynchronousProxy> for zx::NullableHandle {
170    fn from(value: StateSynchronousProxy) -> Self {
171        value.into_channel().into()
172    }
173}
174
175#[cfg(target_os = "fuchsia")]
176impl From<fidl::Channel> for StateSynchronousProxy {
177    fn from(value: fidl::Channel) -> Self {
178        Self::new(value)
179    }
180}
181
182#[cfg(target_os = "fuchsia")]
183impl fidl::endpoints::FromClient for StateSynchronousProxy {
184    type Protocol = StateMarker;
185
186    fn from_client(value: fidl::endpoints::ClientEnd<StateMarker>) -> Self {
187        Self::new(value.into_channel())
188    }
189}
190
191#[derive(Debug, Clone)]
192pub struct StateProxy {
193    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
194}
195
196impl fidl::endpoints::Proxy for StateProxy {
197    type Protocol = StateMarker;
198
199    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
200        Self::new(inner)
201    }
202
203    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
204        self.client.into_channel().map_err(|client| Self { client })
205    }
206
207    fn as_channel(&self) -> &::fidl::AsyncChannel {
208        self.client.as_channel()
209    }
210}
211
212impl StateProxy {
213    /// Create a new Proxy for test.sagcontrol/State.
214    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
215        let protocol_name = <StateMarker 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) -> StateEventStream {
225        StateEventStream { event_receiver: self.client.take_event_receiver() }
226    }
227
228    /// Sets the power elements to specific states supported by SAG.
229    ///
230    /// The initial state of SAG is (2, 0). Boot complete logic is ignored in this protocol.
231    ///
232    /// In SystemActivityGovernorState, omitting specifying a power element's state will preserve
233    /// its existing state.
234    pub fn r#set(
235        &self,
236        mut payload: &SystemActivityGovernorState,
237    ) -> fidl::client::QueryResponseFut<StateSetResult, fidl::encoding::DefaultFuchsiaResourceDialect>
238    {
239        StateProxyInterface::r#set(self, payload)
240    }
241
242    /// Return immediately with the current state of SAG.
243    pub fn r#get(
244        &self,
245    ) -> fidl::client::QueryResponseFut<
246        SystemActivityGovernorState,
247        fidl::encoding::DefaultFuchsiaResourceDialect,
248    > {
249        StateProxyInterface::r#get(self)
250    }
251
252    /// Inform the Fake SAG to pass through the call and also change state.
253    pub fn r#set_boot_complete(
254        &self,
255    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
256        StateProxyInterface::r#set_boot_complete(self)
257    }
258
259    /// On a given connection, the first call will return immediately with SAG's
260    /// current state. Subsequent `Watch` requests will only
261    /// return if and only if a `test.sagcontrol.State.Set` call sends a request and SAG's
262    /// state has changed to the requested supported state.
263    ///
264    /// For example, if the current state of SAG is (1, 0), the first
265    /// `Watch` will return (1, 0). If a `test.sagcontrol.State.Set`
266    /// call sends a request to change state to (2, 1), the next `Watch`
267    /// will return when the SAG's state has fully transitioned to (2, 1),
268    /// any intermediate transient state (in this example, (2, 0),
269    /// will not be returned.
270    ///
271    /// Clients should use this to synchronize SAG states.
272    pub fn r#watch(
273        &self,
274    ) -> fidl::client::QueryResponseFut<
275        SystemActivityGovernorState,
276        fidl::encoding::DefaultFuchsiaResourceDialect,
277    > {
278        StateProxyInterface::r#watch(self)
279    }
280}
281
282impl StateProxyInterface for StateProxy {
283    type SetResponseFut = fidl::client::QueryResponseFut<
284        StateSetResult,
285        fidl::encoding::DefaultFuchsiaResourceDialect,
286    >;
287    fn r#set(&self, mut payload: &SystemActivityGovernorState) -> Self::SetResponseFut {
288        fn _decode(
289            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
290        ) -> Result<StateSetResult, fidl::Error> {
291            let _response = fidl::client::decode_transaction_body::<
292                fidl::encoding::ResultType<
293                    fidl::encoding::EmptyStruct,
294                    SetSystemActivityGovernorStateError,
295                >,
296                fidl::encoding::DefaultFuchsiaResourceDialect,
297                0x212842d46b8459f8,
298            >(_buf?)?;
299            Ok(_response.map(|x| x))
300        }
301        self.client.send_query_and_decode::<SystemActivityGovernorState, StateSetResult>(
302            payload,
303            0x212842d46b8459f8,
304            fidl::encoding::DynamicFlags::empty(),
305            _decode,
306        )
307    }
308
309    type GetResponseFut = fidl::client::QueryResponseFut<
310        SystemActivityGovernorState,
311        fidl::encoding::DefaultFuchsiaResourceDialect,
312    >;
313    fn r#get(&self) -> Self::GetResponseFut {
314        fn _decode(
315            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
316        ) -> Result<SystemActivityGovernorState, fidl::Error> {
317            let _response = fidl::client::decode_transaction_body::<
318                SystemActivityGovernorState,
319                fidl::encoding::DefaultFuchsiaResourceDialect,
320                0x65b19621b5644fdb,
321            >(_buf?)?;
322            Ok(_response)
323        }
324        self.client
325            .send_query_and_decode::<fidl::encoding::EmptyPayload, SystemActivityGovernorState>(
326                (),
327                0x65b19621b5644fdb,
328                fidl::encoding::DynamicFlags::empty(),
329                _decode,
330            )
331    }
332
333    type SetBootCompleteResponseFut =
334        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
335    fn r#set_boot_complete(&self) -> Self::SetBootCompleteResponseFut {
336        fn _decode(
337            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
338        ) -> Result<(), fidl::Error> {
339            let _response = fidl::client::decode_transaction_body::<
340                fidl::encoding::EmptyPayload,
341                fidl::encoding::DefaultFuchsiaResourceDialect,
342                0x7dded2028ad39365,
343            >(_buf?)?;
344            Ok(_response)
345        }
346        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
347            (),
348            0x7dded2028ad39365,
349            fidl::encoding::DynamicFlags::empty(),
350            _decode,
351        )
352    }
353
354    type WatchResponseFut = fidl::client::QueryResponseFut<
355        SystemActivityGovernorState,
356        fidl::encoding::DefaultFuchsiaResourceDialect,
357    >;
358    fn r#watch(&self) -> Self::WatchResponseFut {
359        fn _decode(
360            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
361        ) -> Result<SystemActivityGovernorState, fidl::Error> {
362            let _response = fidl::client::decode_transaction_body::<
363                SystemActivityGovernorState,
364                fidl::encoding::DefaultFuchsiaResourceDialect,
365                0x434b0aa4bbac7965,
366            >(_buf?)?;
367            Ok(_response)
368        }
369        self.client
370            .send_query_and_decode::<fidl::encoding::EmptyPayload, SystemActivityGovernorState>(
371                (),
372                0x434b0aa4bbac7965,
373                fidl::encoding::DynamicFlags::empty(),
374                _decode,
375            )
376    }
377}
378
379pub struct StateEventStream {
380    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
381}
382
383impl std::marker::Unpin for StateEventStream {}
384
385impl futures::stream::FusedStream for StateEventStream {
386    fn is_terminated(&self) -> bool {
387        self.event_receiver.is_terminated()
388    }
389}
390
391impl futures::Stream for StateEventStream {
392    type Item = Result<StateEvent, fidl::Error>;
393
394    fn poll_next(
395        mut self: std::pin::Pin<&mut Self>,
396        cx: &mut std::task::Context<'_>,
397    ) -> std::task::Poll<Option<Self::Item>> {
398        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
399            &mut self.event_receiver,
400            cx
401        )?) {
402            Some(buf) => std::task::Poll::Ready(Some(StateEvent::decode(buf))),
403            None => std::task::Poll::Ready(None),
404        }
405    }
406}
407
408#[derive(Debug)]
409pub enum StateEvent {
410    #[non_exhaustive]
411    _UnknownEvent {
412        /// Ordinal of the event that was sent.
413        ordinal: u64,
414    },
415}
416
417impl StateEvent {
418    /// Decodes a message buffer as a [`StateEvent`].
419    fn decode(
420        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
421    ) -> Result<StateEvent, fidl::Error> {
422        let (bytes, _handles) = buf.split_mut();
423        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
424        debug_assert_eq!(tx_header.tx_id, 0);
425        match tx_header.ordinal {
426            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
427                Ok(StateEvent::_UnknownEvent { ordinal: tx_header.ordinal })
428            }
429            _ => Err(fidl::Error::UnknownOrdinal {
430                ordinal: tx_header.ordinal,
431                protocol_name: <StateMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
432            }),
433        }
434    }
435}
436
437/// A Stream of incoming requests for test.sagcontrol/State.
438pub struct StateRequestStream {
439    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
440    is_terminated: bool,
441}
442
443impl std::marker::Unpin for StateRequestStream {}
444
445impl futures::stream::FusedStream for StateRequestStream {
446    fn is_terminated(&self) -> bool {
447        self.is_terminated
448    }
449}
450
451impl fidl::endpoints::RequestStream for StateRequestStream {
452    type Protocol = StateMarker;
453    type ControlHandle = StateControlHandle;
454
455    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
456        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
457    }
458
459    fn control_handle(&self) -> Self::ControlHandle {
460        StateControlHandle { inner: self.inner.clone() }
461    }
462
463    fn into_inner(
464        self,
465    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
466    {
467        (self.inner, self.is_terminated)
468    }
469
470    fn from_inner(
471        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
472        is_terminated: bool,
473    ) -> Self {
474        Self { inner, is_terminated }
475    }
476}
477
478impl futures::Stream for StateRequestStream {
479    type Item = Result<StateRequest, fidl::Error>;
480
481    fn poll_next(
482        mut self: std::pin::Pin<&mut Self>,
483        cx: &mut std::task::Context<'_>,
484    ) -> std::task::Poll<Option<Self::Item>> {
485        let this = &mut *self;
486        if this.inner.check_shutdown(cx) {
487            this.is_terminated = true;
488            return std::task::Poll::Ready(None);
489        }
490        if this.is_terminated {
491            panic!("polled StateRequestStream after completion");
492        }
493        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
494            |bytes, handles| {
495                match this.inner.channel().read_etc(cx, bytes, handles) {
496                    std::task::Poll::Ready(Ok(())) => {}
497                    std::task::Poll::Pending => return std::task::Poll::Pending,
498                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
499                        this.is_terminated = true;
500                        return std::task::Poll::Ready(None);
501                    }
502                    std::task::Poll::Ready(Err(e)) => {
503                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
504                            e.into(),
505                        ))));
506                    }
507                }
508
509                // A message has been received from the channel
510                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
511
512                std::task::Poll::Ready(Some(match header.ordinal {
513                    0x212842d46b8459f8 => {
514                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
515                        let mut req = fidl::new_empty!(
516                            SystemActivityGovernorState,
517                            fidl::encoding::DefaultFuchsiaResourceDialect
518                        );
519                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SystemActivityGovernorState>(&header, _body_bytes, handles, &mut req)?;
520                        let control_handle = StateControlHandle { inner: this.inner.clone() };
521                        Ok(StateRequest::Set {
522                            payload: req,
523                            responder: StateSetResponder {
524                                control_handle: std::mem::ManuallyDrop::new(control_handle),
525                                tx_id: header.tx_id,
526                            },
527                        })
528                    }
529                    0x65b19621b5644fdb => {
530                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
531                        let mut req = fidl::new_empty!(
532                            fidl::encoding::EmptyPayload,
533                            fidl::encoding::DefaultFuchsiaResourceDialect
534                        );
535                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
536                        let control_handle = StateControlHandle { inner: this.inner.clone() };
537                        Ok(StateRequest::Get {
538                            responder: StateGetResponder {
539                                control_handle: std::mem::ManuallyDrop::new(control_handle),
540                                tx_id: header.tx_id,
541                            },
542                        })
543                    }
544                    0x7dded2028ad39365 => {
545                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
546                        let mut req = fidl::new_empty!(
547                            fidl::encoding::EmptyPayload,
548                            fidl::encoding::DefaultFuchsiaResourceDialect
549                        );
550                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
551                        let control_handle = StateControlHandle { inner: this.inner.clone() };
552                        Ok(StateRequest::SetBootComplete {
553                            responder: StateSetBootCompleteResponder {
554                                control_handle: std::mem::ManuallyDrop::new(control_handle),
555                                tx_id: header.tx_id,
556                            },
557                        })
558                    }
559                    0x434b0aa4bbac7965 => {
560                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
561                        let mut req = fidl::new_empty!(
562                            fidl::encoding::EmptyPayload,
563                            fidl::encoding::DefaultFuchsiaResourceDialect
564                        );
565                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
566                        let control_handle = StateControlHandle { inner: this.inner.clone() };
567                        Ok(StateRequest::Watch {
568                            responder: StateWatchResponder {
569                                control_handle: std::mem::ManuallyDrop::new(control_handle),
570                                tx_id: header.tx_id,
571                            },
572                        })
573                    }
574                    _ if header.tx_id == 0
575                        && header
576                            .dynamic_flags()
577                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
578                    {
579                        Ok(StateRequest::_UnknownMethod {
580                            ordinal: header.ordinal,
581                            control_handle: StateControlHandle { inner: this.inner.clone() },
582                            method_type: fidl::MethodType::OneWay,
583                        })
584                    }
585                    _ if header
586                        .dynamic_flags()
587                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
588                    {
589                        this.inner.send_framework_err(
590                            fidl::encoding::FrameworkErr::UnknownMethod,
591                            header.tx_id,
592                            header.ordinal,
593                            header.dynamic_flags(),
594                            (bytes, handles),
595                        )?;
596                        Ok(StateRequest::_UnknownMethod {
597                            ordinal: header.ordinal,
598                            control_handle: StateControlHandle { inner: this.inner.clone() },
599                            method_type: fidl::MethodType::TwoWay,
600                        })
601                    }
602                    _ => Err(fidl::Error::UnknownOrdinal {
603                        ordinal: header.ordinal,
604                        protocol_name: <StateMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
605                    }),
606                }))
607            },
608        )
609    }
610}
611
612#[derive(Debug)]
613pub enum StateRequest {
614    /// Sets the power elements to specific states supported by SAG.
615    ///
616    /// The initial state of SAG is (2, 0). Boot complete logic is ignored in this protocol.
617    ///
618    /// In SystemActivityGovernorState, omitting specifying a power element's state will preserve
619    /// its existing state.
620    Set { payload: SystemActivityGovernorState, responder: StateSetResponder },
621    /// Return immediately with the current state of SAG.
622    Get { responder: StateGetResponder },
623    /// Inform the Fake SAG to pass through the call and also change state.
624    SetBootComplete { responder: StateSetBootCompleteResponder },
625    /// On a given connection, the first call will return immediately with SAG's
626    /// current state. Subsequent `Watch` requests will only
627    /// return if and only if a `test.sagcontrol.State.Set` call sends a request and SAG's
628    /// state has changed to the requested supported state.
629    ///
630    /// For example, if the current state of SAG is (1, 0), the first
631    /// `Watch` will return (1, 0). If a `test.sagcontrol.State.Set`
632    /// call sends a request to change state to (2, 1), the next `Watch`
633    /// will return when the SAG's state has fully transitioned to (2, 1),
634    /// any intermediate transient state (in this example, (2, 0),
635    /// will not be returned.
636    ///
637    /// Clients should use this to synchronize SAG states.
638    Watch { responder: StateWatchResponder },
639    /// An interaction was received which does not match any known method.
640    #[non_exhaustive]
641    _UnknownMethod {
642        /// Ordinal of the method that was called.
643        ordinal: u64,
644        control_handle: StateControlHandle,
645        method_type: fidl::MethodType,
646    },
647}
648
649impl StateRequest {
650    #[allow(irrefutable_let_patterns)]
651    pub fn into_set(self) -> Option<(SystemActivityGovernorState, StateSetResponder)> {
652        if let StateRequest::Set { payload, responder } = self {
653            Some((payload, responder))
654        } else {
655            None
656        }
657    }
658
659    #[allow(irrefutable_let_patterns)]
660    pub fn into_get(self) -> Option<(StateGetResponder)> {
661        if let StateRequest::Get { responder } = self { Some((responder)) } else { None }
662    }
663
664    #[allow(irrefutable_let_patterns)]
665    pub fn into_set_boot_complete(self) -> Option<(StateSetBootCompleteResponder)> {
666        if let StateRequest::SetBootComplete { responder } = self {
667            Some((responder))
668        } else {
669            None
670        }
671    }
672
673    #[allow(irrefutable_let_patterns)]
674    pub fn into_watch(self) -> Option<(StateWatchResponder)> {
675        if let StateRequest::Watch { responder } = self { Some((responder)) } else { None }
676    }
677
678    /// Name of the method defined in FIDL
679    pub fn method_name(&self) -> &'static str {
680        match *self {
681            StateRequest::Set { .. } => "set",
682            StateRequest::Get { .. } => "get",
683            StateRequest::SetBootComplete { .. } => "set_boot_complete",
684            StateRequest::Watch { .. } => "watch",
685            StateRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
686                "unknown one-way method"
687            }
688            StateRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
689                "unknown two-way method"
690            }
691        }
692    }
693}
694
695#[derive(Debug, Clone)]
696pub struct StateControlHandle {
697    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
698}
699
700impl fidl::endpoints::ControlHandle for StateControlHandle {
701    fn shutdown(&self) {
702        self.inner.shutdown()
703    }
704
705    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
706        self.inner.shutdown_with_epitaph(status)
707    }
708
709    fn is_closed(&self) -> bool {
710        self.inner.channel().is_closed()
711    }
712    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
713        self.inner.channel().on_closed()
714    }
715
716    #[cfg(target_os = "fuchsia")]
717    fn signal_peer(
718        &self,
719        clear_mask: zx::Signals,
720        set_mask: zx::Signals,
721    ) -> Result<(), zx_status::Status> {
722        use fidl::Peered;
723        self.inner.channel().signal_peer(clear_mask, set_mask)
724    }
725}
726
727impl StateControlHandle {}
728
729#[must_use = "FIDL methods require a response to be sent"]
730#[derive(Debug)]
731pub struct StateSetResponder {
732    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
733    tx_id: u32,
734}
735
736/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
737/// if the responder is dropped without sending a response, so that the client
738/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
739impl std::ops::Drop for StateSetResponder {
740    fn drop(&mut self) {
741        self.control_handle.shutdown();
742        // Safety: drops once, never accessed again
743        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
744    }
745}
746
747impl fidl::endpoints::Responder for StateSetResponder {
748    type ControlHandle = StateControlHandle;
749
750    fn control_handle(&self) -> &StateControlHandle {
751        &self.control_handle
752    }
753
754    fn drop_without_shutdown(mut self) {
755        // Safety: drops once, never accessed again due to mem::forget
756        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
757        // Prevent Drop from running (which would shut down the channel)
758        std::mem::forget(self);
759    }
760}
761
762impl StateSetResponder {
763    /// Sends a response to the FIDL transaction.
764    ///
765    /// Sets the channel to shutdown if an error occurs.
766    pub fn send(
767        self,
768        mut result: Result<(), SetSystemActivityGovernorStateError>,
769    ) -> Result<(), fidl::Error> {
770        let _result = self.send_raw(result);
771        if _result.is_err() {
772            self.control_handle.shutdown();
773        }
774        self.drop_without_shutdown();
775        _result
776    }
777
778    /// Similar to "send" but does not shutdown the channel if an error occurs.
779    pub fn send_no_shutdown_on_err(
780        self,
781        mut result: Result<(), SetSystemActivityGovernorStateError>,
782    ) -> Result<(), fidl::Error> {
783        let _result = self.send_raw(result);
784        self.drop_without_shutdown();
785        _result
786    }
787
788    fn send_raw(
789        &self,
790        mut result: Result<(), SetSystemActivityGovernorStateError>,
791    ) -> Result<(), fidl::Error> {
792        self.control_handle.inner.send::<fidl::encoding::ResultType<
793            fidl::encoding::EmptyStruct,
794            SetSystemActivityGovernorStateError,
795        >>(
796            result,
797            self.tx_id,
798            0x212842d46b8459f8,
799            fidl::encoding::DynamicFlags::empty(),
800        )
801    }
802}
803
804#[must_use = "FIDL methods require a response to be sent"]
805#[derive(Debug)]
806pub struct StateGetResponder {
807    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
808    tx_id: u32,
809}
810
811/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
812/// if the responder is dropped without sending a response, so that the client
813/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
814impl std::ops::Drop for StateGetResponder {
815    fn drop(&mut self) {
816        self.control_handle.shutdown();
817        // Safety: drops once, never accessed again
818        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
819    }
820}
821
822impl fidl::endpoints::Responder for StateGetResponder {
823    type ControlHandle = StateControlHandle;
824
825    fn control_handle(&self) -> &StateControlHandle {
826        &self.control_handle
827    }
828
829    fn drop_without_shutdown(mut self) {
830        // Safety: drops once, never accessed again due to mem::forget
831        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
832        // Prevent Drop from running (which would shut down the channel)
833        std::mem::forget(self);
834    }
835}
836
837impl StateGetResponder {
838    /// Sends a response to the FIDL transaction.
839    ///
840    /// Sets the channel to shutdown if an error occurs.
841    pub fn send(self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
842        let _result = self.send_raw(payload);
843        if _result.is_err() {
844            self.control_handle.shutdown();
845        }
846        self.drop_without_shutdown();
847        _result
848    }
849
850    /// Similar to "send" but does not shutdown the channel if an error occurs.
851    pub fn send_no_shutdown_on_err(
852        self,
853        mut payload: &SystemActivityGovernorState,
854    ) -> Result<(), fidl::Error> {
855        let _result = self.send_raw(payload);
856        self.drop_without_shutdown();
857        _result
858    }
859
860    fn send_raw(&self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
861        self.control_handle.inner.send::<SystemActivityGovernorState>(
862            payload,
863            self.tx_id,
864            0x65b19621b5644fdb,
865            fidl::encoding::DynamicFlags::empty(),
866        )
867    }
868}
869
870#[must_use = "FIDL methods require a response to be sent"]
871#[derive(Debug)]
872pub struct StateSetBootCompleteResponder {
873    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
874    tx_id: u32,
875}
876
877/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
878/// if the responder is dropped without sending a response, so that the client
879/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
880impl std::ops::Drop for StateSetBootCompleteResponder {
881    fn drop(&mut self) {
882        self.control_handle.shutdown();
883        // Safety: drops once, never accessed again
884        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
885    }
886}
887
888impl fidl::endpoints::Responder for StateSetBootCompleteResponder {
889    type ControlHandle = StateControlHandle;
890
891    fn control_handle(&self) -> &StateControlHandle {
892        &self.control_handle
893    }
894
895    fn drop_without_shutdown(mut self) {
896        // Safety: drops once, never accessed again due to mem::forget
897        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
898        // Prevent Drop from running (which would shut down the channel)
899        std::mem::forget(self);
900    }
901}
902
903impl StateSetBootCompleteResponder {
904    /// Sends a response to the FIDL transaction.
905    ///
906    /// Sets the channel to shutdown if an error occurs.
907    pub fn send(self) -> Result<(), fidl::Error> {
908        let _result = self.send_raw();
909        if _result.is_err() {
910            self.control_handle.shutdown();
911        }
912        self.drop_without_shutdown();
913        _result
914    }
915
916    /// Similar to "send" but does not shutdown the channel if an error occurs.
917    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
918        let _result = self.send_raw();
919        self.drop_without_shutdown();
920        _result
921    }
922
923    fn send_raw(&self) -> Result<(), fidl::Error> {
924        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
925            (),
926            self.tx_id,
927            0x7dded2028ad39365,
928            fidl::encoding::DynamicFlags::empty(),
929        )
930    }
931}
932
933#[must_use = "FIDL methods require a response to be sent"]
934#[derive(Debug)]
935pub struct StateWatchResponder {
936    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
937    tx_id: u32,
938}
939
940/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
941/// if the responder is dropped without sending a response, so that the client
942/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
943impl std::ops::Drop for StateWatchResponder {
944    fn drop(&mut self) {
945        self.control_handle.shutdown();
946        // Safety: drops once, never accessed again
947        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
948    }
949}
950
951impl fidl::endpoints::Responder for StateWatchResponder {
952    type ControlHandle = StateControlHandle;
953
954    fn control_handle(&self) -> &StateControlHandle {
955        &self.control_handle
956    }
957
958    fn drop_without_shutdown(mut self) {
959        // Safety: drops once, never accessed again due to mem::forget
960        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
961        // Prevent Drop from running (which would shut down the channel)
962        std::mem::forget(self);
963    }
964}
965
966impl StateWatchResponder {
967    /// Sends a response to the FIDL transaction.
968    ///
969    /// Sets the channel to shutdown if an error occurs.
970    pub fn send(self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
971        let _result = self.send_raw(payload);
972        if _result.is_err() {
973            self.control_handle.shutdown();
974        }
975        self.drop_without_shutdown();
976        _result
977    }
978
979    /// Similar to "send" but does not shutdown the channel if an error occurs.
980    pub fn send_no_shutdown_on_err(
981        self,
982        mut payload: &SystemActivityGovernorState,
983    ) -> Result<(), fidl::Error> {
984        let _result = self.send_raw(payload);
985        self.drop_without_shutdown();
986        _result
987    }
988
989    fn send_raw(&self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
990        self.control_handle.inner.send::<SystemActivityGovernorState>(
991            payload,
992            self.tx_id,
993            0x434b0aa4bbac7965,
994            fidl::encoding::DynamicFlags::empty(),
995        )
996    }
997}
998
999mod internal {
1000    use super::*;
1001}