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