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