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 {
658            Some((responder))
659        } else {
660            None
661        }
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 {
676            Some((responder))
677        } else {
678            None
679        }
680    }
681
682    /// Name of the method defined in FIDL
683    pub fn method_name(&self) -> &'static str {
684        match *self {
685            StateRequest::Set { .. } => "set",
686            StateRequest::Get { .. } => "get",
687            StateRequest::SetBootComplete { .. } => "set_boot_complete",
688            StateRequest::Watch { .. } => "watch",
689            StateRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
690                "unknown one-way method"
691            }
692            StateRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
693                "unknown two-way method"
694            }
695        }
696    }
697}
698
699#[derive(Debug, Clone)]
700pub struct StateControlHandle {
701    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
702}
703
704impl fidl::endpoints::ControlHandle for StateControlHandle {
705    fn shutdown(&self) {
706        self.inner.shutdown()
707    }
708    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
709        self.inner.shutdown_with_epitaph(status)
710    }
711
712    fn is_closed(&self) -> bool {
713        self.inner.channel().is_closed()
714    }
715    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
716        self.inner.channel().on_closed()
717    }
718
719    #[cfg(target_os = "fuchsia")]
720    fn signal_peer(
721        &self,
722        clear_mask: zx::Signals,
723        set_mask: zx::Signals,
724    ) -> Result<(), zx_status::Status> {
725        use fidl::Peered;
726        self.inner.channel().signal_peer(clear_mask, set_mask)
727    }
728}
729
730impl StateControlHandle {}
731
732#[must_use = "FIDL methods require a response to be sent"]
733#[derive(Debug)]
734pub struct StateSetResponder {
735    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
736    tx_id: u32,
737}
738
739/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
740/// if the responder is dropped without sending a response, so that the client
741/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
742impl std::ops::Drop for StateSetResponder {
743    fn drop(&mut self) {
744        self.control_handle.shutdown();
745        // Safety: drops once, never accessed again
746        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
747    }
748}
749
750impl fidl::endpoints::Responder for StateSetResponder {
751    type ControlHandle = StateControlHandle;
752
753    fn control_handle(&self) -> &StateControlHandle {
754        &self.control_handle
755    }
756
757    fn drop_without_shutdown(mut self) {
758        // Safety: drops once, never accessed again due to mem::forget
759        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
760        // Prevent Drop from running (which would shut down the channel)
761        std::mem::forget(self);
762    }
763}
764
765impl StateSetResponder {
766    /// Sends a response to the FIDL transaction.
767    ///
768    /// Sets the channel to shutdown if an error occurs.
769    pub fn send(
770        self,
771        mut result: Result<(), SetSystemActivityGovernorStateError>,
772    ) -> Result<(), fidl::Error> {
773        let _result = self.send_raw(result);
774        if _result.is_err() {
775            self.control_handle.shutdown();
776        }
777        self.drop_without_shutdown();
778        _result
779    }
780
781    /// Similar to "send" but does not shutdown the channel if an error occurs.
782    pub fn send_no_shutdown_on_err(
783        self,
784        mut result: Result<(), SetSystemActivityGovernorStateError>,
785    ) -> Result<(), fidl::Error> {
786        let _result = self.send_raw(result);
787        self.drop_without_shutdown();
788        _result
789    }
790
791    fn send_raw(
792        &self,
793        mut result: Result<(), SetSystemActivityGovernorStateError>,
794    ) -> Result<(), fidl::Error> {
795        self.control_handle.inner.send::<fidl::encoding::ResultType<
796            fidl::encoding::EmptyStruct,
797            SetSystemActivityGovernorStateError,
798        >>(
799            result,
800            self.tx_id,
801            0x212842d46b8459f8,
802            fidl::encoding::DynamicFlags::empty(),
803        )
804    }
805}
806
807#[must_use = "FIDL methods require a response to be sent"]
808#[derive(Debug)]
809pub struct StateGetResponder {
810    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
811    tx_id: u32,
812}
813
814/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
815/// if the responder is dropped without sending a response, so that the client
816/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
817impl std::ops::Drop for StateGetResponder {
818    fn drop(&mut self) {
819        self.control_handle.shutdown();
820        // Safety: drops once, never accessed again
821        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
822    }
823}
824
825impl fidl::endpoints::Responder for StateGetResponder {
826    type ControlHandle = StateControlHandle;
827
828    fn control_handle(&self) -> &StateControlHandle {
829        &self.control_handle
830    }
831
832    fn drop_without_shutdown(mut self) {
833        // Safety: drops once, never accessed again due to mem::forget
834        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
835        // Prevent Drop from running (which would shut down the channel)
836        std::mem::forget(self);
837    }
838}
839
840impl StateGetResponder {
841    /// Sends a response to the FIDL transaction.
842    ///
843    /// Sets the channel to shutdown if an error occurs.
844    pub fn send(self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
845        let _result = self.send_raw(payload);
846        if _result.is_err() {
847            self.control_handle.shutdown();
848        }
849        self.drop_without_shutdown();
850        _result
851    }
852
853    /// Similar to "send" but does not shutdown the channel if an error occurs.
854    pub fn send_no_shutdown_on_err(
855        self,
856        mut payload: &SystemActivityGovernorState,
857    ) -> Result<(), fidl::Error> {
858        let _result = self.send_raw(payload);
859        self.drop_without_shutdown();
860        _result
861    }
862
863    fn send_raw(&self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
864        self.control_handle.inner.send::<SystemActivityGovernorState>(
865            payload,
866            self.tx_id,
867            0x65b19621b5644fdb,
868            fidl::encoding::DynamicFlags::empty(),
869        )
870    }
871}
872
873#[must_use = "FIDL methods require a response to be sent"]
874#[derive(Debug)]
875pub struct StateSetBootCompleteResponder {
876    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
877    tx_id: u32,
878}
879
880/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
881/// if the responder is dropped without sending a response, so that the client
882/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
883impl std::ops::Drop for StateSetBootCompleteResponder {
884    fn drop(&mut self) {
885        self.control_handle.shutdown();
886        // Safety: drops once, never accessed again
887        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
888    }
889}
890
891impl fidl::endpoints::Responder for StateSetBootCompleteResponder {
892    type ControlHandle = StateControlHandle;
893
894    fn control_handle(&self) -> &StateControlHandle {
895        &self.control_handle
896    }
897
898    fn drop_without_shutdown(mut self) {
899        // Safety: drops once, never accessed again due to mem::forget
900        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
901        // Prevent Drop from running (which would shut down the channel)
902        std::mem::forget(self);
903    }
904}
905
906impl StateSetBootCompleteResponder {
907    /// Sends a response to the FIDL transaction.
908    ///
909    /// Sets the channel to shutdown if an error occurs.
910    pub fn send(self) -> Result<(), fidl::Error> {
911        let _result = self.send_raw();
912        if _result.is_err() {
913            self.control_handle.shutdown();
914        }
915        self.drop_without_shutdown();
916        _result
917    }
918
919    /// Similar to "send" but does not shutdown the channel if an error occurs.
920    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
921        let _result = self.send_raw();
922        self.drop_without_shutdown();
923        _result
924    }
925
926    fn send_raw(&self) -> Result<(), fidl::Error> {
927        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
928            (),
929            self.tx_id,
930            0x7dded2028ad39365,
931            fidl::encoding::DynamicFlags::empty(),
932        )
933    }
934}
935
936#[must_use = "FIDL methods require a response to be sent"]
937#[derive(Debug)]
938pub struct StateWatchResponder {
939    control_handle: std::mem::ManuallyDrop<StateControlHandle>,
940    tx_id: u32,
941}
942
943/// Set the the channel to be shutdown (see [`StateControlHandle::shutdown`])
944/// if the responder is dropped without sending a response, so that the client
945/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
946impl std::ops::Drop for StateWatchResponder {
947    fn drop(&mut self) {
948        self.control_handle.shutdown();
949        // Safety: drops once, never accessed again
950        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
951    }
952}
953
954impl fidl::endpoints::Responder for StateWatchResponder {
955    type ControlHandle = StateControlHandle;
956
957    fn control_handle(&self) -> &StateControlHandle {
958        &self.control_handle
959    }
960
961    fn drop_without_shutdown(mut self) {
962        // Safety: drops once, never accessed again due to mem::forget
963        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
964        // Prevent Drop from running (which would shut down the channel)
965        std::mem::forget(self);
966    }
967}
968
969impl StateWatchResponder {
970    /// Sends a response to the FIDL transaction.
971    ///
972    /// Sets the channel to shutdown if an error occurs.
973    pub fn send(self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
974        let _result = self.send_raw(payload);
975        if _result.is_err() {
976            self.control_handle.shutdown();
977        }
978        self.drop_without_shutdown();
979        _result
980    }
981
982    /// Similar to "send" but does not shutdown the channel if an error occurs.
983    pub fn send_no_shutdown_on_err(
984        self,
985        mut payload: &SystemActivityGovernorState,
986    ) -> Result<(), fidl::Error> {
987        let _result = self.send_raw(payload);
988        self.drop_without_shutdown();
989        _result
990    }
991
992    fn send_raw(&self, mut payload: &SystemActivityGovernorState) -> Result<(), fidl::Error> {
993        self.control_handle.inner.send::<SystemActivityGovernorState>(
994            payload,
995            self.tx_id,
996            0x434b0aa4bbac7965,
997            fidl::encoding::DynamicFlags::empty(),
998        )
999    }
1000}
1001
1002mod internal {
1003    use super::*;
1004}