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