fidl_fuchsia_power_cpu_manager/
fidl_fuchsia_power_cpu_manager.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_fuchsia_power_cpu_manager__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct BoostBoostResponse {
16    pub token: fidl::EventPair,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for BoostBoostResponse {}
20
21#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
22pub struct BoostMarker;
23
24impl fidl::endpoints::ProtocolMarker for BoostMarker {
25    type Proxy = BoostProxy;
26    type RequestStream = BoostRequestStream;
27    #[cfg(target_os = "fuchsia")]
28    type SynchronousProxy = BoostSynchronousProxy;
29
30    const DEBUG_NAME: &'static str = "fuchsia.power.cpu.manager.Boost";
31}
32impl fidl::endpoints::DiscoverableProtocolMarker for BoostMarker {}
33pub type BoostBoostResult = Result<fidl::EventPair, BoostError>;
34
35pub trait BoostProxyInterface: Send + Sync {
36    type BoostResponseFut: std::future::Future<Output = Result<BoostBoostResult, fidl::Error>>
37        + Send;
38    fn r#boost(&self) -> Self::BoostResponseFut;
39}
40#[derive(Debug)]
41#[cfg(target_os = "fuchsia")]
42pub struct BoostSynchronousProxy {
43    client: fidl::client::sync::Client,
44}
45
46#[cfg(target_os = "fuchsia")]
47impl fidl::endpoints::SynchronousProxy for BoostSynchronousProxy {
48    type Proxy = BoostProxy;
49    type Protocol = BoostMarker;
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 BoostSynchronousProxy {
66    pub fn new(channel: fidl::Channel) -> Self {
67        let protocol_name = <BoostMarker 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<BoostEvent, fidl::Error> {
81        BoostEvent::decode(self.client.wait_for_event(deadline)?)
82    }
83
84    /// Boost the system to a higher performance state. Signal the end of boost by closing the
85    /// returned eventpair.
86    ///
87    /// This call is ref-counted. If there are multiple boost sources, the system will return to
88    /// normal performance when the last boost source is removed.
89    pub fn r#boost(
90        &self,
91        ___deadline: zx::MonotonicInstant,
92    ) -> Result<BoostBoostResult, fidl::Error> {
93        let _response = self.client.send_query::<
94            fidl::encoding::EmptyPayload,
95            fidl::encoding::FlexibleResultType<BoostBoostResponse, BoostError>,
96        >(
97            (),
98            0x814fabf86f2b1a3,
99            fidl::encoding::DynamicFlags::FLEXIBLE,
100            ___deadline,
101        )?
102        .into_result::<BoostMarker>("boost")?;
103        Ok(_response.map(|x| x.token))
104    }
105}
106
107#[cfg(target_os = "fuchsia")]
108impl From<BoostSynchronousProxy> for zx::NullableHandle {
109    fn from(value: BoostSynchronousProxy) -> Self {
110        value.into_channel().into()
111    }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl From<fidl::Channel> for BoostSynchronousProxy {
116    fn from(value: fidl::Channel) -> Self {
117        Self::new(value)
118    }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl fidl::endpoints::FromClient for BoostSynchronousProxy {
123    type Protocol = BoostMarker;
124
125    fn from_client(value: fidl::endpoints::ClientEnd<BoostMarker>) -> Self {
126        Self::new(value.into_channel())
127    }
128}
129
130#[derive(Debug, Clone)]
131pub struct BoostProxy {
132    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
133}
134
135impl fidl::endpoints::Proxy for BoostProxy {
136    type Protocol = BoostMarker;
137
138    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
139        Self::new(inner)
140    }
141
142    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
143        self.client.into_channel().map_err(|client| Self { client })
144    }
145
146    fn as_channel(&self) -> &::fidl::AsyncChannel {
147        self.client.as_channel()
148    }
149}
150
151impl BoostProxy {
152    /// Create a new Proxy for fuchsia.power.cpu.manager/Boost.
153    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
154        let protocol_name = <BoostMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
155        Self { client: fidl::client::Client::new(channel, protocol_name) }
156    }
157
158    /// Get a Stream of events from the remote end of the protocol.
159    ///
160    /// # Panics
161    ///
162    /// Panics if the event stream was already taken.
163    pub fn take_event_stream(&self) -> BoostEventStream {
164        BoostEventStream { event_receiver: self.client.take_event_receiver() }
165    }
166
167    /// Boost the system to a higher performance state. Signal the end of boost by closing the
168    /// returned eventpair.
169    ///
170    /// This call is ref-counted. If there are multiple boost sources, the system will return to
171    /// normal performance when the last boost source is removed.
172    pub fn r#boost(
173        &self,
174    ) -> fidl::client::QueryResponseFut<
175        BoostBoostResult,
176        fidl::encoding::DefaultFuchsiaResourceDialect,
177    > {
178        BoostProxyInterface::r#boost(self)
179    }
180}
181
182impl BoostProxyInterface for BoostProxy {
183    type BoostResponseFut = fidl::client::QueryResponseFut<
184        BoostBoostResult,
185        fidl::encoding::DefaultFuchsiaResourceDialect,
186    >;
187    fn r#boost(&self) -> Self::BoostResponseFut {
188        fn _decode(
189            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
190        ) -> Result<BoostBoostResult, fidl::Error> {
191            let _response = fidl::client::decode_transaction_body::<
192                fidl::encoding::FlexibleResultType<BoostBoostResponse, BoostError>,
193                fidl::encoding::DefaultFuchsiaResourceDialect,
194                0x814fabf86f2b1a3,
195            >(_buf?)?
196            .into_result::<BoostMarker>("boost")?;
197            Ok(_response.map(|x| x.token))
198        }
199        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, BoostBoostResult>(
200            (),
201            0x814fabf86f2b1a3,
202            fidl::encoding::DynamicFlags::FLEXIBLE,
203            _decode,
204        )
205    }
206}
207
208pub struct BoostEventStream {
209    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
210}
211
212impl std::marker::Unpin for BoostEventStream {}
213
214impl futures::stream::FusedStream for BoostEventStream {
215    fn is_terminated(&self) -> bool {
216        self.event_receiver.is_terminated()
217    }
218}
219
220impl futures::Stream for BoostEventStream {
221    type Item = Result<BoostEvent, fidl::Error>;
222
223    fn poll_next(
224        mut self: std::pin::Pin<&mut Self>,
225        cx: &mut std::task::Context<'_>,
226    ) -> std::task::Poll<Option<Self::Item>> {
227        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
228            &mut self.event_receiver,
229            cx
230        )?) {
231            Some(buf) => std::task::Poll::Ready(Some(BoostEvent::decode(buf))),
232            None => std::task::Poll::Ready(None),
233        }
234    }
235}
236
237#[derive(Debug)]
238pub enum BoostEvent {
239    #[non_exhaustive]
240    _UnknownEvent {
241        /// Ordinal of the event that was sent.
242        ordinal: u64,
243    },
244}
245
246impl BoostEvent {
247    /// Decodes a message buffer as a [`BoostEvent`].
248    fn decode(
249        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
250    ) -> Result<BoostEvent, fidl::Error> {
251        let (bytes, _handles) = buf.split_mut();
252        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
253        debug_assert_eq!(tx_header.tx_id, 0);
254        match tx_header.ordinal {
255            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
256                Ok(BoostEvent::_UnknownEvent { ordinal: tx_header.ordinal })
257            }
258            _ => Err(fidl::Error::UnknownOrdinal {
259                ordinal: tx_header.ordinal,
260                protocol_name: <BoostMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
261            }),
262        }
263    }
264}
265
266/// A Stream of incoming requests for fuchsia.power.cpu.manager/Boost.
267pub struct BoostRequestStream {
268    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
269    is_terminated: bool,
270}
271
272impl std::marker::Unpin for BoostRequestStream {}
273
274impl futures::stream::FusedStream for BoostRequestStream {
275    fn is_terminated(&self) -> bool {
276        self.is_terminated
277    }
278}
279
280impl fidl::endpoints::RequestStream for BoostRequestStream {
281    type Protocol = BoostMarker;
282    type ControlHandle = BoostControlHandle;
283
284    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
285        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
286    }
287
288    fn control_handle(&self) -> Self::ControlHandle {
289        BoostControlHandle { inner: self.inner.clone() }
290    }
291
292    fn into_inner(
293        self,
294    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
295    {
296        (self.inner, self.is_terminated)
297    }
298
299    fn from_inner(
300        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
301        is_terminated: bool,
302    ) -> Self {
303        Self { inner, is_terminated }
304    }
305}
306
307impl futures::Stream for BoostRequestStream {
308    type Item = Result<BoostRequest, fidl::Error>;
309
310    fn poll_next(
311        mut self: std::pin::Pin<&mut Self>,
312        cx: &mut std::task::Context<'_>,
313    ) -> std::task::Poll<Option<Self::Item>> {
314        let this = &mut *self;
315        if this.inner.check_shutdown(cx) {
316            this.is_terminated = true;
317            return std::task::Poll::Ready(None);
318        }
319        if this.is_terminated {
320            panic!("polled BoostRequestStream after completion");
321        }
322        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
323            |bytes, handles| {
324                match this.inner.channel().read_etc(cx, bytes, handles) {
325                    std::task::Poll::Ready(Ok(())) => {}
326                    std::task::Poll::Pending => return std::task::Poll::Pending,
327                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
328                        this.is_terminated = true;
329                        return std::task::Poll::Ready(None);
330                    }
331                    std::task::Poll::Ready(Err(e)) => {
332                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
333                            e.into(),
334                        ))));
335                    }
336                }
337
338                // A message has been received from the channel
339                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
340
341                std::task::Poll::Ready(Some(match header.ordinal {
342                    0x814fabf86f2b1a3 => {
343                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
344                        let mut req = fidl::new_empty!(
345                            fidl::encoding::EmptyPayload,
346                            fidl::encoding::DefaultFuchsiaResourceDialect
347                        );
348                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
349                        let control_handle = BoostControlHandle { inner: this.inner.clone() };
350                        Ok(BoostRequest::Boost {
351                            responder: BoostBoostResponder {
352                                control_handle: std::mem::ManuallyDrop::new(control_handle),
353                                tx_id: header.tx_id,
354                            },
355                        })
356                    }
357                    _ if header.tx_id == 0
358                        && header
359                            .dynamic_flags()
360                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
361                    {
362                        Ok(BoostRequest::_UnknownMethod {
363                            ordinal: header.ordinal,
364                            control_handle: BoostControlHandle { inner: this.inner.clone() },
365                            method_type: fidl::MethodType::OneWay,
366                        })
367                    }
368                    _ if header
369                        .dynamic_flags()
370                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
371                    {
372                        this.inner.send_framework_err(
373                            fidl::encoding::FrameworkErr::UnknownMethod,
374                            header.tx_id,
375                            header.ordinal,
376                            header.dynamic_flags(),
377                            (bytes, handles),
378                        )?;
379                        Ok(BoostRequest::_UnknownMethod {
380                            ordinal: header.ordinal,
381                            control_handle: BoostControlHandle { inner: this.inner.clone() },
382                            method_type: fidl::MethodType::TwoWay,
383                        })
384                    }
385                    _ => Err(fidl::Error::UnknownOrdinal {
386                        ordinal: header.ordinal,
387                        protocol_name: <BoostMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
388                    }),
389                }))
390            },
391        )
392    }
393}
394
395#[derive(Debug)]
396pub enum BoostRequest {
397    /// Boost the system to a higher performance state. Signal the end of boost by closing the
398    /// returned eventpair.
399    ///
400    /// This call is ref-counted. If there are multiple boost sources, the system will return to
401    /// normal performance when the last boost source is removed.
402    Boost { responder: BoostBoostResponder },
403    /// An interaction was received which does not match any known method.
404    #[non_exhaustive]
405    _UnknownMethod {
406        /// Ordinal of the method that was called.
407        ordinal: u64,
408        control_handle: BoostControlHandle,
409        method_type: fidl::MethodType,
410    },
411}
412
413impl BoostRequest {
414    #[allow(irrefutable_let_patterns)]
415    pub fn into_boost(self) -> Option<(BoostBoostResponder)> {
416        if let BoostRequest::Boost { responder } = self { Some((responder)) } else { None }
417    }
418
419    /// Name of the method defined in FIDL
420    pub fn method_name(&self) -> &'static str {
421        match *self {
422            BoostRequest::Boost { .. } => "boost",
423            BoostRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
424                "unknown one-way method"
425            }
426            BoostRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
427                "unknown two-way method"
428            }
429        }
430    }
431}
432
433#[derive(Debug, Clone)]
434pub struct BoostControlHandle {
435    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
436}
437
438impl fidl::endpoints::ControlHandle for BoostControlHandle {
439    fn shutdown(&self) {
440        self.inner.shutdown()
441    }
442
443    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
444        self.inner.shutdown_with_epitaph(status)
445    }
446
447    fn is_closed(&self) -> bool {
448        self.inner.channel().is_closed()
449    }
450    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
451        self.inner.channel().on_closed()
452    }
453
454    #[cfg(target_os = "fuchsia")]
455    fn signal_peer(
456        &self,
457        clear_mask: zx::Signals,
458        set_mask: zx::Signals,
459    ) -> Result<(), zx_status::Status> {
460        use fidl::Peered;
461        self.inner.channel().signal_peer(clear_mask, set_mask)
462    }
463}
464
465impl BoostControlHandle {}
466
467#[must_use = "FIDL methods require a response to be sent"]
468#[derive(Debug)]
469pub struct BoostBoostResponder {
470    control_handle: std::mem::ManuallyDrop<BoostControlHandle>,
471    tx_id: u32,
472}
473
474/// Set the the channel to be shutdown (see [`BoostControlHandle::shutdown`])
475/// if the responder is dropped without sending a response, so that the client
476/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
477impl std::ops::Drop for BoostBoostResponder {
478    fn drop(&mut self) {
479        self.control_handle.shutdown();
480        // Safety: drops once, never accessed again
481        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
482    }
483}
484
485impl fidl::endpoints::Responder for BoostBoostResponder {
486    type ControlHandle = BoostControlHandle;
487
488    fn control_handle(&self) -> &BoostControlHandle {
489        &self.control_handle
490    }
491
492    fn drop_without_shutdown(mut self) {
493        // Safety: drops once, never accessed again due to mem::forget
494        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
495        // Prevent Drop from running (which would shut down the channel)
496        std::mem::forget(self);
497    }
498}
499
500impl BoostBoostResponder {
501    /// Sends a response to the FIDL transaction.
502    ///
503    /// Sets the channel to shutdown if an error occurs.
504    pub fn send(self, mut result: Result<fidl::EventPair, BoostError>) -> Result<(), fidl::Error> {
505        let _result = self.send_raw(result);
506        if _result.is_err() {
507            self.control_handle.shutdown();
508        }
509        self.drop_without_shutdown();
510        _result
511    }
512
513    /// Similar to "send" but does not shutdown the channel if an error occurs.
514    pub fn send_no_shutdown_on_err(
515        self,
516        mut result: Result<fidl::EventPair, BoostError>,
517    ) -> Result<(), fidl::Error> {
518        let _result = self.send_raw(result);
519        self.drop_without_shutdown();
520        _result
521    }
522
523    fn send_raw(&self, mut result: Result<fidl::EventPair, BoostError>) -> Result<(), fidl::Error> {
524        self.control_handle
525            .inner
526            .send::<fidl::encoding::FlexibleResultType<BoostBoostResponse, BoostError>>(
527                fidl::encoding::FlexibleResult::new(result.map(|token| (token,))),
528                self.tx_id,
529                0x814fabf86f2b1a3,
530                fidl::encoding::DynamicFlags::FLEXIBLE,
531            )
532    }
533}
534
535mod internal {
536    use super::*;
537
538    impl fidl::encoding::ResourceTypeMarker for BoostBoostResponse {
539        type Borrowed<'a> = &'a mut Self;
540        fn take_or_borrow<'a>(
541            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
542        ) -> Self::Borrowed<'a> {
543            value
544        }
545    }
546
547    unsafe impl fidl::encoding::TypeMarker for BoostBoostResponse {
548        type Owned = Self;
549
550        #[inline(always)]
551        fn inline_align(_context: fidl::encoding::Context) -> usize {
552            4
553        }
554
555        #[inline(always)]
556        fn inline_size(_context: fidl::encoding::Context) -> usize {
557            4
558        }
559    }
560
561    unsafe impl
562        fidl::encoding::Encode<BoostBoostResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
563        for &mut BoostBoostResponse
564    {
565        #[inline]
566        unsafe fn encode(
567            self,
568            encoder: &mut fidl::encoding::Encoder<
569                '_,
570                fidl::encoding::DefaultFuchsiaResourceDialect,
571            >,
572            offset: usize,
573            _depth: fidl::encoding::Depth,
574        ) -> fidl::Result<()> {
575            encoder.debug_check_bounds::<BoostBoostResponse>(offset);
576            // Delegate to tuple encoding.
577            fidl::encoding::Encode::<
578                BoostBoostResponse,
579                fidl::encoding::DefaultFuchsiaResourceDialect,
580            >::encode(
581                (<fidl::encoding::HandleType<
582                    fidl::EventPair,
583                    { fidl::ObjectType::EVENTPAIR.into_raw() },
584                    2147483648,
585                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
586                    &mut self.token
587                ),),
588                encoder,
589                offset,
590                _depth,
591            )
592        }
593    }
594    unsafe impl<
595        T0: fidl::encoding::Encode<
596                fidl::encoding::HandleType<
597                    fidl::EventPair,
598                    { fidl::ObjectType::EVENTPAIR.into_raw() },
599                    2147483648,
600                >,
601                fidl::encoding::DefaultFuchsiaResourceDialect,
602            >,
603    > fidl::encoding::Encode<BoostBoostResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
604        for (T0,)
605    {
606        #[inline]
607        unsafe fn encode(
608            self,
609            encoder: &mut fidl::encoding::Encoder<
610                '_,
611                fidl::encoding::DefaultFuchsiaResourceDialect,
612            >,
613            offset: usize,
614            depth: fidl::encoding::Depth,
615        ) -> fidl::Result<()> {
616            encoder.debug_check_bounds::<BoostBoostResponse>(offset);
617            // Zero out padding regions. There's no need to apply masks
618            // because the unmasked parts will be overwritten by fields.
619            // Write the fields.
620            self.0.encode(encoder, offset + 0, depth)?;
621            Ok(())
622        }
623    }
624
625    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
626        for BoostBoostResponse
627    {
628        #[inline(always)]
629        fn new_empty() -> Self {
630            Self {
631                token: fidl::new_empty!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
632            }
633        }
634
635        #[inline]
636        unsafe fn decode(
637            &mut self,
638            decoder: &mut fidl::encoding::Decoder<
639                '_,
640                fidl::encoding::DefaultFuchsiaResourceDialect,
641            >,
642            offset: usize,
643            _depth: fidl::encoding::Depth,
644        ) -> fidl::Result<()> {
645            decoder.debug_check_bounds::<Self>(offset);
646            // Verify that padding bytes are zero.
647            fidl::decode!(fidl::encoding::HandleType<fidl::EventPair, { fidl::ObjectType::EVENTPAIR.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.token, decoder, offset + 0, _depth)?;
648            Ok(())
649        }
650    }
651}