fidl_fuchsia_starnix_psi/
fidl_fuchsia_starnix_psi.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_starnix_psi_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Default, PartialEq)]
15pub struct PsiProviderWatchMemoryStallResponse {
16    pub event: Option<fidl::Event>,
17    #[doc(hidden)]
18    pub __source_breaking: fidl::marker::SourceBreaking,
19}
20
21impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
22    for PsiProviderWatchMemoryStallResponse
23{
24}
25
26#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
27pub struct PsiProviderMarker;
28
29impl fidl::endpoints::ProtocolMarker for PsiProviderMarker {
30    type Proxy = PsiProviderProxy;
31    type RequestStream = PsiProviderRequestStream;
32    #[cfg(target_os = "fuchsia")]
33    type SynchronousProxy = PsiProviderSynchronousProxy;
34
35    const DEBUG_NAME: &'static str = "fuchsia.starnix.psi.PsiProvider";
36}
37impl fidl::endpoints::DiscoverableProtocolMarker for PsiProviderMarker {}
38pub type PsiProviderGetMemoryPressureStatsResult =
39    Result<PsiProviderGetMemoryPressureStatsResponse, i32>;
40pub type PsiProviderWatchMemoryStallResult = Result<PsiProviderWatchMemoryStallResponse, i32>;
41
42pub trait PsiProviderProxyInterface: Send + Sync {
43    type GetMemoryPressureStatsResponseFut: std::future::Future<Output = Result<PsiProviderGetMemoryPressureStatsResult, fidl::Error>>
44        + Send;
45    fn r#get_memory_pressure_stats(&self) -> Self::GetMemoryPressureStatsResponseFut;
46    type WatchMemoryStallResponseFut: std::future::Future<Output = Result<PsiProviderWatchMemoryStallResult, fidl::Error>>
47        + Send;
48    fn r#watch_memory_stall(
49        &self,
50        payload: &PsiProviderWatchMemoryStallRequest,
51    ) -> Self::WatchMemoryStallResponseFut;
52}
53#[derive(Debug)]
54#[cfg(target_os = "fuchsia")]
55pub struct PsiProviderSynchronousProxy {
56    client: fidl::client::sync::Client,
57}
58
59#[cfg(target_os = "fuchsia")]
60impl fidl::endpoints::SynchronousProxy for PsiProviderSynchronousProxy {
61    type Proxy = PsiProviderProxy;
62    type Protocol = PsiProviderMarker;
63
64    fn from_channel(inner: fidl::Channel) -> Self {
65        Self::new(inner)
66    }
67
68    fn into_channel(self) -> fidl::Channel {
69        self.client.into_channel()
70    }
71
72    fn as_channel(&self) -> &fidl::Channel {
73        self.client.as_channel()
74    }
75}
76
77#[cfg(target_os = "fuchsia")]
78impl PsiProviderSynchronousProxy {
79    pub fn new(channel: fidl::Channel) -> Self {
80        let protocol_name = <PsiProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
81        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
82    }
83
84    pub fn into_channel(self) -> fidl::Channel {
85        self.client.into_channel()
86    }
87
88    /// Waits until an event arrives and returns it. It is safe for other
89    /// threads to make concurrent requests while waiting for an event.
90    pub fn wait_for_event(
91        &self,
92        deadline: zx::MonotonicInstant,
93    ) -> Result<PsiProviderEvent, fidl::Error> {
94        PsiProviderEvent::decode(self.client.wait_for_event(deadline)?)
95    }
96
97    pub fn r#get_memory_pressure_stats(
98        &self,
99        ___deadline: zx::MonotonicInstant,
100    ) -> Result<PsiProviderGetMemoryPressureStatsResult, fidl::Error> {
101        let _response = self.client.send_query::<
102            fidl::encoding::EmptyPayload,
103            fidl::encoding::FlexibleResultType<PsiProviderGetMemoryPressureStatsResponse, i32>,
104        >(
105            (),
106            0x2122b26519bc6d20,
107            fidl::encoding::DynamicFlags::FLEXIBLE,
108            ___deadline,
109        )?
110        .into_result::<PsiProviderMarker>("get_memory_pressure_stats")?;
111        Ok(_response.map(|x| x))
112    }
113
114    pub fn r#watch_memory_stall(
115        &self,
116        mut payload: &PsiProviderWatchMemoryStallRequest,
117        ___deadline: zx::MonotonicInstant,
118    ) -> Result<PsiProviderWatchMemoryStallResult, fidl::Error> {
119        let _response = self.client.send_query::<
120            PsiProviderWatchMemoryStallRequest,
121            fidl::encoding::FlexibleResultType<PsiProviderWatchMemoryStallResponse, i32>,
122        >(
123            payload,
124            0x1c45c961cce60400,
125            fidl::encoding::DynamicFlags::FLEXIBLE,
126            ___deadline,
127        )?
128        .into_result::<PsiProviderMarker>("watch_memory_stall")?;
129        Ok(_response.map(|x| x))
130    }
131}
132
133#[cfg(target_os = "fuchsia")]
134impl From<PsiProviderSynchronousProxy> for zx::Handle {
135    fn from(value: PsiProviderSynchronousProxy) -> Self {
136        value.into_channel().into()
137    }
138}
139
140#[cfg(target_os = "fuchsia")]
141impl From<fidl::Channel> for PsiProviderSynchronousProxy {
142    fn from(value: fidl::Channel) -> Self {
143        Self::new(value)
144    }
145}
146
147#[derive(Debug, Clone)]
148pub struct PsiProviderProxy {
149    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
150}
151
152impl fidl::endpoints::Proxy for PsiProviderProxy {
153    type Protocol = PsiProviderMarker;
154
155    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
156        Self::new(inner)
157    }
158
159    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
160        self.client.into_channel().map_err(|client| Self { client })
161    }
162
163    fn as_channel(&self) -> &::fidl::AsyncChannel {
164        self.client.as_channel()
165    }
166}
167
168impl PsiProviderProxy {
169    /// Create a new Proxy for fuchsia.starnix.psi/PsiProvider.
170    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
171        let protocol_name = <PsiProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
172        Self { client: fidl::client::Client::new(channel, protocol_name) }
173    }
174
175    /// Get a Stream of events from the remote end of the protocol.
176    ///
177    /// # Panics
178    ///
179    /// Panics if the event stream was already taken.
180    pub fn take_event_stream(&self) -> PsiProviderEventStream {
181        PsiProviderEventStream { event_receiver: self.client.take_event_receiver() }
182    }
183
184    pub fn r#get_memory_pressure_stats(
185        &self,
186    ) -> fidl::client::QueryResponseFut<
187        PsiProviderGetMemoryPressureStatsResult,
188        fidl::encoding::DefaultFuchsiaResourceDialect,
189    > {
190        PsiProviderProxyInterface::r#get_memory_pressure_stats(self)
191    }
192
193    pub fn r#watch_memory_stall(
194        &self,
195        mut payload: &PsiProviderWatchMemoryStallRequest,
196    ) -> fidl::client::QueryResponseFut<
197        PsiProviderWatchMemoryStallResult,
198        fidl::encoding::DefaultFuchsiaResourceDialect,
199    > {
200        PsiProviderProxyInterface::r#watch_memory_stall(self, payload)
201    }
202}
203
204impl PsiProviderProxyInterface for PsiProviderProxy {
205    type GetMemoryPressureStatsResponseFut = fidl::client::QueryResponseFut<
206        PsiProviderGetMemoryPressureStatsResult,
207        fidl::encoding::DefaultFuchsiaResourceDialect,
208    >;
209    fn r#get_memory_pressure_stats(&self) -> Self::GetMemoryPressureStatsResponseFut {
210        fn _decode(
211            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
212        ) -> Result<PsiProviderGetMemoryPressureStatsResult, fidl::Error> {
213            let _response = fidl::client::decode_transaction_body::<
214                fidl::encoding::FlexibleResultType<PsiProviderGetMemoryPressureStatsResponse, i32>,
215                fidl::encoding::DefaultFuchsiaResourceDialect,
216                0x2122b26519bc6d20,
217            >(_buf?)?
218            .into_result::<PsiProviderMarker>("get_memory_pressure_stats")?;
219            Ok(_response.map(|x| x))
220        }
221        self.client.send_query_and_decode::<
222            fidl::encoding::EmptyPayload,
223            PsiProviderGetMemoryPressureStatsResult,
224        >(
225            (),
226            0x2122b26519bc6d20,
227            fidl::encoding::DynamicFlags::FLEXIBLE,
228            _decode,
229        )
230    }
231
232    type WatchMemoryStallResponseFut = fidl::client::QueryResponseFut<
233        PsiProviderWatchMemoryStallResult,
234        fidl::encoding::DefaultFuchsiaResourceDialect,
235    >;
236    fn r#watch_memory_stall(
237        &self,
238        mut payload: &PsiProviderWatchMemoryStallRequest,
239    ) -> Self::WatchMemoryStallResponseFut {
240        fn _decode(
241            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
242        ) -> Result<PsiProviderWatchMemoryStallResult, fidl::Error> {
243            let _response = fidl::client::decode_transaction_body::<
244                fidl::encoding::FlexibleResultType<PsiProviderWatchMemoryStallResponse, i32>,
245                fidl::encoding::DefaultFuchsiaResourceDialect,
246                0x1c45c961cce60400,
247            >(_buf?)?
248            .into_result::<PsiProviderMarker>("watch_memory_stall")?;
249            Ok(_response.map(|x| x))
250        }
251        self.client.send_query_and_decode::<
252            PsiProviderWatchMemoryStallRequest,
253            PsiProviderWatchMemoryStallResult,
254        >(
255            payload,
256            0x1c45c961cce60400,
257            fidl::encoding::DynamicFlags::FLEXIBLE,
258            _decode,
259        )
260    }
261}
262
263pub struct PsiProviderEventStream {
264    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
265}
266
267impl std::marker::Unpin for PsiProviderEventStream {}
268
269impl futures::stream::FusedStream for PsiProviderEventStream {
270    fn is_terminated(&self) -> bool {
271        self.event_receiver.is_terminated()
272    }
273}
274
275impl futures::Stream for PsiProviderEventStream {
276    type Item = Result<PsiProviderEvent, fidl::Error>;
277
278    fn poll_next(
279        mut self: std::pin::Pin<&mut Self>,
280        cx: &mut std::task::Context<'_>,
281    ) -> std::task::Poll<Option<Self::Item>> {
282        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
283            &mut self.event_receiver,
284            cx
285        )?) {
286            Some(buf) => std::task::Poll::Ready(Some(PsiProviderEvent::decode(buf))),
287            None => std::task::Poll::Ready(None),
288        }
289    }
290}
291
292#[derive(Debug)]
293pub enum PsiProviderEvent {
294    #[non_exhaustive]
295    _UnknownEvent {
296        /// Ordinal of the event that was sent.
297        ordinal: u64,
298    },
299}
300
301impl PsiProviderEvent {
302    /// Decodes a message buffer as a [`PsiProviderEvent`].
303    fn decode(
304        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
305    ) -> Result<PsiProviderEvent, fidl::Error> {
306        let (bytes, _handles) = buf.split_mut();
307        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
308        debug_assert_eq!(tx_header.tx_id, 0);
309        match tx_header.ordinal {
310            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
311                Ok(PsiProviderEvent::_UnknownEvent { ordinal: tx_header.ordinal })
312            }
313            _ => Err(fidl::Error::UnknownOrdinal {
314                ordinal: tx_header.ordinal,
315                protocol_name: <PsiProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
316            }),
317        }
318    }
319}
320
321/// A Stream of incoming requests for fuchsia.starnix.psi/PsiProvider.
322pub struct PsiProviderRequestStream {
323    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
324    is_terminated: bool,
325}
326
327impl std::marker::Unpin for PsiProviderRequestStream {}
328
329impl futures::stream::FusedStream for PsiProviderRequestStream {
330    fn is_terminated(&self) -> bool {
331        self.is_terminated
332    }
333}
334
335impl fidl::endpoints::RequestStream for PsiProviderRequestStream {
336    type Protocol = PsiProviderMarker;
337    type ControlHandle = PsiProviderControlHandle;
338
339    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
340        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
341    }
342
343    fn control_handle(&self) -> Self::ControlHandle {
344        PsiProviderControlHandle { inner: self.inner.clone() }
345    }
346
347    fn into_inner(
348        self,
349    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
350    {
351        (self.inner, self.is_terminated)
352    }
353
354    fn from_inner(
355        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
356        is_terminated: bool,
357    ) -> Self {
358        Self { inner, is_terminated }
359    }
360}
361
362impl futures::Stream for PsiProviderRequestStream {
363    type Item = Result<PsiProviderRequest, fidl::Error>;
364
365    fn poll_next(
366        mut self: std::pin::Pin<&mut Self>,
367        cx: &mut std::task::Context<'_>,
368    ) -> std::task::Poll<Option<Self::Item>> {
369        let this = &mut *self;
370        if this.inner.check_shutdown(cx) {
371            this.is_terminated = true;
372            return std::task::Poll::Ready(None);
373        }
374        if this.is_terminated {
375            panic!("polled PsiProviderRequestStream after completion");
376        }
377        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
378            |bytes, handles| {
379                match this.inner.channel().read_etc(cx, bytes, handles) {
380                    std::task::Poll::Ready(Ok(())) => {}
381                    std::task::Poll::Pending => return std::task::Poll::Pending,
382                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
383                        this.is_terminated = true;
384                        return std::task::Poll::Ready(None);
385                    }
386                    std::task::Poll::Ready(Err(e)) => {
387                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
388                            e.into(),
389                        ))))
390                    }
391                }
392
393                // A message has been received from the channel
394                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
395
396                std::task::Poll::Ready(Some(match header.ordinal {
397                    0x2122b26519bc6d20 => {
398                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
399                        let mut req = fidl::new_empty!(
400                            fidl::encoding::EmptyPayload,
401                            fidl::encoding::DefaultFuchsiaResourceDialect
402                        );
403                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
404                        let control_handle = PsiProviderControlHandle { inner: this.inner.clone() };
405                        Ok(PsiProviderRequest::GetMemoryPressureStats {
406                            responder: PsiProviderGetMemoryPressureStatsResponder {
407                                control_handle: std::mem::ManuallyDrop::new(control_handle),
408                                tx_id: header.tx_id,
409                            },
410                        })
411                    }
412                    0x1c45c961cce60400 => {
413                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
414                        let mut req = fidl::new_empty!(
415                            PsiProviderWatchMemoryStallRequest,
416                            fidl::encoding::DefaultFuchsiaResourceDialect
417                        );
418                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<PsiProviderWatchMemoryStallRequest>(&header, _body_bytes, handles, &mut req)?;
419                        let control_handle = PsiProviderControlHandle { inner: this.inner.clone() };
420                        Ok(PsiProviderRequest::WatchMemoryStall {
421                            payload: req,
422                            responder: PsiProviderWatchMemoryStallResponder {
423                                control_handle: std::mem::ManuallyDrop::new(control_handle),
424                                tx_id: header.tx_id,
425                            },
426                        })
427                    }
428                    _ if header.tx_id == 0
429                        && header
430                            .dynamic_flags()
431                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
432                    {
433                        Ok(PsiProviderRequest::_UnknownMethod {
434                            ordinal: header.ordinal,
435                            control_handle: PsiProviderControlHandle { inner: this.inner.clone() },
436                            method_type: fidl::MethodType::OneWay,
437                        })
438                    }
439                    _ if header
440                        .dynamic_flags()
441                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
442                    {
443                        this.inner.send_framework_err(
444                            fidl::encoding::FrameworkErr::UnknownMethod,
445                            header.tx_id,
446                            header.ordinal,
447                            header.dynamic_flags(),
448                            (bytes, handles),
449                        )?;
450                        Ok(PsiProviderRequest::_UnknownMethod {
451                            ordinal: header.ordinal,
452                            control_handle: PsiProviderControlHandle { inner: this.inner.clone() },
453                            method_type: fidl::MethodType::TwoWay,
454                        })
455                    }
456                    _ => Err(fidl::Error::UnknownOrdinal {
457                        ordinal: header.ordinal,
458                        protocol_name:
459                            <PsiProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
460                    }),
461                }))
462            },
463        )
464    }
465}
466
467#[derive(Debug)]
468pub enum PsiProviderRequest {
469    GetMemoryPressureStats {
470        responder: PsiProviderGetMemoryPressureStatsResponder,
471    },
472    WatchMemoryStall {
473        payload: PsiProviderWatchMemoryStallRequest,
474        responder: PsiProviderWatchMemoryStallResponder,
475    },
476    /// An interaction was received which does not match any known method.
477    #[non_exhaustive]
478    _UnknownMethod {
479        /// Ordinal of the method that was called.
480        ordinal: u64,
481        control_handle: PsiProviderControlHandle,
482        method_type: fidl::MethodType,
483    },
484}
485
486impl PsiProviderRequest {
487    #[allow(irrefutable_let_patterns)]
488    pub fn into_get_memory_pressure_stats(
489        self,
490    ) -> Option<(PsiProviderGetMemoryPressureStatsResponder)> {
491        if let PsiProviderRequest::GetMemoryPressureStats { responder } = self {
492            Some((responder))
493        } else {
494            None
495        }
496    }
497
498    #[allow(irrefutable_let_patterns)]
499    pub fn into_watch_memory_stall(
500        self,
501    ) -> Option<(PsiProviderWatchMemoryStallRequest, PsiProviderWatchMemoryStallResponder)> {
502        if let PsiProviderRequest::WatchMemoryStall { payload, responder } = self {
503            Some((payload, responder))
504        } else {
505            None
506        }
507    }
508
509    /// Name of the method defined in FIDL
510    pub fn method_name(&self) -> &'static str {
511        match *self {
512            PsiProviderRequest::GetMemoryPressureStats { .. } => "get_memory_pressure_stats",
513            PsiProviderRequest::WatchMemoryStall { .. } => "watch_memory_stall",
514            PsiProviderRequest::_UnknownMethod {
515                method_type: fidl::MethodType::OneWay, ..
516            } => "unknown one-way method",
517            PsiProviderRequest::_UnknownMethod {
518                method_type: fidl::MethodType::TwoWay, ..
519            } => "unknown two-way method",
520        }
521    }
522}
523
524#[derive(Debug, Clone)]
525pub struct PsiProviderControlHandle {
526    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
527}
528
529impl fidl::endpoints::ControlHandle for PsiProviderControlHandle {
530    fn shutdown(&self) {
531        self.inner.shutdown()
532    }
533    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
534        self.inner.shutdown_with_epitaph(status)
535    }
536
537    fn is_closed(&self) -> bool {
538        self.inner.channel().is_closed()
539    }
540    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
541        self.inner.channel().on_closed()
542    }
543
544    #[cfg(target_os = "fuchsia")]
545    fn signal_peer(
546        &self,
547        clear_mask: zx::Signals,
548        set_mask: zx::Signals,
549    ) -> Result<(), zx_status::Status> {
550        use fidl::Peered;
551        self.inner.channel().signal_peer(clear_mask, set_mask)
552    }
553}
554
555impl PsiProviderControlHandle {}
556
557#[must_use = "FIDL methods require a response to be sent"]
558#[derive(Debug)]
559pub struct PsiProviderGetMemoryPressureStatsResponder {
560    control_handle: std::mem::ManuallyDrop<PsiProviderControlHandle>,
561    tx_id: u32,
562}
563
564/// Set the the channel to be shutdown (see [`PsiProviderControlHandle::shutdown`])
565/// if the responder is dropped without sending a response, so that the client
566/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
567impl std::ops::Drop for PsiProviderGetMemoryPressureStatsResponder {
568    fn drop(&mut self) {
569        self.control_handle.shutdown();
570        // Safety: drops once, never accessed again
571        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
572    }
573}
574
575impl fidl::endpoints::Responder for PsiProviderGetMemoryPressureStatsResponder {
576    type ControlHandle = PsiProviderControlHandle;
577
578    fn control_handle(&self) -> &PsiProviderControlHandle {
579        &self.control_handle
580    }
581
582    fn drop_without_shutdown(mut self) {
583        // Safety: drops once, never accessed again due to mem::forget
584        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
585        // Prevent Drop from running (which would shut down the channel)
586        std::mem::forget(self);
587    }
588}
589
590impl PsiProviderGetMemoryPressureStatsResponder {
591    /// Sends a response to the FIDL transaction.
592    ///
593    /// Sets the channel to shutdown if an error occurs.
594    pub fn send(
595        self,
596        mut result: Result<&PsiProviderGetMemoryPressureStatsResponse, i32>,
597    ) -> Result<(), fidl::Error> {
598        let _result = self.send_raw(result);
599        if _result.is_err() {
600            self.control_handle.shutdown();
601        }
602        self.drop_without_shutdown();
603        _result
604    }
605
606    /// Similar to "send" but does not shutdown the channel if an error occurs.
607    pub fn send_no_shutdown_on_err(
608        self,
609        mut result: Result<&PsiProviderGetMemoryPressureStatsResponse, i32>,
610    ) -> Result<(), fidl::Error> {
611        let _result = self.send_raw(result);
612        self.drop_without_shutdown();
613        _result
614    }
615
616    fn send_raw(
617        &self,
618        mut result: Result<&PsiProviderGetMemoryPressureStatsResponse, i32>,
619    ) -> Result<(), fidl::Error> {
620        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
621            PsiProviderGetMemoryPressureStatsResponse,
622            i32,
623        >>(
624            fidl::encoding::FlexibleResult::new(result),
625            self.tx_id,
626            0x2122b26519bc6d20,
627            fidl::encoding::DynamicFlags::FLEXIBLE,
628        )
629    }
630}
631
632#[must_use = "FIDL methods require a response to be sent"]
633#[derive(Debug)]
634pub struct PsiProviderWatchMemoryStallResponder {
635    control_handle: std::mem::ManuallyDrop<PsiProviderControlHandle>,
636    tx_id: u32,
637}
638
639/// Set the the channel to be shutdown (see [`PsiProviderControlHandle::shutdown`])
640/// if the responder is dropped without sending a response, so that the client
641/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
642impl std::ops::Drop for PsiProviderWatchMemoryStallResponder {
643    fn drop(&mut self) {
644        self.control_handle.shutdown();
645        // Safety: drops once, never accessed again
646        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
647    }
648}
649
650impl fidl::endpoints::Responder for PsiProviderWatchMemoryStallResponder {
651    type ControlHandle = PsiProviderControlHandle;
652
653    fn control_handle(&self) -> &PsiProviderControlHandle {
654        &self.control_handle
655    }
656
657    fn drop_without_shutdown(mut self) {
658        // Safety: drops once, never accessed again due to mem::forget
659        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
660        // Prevent Drop from running (which would shut down the channel)
661        std::mem::forget(self);
662    }
663}
664
665impl PsiProviderWatchMemoryStallResponder {
666    /// Sends a response to the FIDL transaction.
667    ///
668    /// Sets the channel to shutdown if an error occurs.
669    pub fn send(
670        self,
671        mut result: Result<PsiProviderWatchMemoryStallResponse, i32>,
672    ) -> Result<(), fidl::Error> {
673        let _result = self.send_raw(result);
674        if _result.is_err() {
675            self.control_handle.shutdown();
676        }
677        self.drop_without_shutdown();
678        _result
679    }
680
681    /// Similar to "send" but does not shutdown the channel if an error occurs.
682    pub fn send_no_shutdown_on_err(
683        self,
684        mut result: Result<PsiProviderWatchMemoryStallResponse, i32>,
685    ) -> Result<(), fidl::Error> {
686        let _result = self.send_raw(result);
687        self.drop_without_shutdown();
688        _result
689    }
690
691    fn send_raw(
692        &self,
693        mut result: Result<PsiProviderWatchMemoryStallResponse, i32>,
694    ) -> Result<(), fidl::Error> {
695        self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
696            PsiProviderWatchMemoryStallResponse,
697            i32,
698        >>(
699            fidl::encoding::FlexibleResult::new(result.as_mut().map_err(|e| *e)),
700            self.tx_id,
701            0x1c45c961cce60400,
702            fidl::encoding::DynamicFlags::FLEXIBLE,
703        )
704    }
705}
706
707mod internal {
708    use super::*;
709
710    impl PsiProviderWatchMemoryStallResponse {
711        #[inline(always)]
712        fn max_ordinal_present(&self) -> u64 {
713            if let Some(_) = self.event {
714                return 1;
715            }
716            0
717        }
718    }
719
720    impl fidl::encoding::ResourceTypeMarker for PsiProviderWatchMemoryStallResponse {
721        type Borrowed<'a> = &'a mut Self;
722        fn take_or_borrow<'a>(
723            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
724        ) -> Self::Borrowed<'a> {
725            value
726        }
727    }
728
729    unsafe impl fidl::encoding::TypeMarker for PsiProviderWatchMemoryStallResponse {
730        type Owned = Self;
731
732        #[inline(always)]
733        fn inline_align(_context: fidl::encoding::Context) -> usize {
734            8
735        }
736
737        #[inline(always)]
738        fn inline_size(_context: fidl::encoding::Context) -> usize {
739            16
740        }
741    }
742
743    unsafe impl
744        fidl::encoding::Encode<
745            PsiProviderWatchMemoryStallResponse,
746            fidl::encoding::DefaultFuchsiaResourceDialect,
747        > for &mut PsiProviderWatchMemoryStallResponse
748    {
749        unsafe fn encode(
750            self,
751            encoder: &mut fidl::encoding::Encoder<
752                '_,
753                fidl::encoding::DefaultFuchsiaResourceDialect,
754            >,
755            offset: usize,
756            mut depth: fidl::encoding::Depth,
757        ) -> fidl::Result<()> {
758            encoder.debug_check_bounds::<PsiProviderWatchMemoryStallResponse>(offset);
759            // Vector header
760            let max_ordinal: u64 = self.max_ordinal_present();
761            encoder.write_num(max_ordinal, offset);
762            encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
763            // Calling encoder.out_of_line_offset(0) is not allowed.
764            if max_ordinal == 0 {
765                return Ok(());
766            }
767            depth.increment()?;
768            let envelope_size = 8;
769            let bytes_len = max_ordinal as usize * envelope_size;
770            #[allow(unused_variables)]
771            let offset = encoder.out_of_line_offset(bytes_len);
772            let mut _prev_end_offset: usize = 0;
773            if 1 > max_ordinal {
774                return Ok(());
775            }
776
777            // Write at offset+(ordinal-1)*envelope_size, since ordinals are one-based and envelopes
778            // are envelope_size bytes.
779            let cur_offset: usize = (1 - 1) * envelope_size;
780
781            // Zero reserved fields.
782            encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
783
784            // Safety:
785            // - bytes_len is calculated to fit envelope_size*max(member.ordinal).
786            // - Since cur_offset is envelope_size*(member.ordinal - 1) and the envelope takes
787            //   envelope_size bytes, there is always sufficient room.
788            fidl::encoding::encode_in_envelope_optional::<
789                fidl::encoding::HandleType<
790                    fidl::Event,
791                    { fidl::ObjectType::EVENT.into_raw() },
792                    2147483648,
793                >,
794                fidl::encoding::DefaultFuchsiaResourceDialect,
795            >(
796                self.event.as_mut().map(
797                    <fidl::encoding::HandleType<
798                        fidl::Event,
799                        { fidl::ObjectType::EVENT.into_raw() },
800                        2147483648,
801                    > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
802                ),
803                encoder,
804                offset + cur_offset,
805                depth,
806            )?;
807
808            _prev_end_offset = cur_offset + envelope_size;
809
810            Ok(())
811        }
812    }
813
814    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
815        for PsiProviderWatchMemoryStallResponse
816    {
817        #[inline(always)]
818        fn new_empty() -> Self {
819            Self::default()
820        }
821
822        unsafe fn decode(
823            &mut self,
824            decoder: &mut fidl::encoding::Decoder<
825                '_,
826                fidl::encoding::DefaultFuchsiaResourceDialect,
827            >,
828            offset: usize,
829            mut depth: fidl::encoding::Depth,
830        ) -> fidl::Result<()> {
831            decoder.debug_check_bounds::<Self>(offset);
832            let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
833                None => return Err(fidl::Error::NotNullable),
834                Some(len) => len,
835            };
836            // Calling decoder.out_of_line_offset(0) is not allowed.
837            if len == 0 {
838                return Ok(());
839            };
840            depth.increment()?;
841            let envelope_size = 8;
842            let bytes_len = len * envelope_size;
843            let offset = decoder.out_of_line_offset(bytes_len)?;
844            // Decode the envelope for each type.
845            let mut _next_ordinal_to_read = 0;
846            let mut next_offset = offset;
847            let end_offset = offset + bytes_len;
848            _next_ordinal_to_read += 1;
849            if next_offset >= end_offset {
850                return Ok(());
851            }
852
853            // Decode unknown envelopes for gaps in ordinals.
854            while _next_ordinal_to_read < 1 {
855                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
856                _next_ordinal_to_read += 1;
857                next_offset += envelope_size;
858            }
859
860            let next_out_of_line = decoder.next_out_of_line();
861            let handles_before = decoder.remaining_handles();
862            if let Some((inlined, num_bytes, num_handles)) =
863                fidl::encoding::decode_envelope_header(decoder, next_offset)?
864            {
865                let member_inline_size = <fidl::encoding::HandleType<
866                    fidl::Event,
867                    { fidl::ObjectType::EVENT.into_raw() },
868                    2147483648,
869                > as fidl::encoding::TypeMarker>::inline_size(
870                    decoder.context
871                );
872                if inlined != (member_inline_size <= 4) {
873                    return Err(fidl::Error::InvalidInlineBitInEnvelope);
874                }
875                let inner_offset;
876                let mut inner_depth = depth.clone();
877                if inlined {
878                    decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
879                    inner_offset = next_offset;
880                } else {
881                    inner_offset = decoder.out_of_line_offset(member_inline_size)?;
882                    inner_depth.increment()?;
883                }
884                let val_ref =
885                self.event.get_or_insert_with(|| fidl::new_empty!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect));
886                fidl::decode!(fidl::encoding::HandleType<fidl::Event, { fidl::ObjectType::EVENT.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, val_ref, decoder, inner_offset, inner_depth)?;
887                if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
888                {
889                    return Err(fidl::Error::InvalidNumBytesInEnvelope);
890                }
891                if handles_before != decoder.remaining_handles() + (num_handles as usize) {
892                    return Err(fidl::Error::InvalidNumHandlesInEnvelope);
893                }
894            }
895
896            next_offset += envelope_size;
897
898            // Decode the remaining unknown envelopes.
899            while next_offset < end_offset {
900                _next_ordinal_to_read += 1;
901                fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
902                next_offset += envelope_size;
903            }
904
905            Ok(())
906        }
907    }
908}