fidl_fuchsia_memory_attribution_plugin/
fidl_fuchsia_memory_attribution_plugin.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_memory_attribution_plugin__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct MemoryMonitorGetSnapshotRequest {
16    pub snapshot: fidl::Socket,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for MemoryMonitorGetSnapshotRequest
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct MemoryMonitorMarker;
26
27impl fidl::endpoints::ProtocolMarker for MemoryMonitorMarker {
28    type Proxy = MemoryMonitorProxy;
29    type RequestStream = MemoryMonitorRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = MemoryMonitorSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "fuchsia.memory.attribution.plugin.MemoryMonitor";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for MemoryMonitorMarker {}
36
37pub trait MemoryMonitorProxyInterface: Send + Sync {
38    fn r#get_snapshot(&self, snapshot: fidl::Socket) -> Result<(), fidl::Error>;
39}
40#[derive(Debug)]
41#[cfg(target_os = "fuchsia")]
42pub struct MemoryMonitorSynchronousProxy {
43    client: fidl::client::sync::Client,
44}
45
46#[cfg(target_os = "fuchsia")]
47impl fidl::endpoints::SynchronousProxy for MemoryMonitorSynchronousProxy {
48    type Proxy = MemoryMonitorProxy;
49    type Protocol = MemoryMonitorMarker;
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 MemoryMonitorSynchronousProxy {
66    pub fn new(channel: fidl::Channel) -> Self {
67        let protocol_name = <MemoryMonitorMarker 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<MemoryMonitorEvent, fidl::Error> {
81        MemoryMonitorEvent::decode(self.client.wait_for_event(deadline)?)
82    }
83
84    pub fn r#get_snapshot(&self, mut snapshot: fidl::Socket) -> Result<(), fidl::Error> {
85        self.client.send::<MemoryMonitorGetSnapshotRequest>(
86            (snapshot,),
87            0x3af6caa4c6a6fdb7,
88            fidl::encoding::DynamicFlags::FLEXIBLE,
89        )
90    }
91}
92
93#[cfg(target_os = "fuchsia")]
94impl From<MemoryMonitorSynchronousProxy> for zx::Handle {
95    fn from(value: MemoryMonitorSynchronousProxy) -> Self {
96        value.into_channel().into()
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl From<fidl::Channel> for MemoryMonitorSynchronousProxy {
102    fn from(value: fidl::Channel) -> Self {
103        Self::new(value)
104    }
105}
106
107#[cfg(target_os = "fuchsia")]
108impl fidl::endpoints::FromClient for MemoryMonitorSynchronousProxy {
109    type Protocol = MemoryMonitorMarker;
110
111    fn from_client(value: fidl::endpoints::ClientEnd<MemoryMonitorMarker>) -> Self {
112        Self::new(value.into_channel())
113    }
114}
115
116#[derive(Debug, Clone)]
117pub struct MemoryMonitorProxy {
118    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
119}
120
121impl fidl::endpoints::Proxy for MemoryMonitorProxy {
122    type Protocol = MemoryMonitorMarker;
123
124    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
125        Self::new(inner)
126    }
127
128    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
129        self.client.into_channel().map_err(|client| Self { client })
130    }
131
132    fn as_channel(&self) -> &::fidl::AsyncChannel {
133        self.client.as_channel()
134    }
135}
136
137impl MemoryMonitorProxy {
138    /// Create a new Proxy for fuchsia.memory.attribution.plugin/MemoryMonitor.
139    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
140        let protocol_name = <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
141        Self { client: fidl::client::Client::new(channel, protocol_name) }
142    }
143
144    /// Get a Stream of events from the remote end of the protocol.
145    ///
146    /// # Panics
147    ///
148    /// Panics if the event stream was already taken.
149    pub fn take_event_stream(&self) -> MemoryMonitorEventStream {
150        MemoryMonitorEventStream { event_receiver: self.client.take_event_receiver() }
151    }
152
153    pub fn r#get_snapshot(&self, mut snapshot: fidl::Socket) -> Result<(), fidl::Error> {
154        MemoryMonitorProxyInterface::r#get_snapshot(self, snapshot)
155    }
156}
157
158impl MemoryMonitorProxyInterface for MemoryMonitorProxy {
159    fn r#get_snapshot(&self, mut snapshot: fidl::Socket) -> Result<(), fidl::Error> {
160        self.client.send::<MemoryMonitorGetSnapshotRequest>(
161            (snapshot,),
162            0x3af6caa4c6a6fdb7,
163            fidl::encoding::DynamicFlags::FLEXIBLE,
164        )
165    }
166}
167
168pub struct MemoryMonitorEventStream {
169    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
170}
171
172impl std::marker::Unpin for MemoryMonitorEventStream {}
173
174impl futures::stream::FusedStream for MemoryMonitorEventStream {
175    fn is_terminated(&self) -> bool {
176        self.event_receiver.is_terminated()
177    }
178}
179
180impl futures::Stream for MemoryMonitorEventStream {
181    type Item = Result<MemoryMonitorEvent, fidl::Error>;
182
183    fn poll_next(
184        mut self: std::pin::Pin<&mut Self>,
185        cx: &mut std::task::Context<'_>,
186    ) -> std::task::Poll<Option<Self::Item>> {
187        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
188            &mut self.event_receiver,
189            cx
190        )?) {
191            Some(buf) => std::task::Poll::Ready(Some(MemoryMonitorEvent::decode(buf))),
192            None => std::task::Poll::Ready(None),
193        }
194    }
195}
196
197#[derive(Debug)]
198pub enum MemoryMonitorEvent {
199    #[non_exhaustive]
200    _UnknownEvent {
201        /// Ordinal of the event that was sent.
202        ordinal: u64,
203    },
204}
205
206impl MemoryMonitorEvent {
207    /// Decodes a message buffer as a [`MemoryMonitorEvent`].
208    fn decode(
209        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
210    ) -> Result<MemoryMonitorEvent, fidl::Error> {
211        let (bytes, _handles) = buf.split_mut();
212        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
213        debug_assert_eq!(tx_header.tx_id, 0);
214        match tx_header.ordinal {
215            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
216                Ok(MemoryMonitorEvent::_UnknownEvent { ordinal: tx_header.ordinal })
217            }
218            _ => Err(fidl::Error::UnknownOrdinal {
219                ordinal: tx_header.ordinal,
220                protocol_name: <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
221            }),
222        }
223    }
224}
225
226/// A Stream of incoming requests for fuchsia.memory.attribution.plugin/MemoryMonitor.
227pub struct MemoryMonitorRequestStream {
228    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
229    is_terminated: bool,
230}
231
232impl std::marker::Unpin for MemoryMonitorRequestStream {}
233
234impl futures::stream::FusedStream for MemoryMonitorRequestStream {
235    fn is_terminated(&self) -> bool {
236        self.is_terminated
237    }
238}
239
240impl fidl::endpoints::RequestStream for MemoryMonitorRequestStream {
241    type Protocol = MemoryMonitorMarker;
242    type ControlHandle = MemoryMonitorControlHandle;
243
244    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
245        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
246    }
247
248    fn control_handle(&self) -> Self::ControlHandle {
249        MemoryMonitorControlHandle { inner: self.inner.clone() }
250    }
251
252    fn into_inner(
253        self,
254    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
255    {
256        (self.inner, self.is_terminated)
257    }
258
259    fn from_inner(
260        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
261        is_terminated: bool,
262    ) -> Self {
263        Self { inner, is_terminated }
264    }
265}
266
267impl futures::Stream for MemoryMonitorRequestStream {
268    type Item = Result<MemoryMonitorRequest, fidl::Error>;
269
270    fn poll_next(
271        mut self: std::pin::Pin<&mut Self>,
272        cx: &mut std::task::Context<'_>,
273    ) -> std::task::Poll<Option<Self::Item>> {
274        let this = &mut *self;
275        if this.inner.check_shutdown(cx) {
276            this.is_terminated = true;
277            return std::task::Poll::Ready(None);
278        }
279        if this.is_terminated {
280            panic!("polled MemoryMonitorRequestStream after completion");
281        }
282        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
283            |bytes, handles| {
284                match this.inner.channel().read_etc(cx, bytes, handles) {
285                    std::task::Poll::Ready(Ok(())) => {}
286                    std::task::Poll::Pending => return std::task::Poll::Pending,
287                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
288                        this.is_terminated = true;
289                        return std::task::Poll::Ready(None);
290                    }
291                    std::task::Poll::Ready(Err(e)) => {
292                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
293                            e.into(),
294                        ))))
295                    }
296                }
297
298                // A message has been received from the channel
299                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
300
301                std::task::Poll::Ready(Some(match header.ordinal {
302                    0x3af6caa4c6a6fdb7 => {
303                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
304                        let mut req = fidl::new_empty!(
305                            MemoryMonitorGetSnapshotRequest,
306                            fidl::encoding::DefaultFuchsiaResourceDialect
307                        );
308                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MemoryMonitorGetSnapshotRequest>(&header, _body_bytes, handles, &mut req)?;
309                        let control_handle =
310                            MemoryMonitorControlHandle { inner: this.inner.clone() };
311                        Ok(MemoryMonitorRequest::GetSnapshot {
312                            snapshot: req.snapshot,
313
314                            control_handle,
315                        })
316                    }
317                    _ if header.tx_id == 0
318                        && header
319                            .dynamic_flags()
320                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
321                    {
322                        Ok(MemoryMonitorRequest::_UnknownMethod {
323                            ordinal: header.ordinal,
324                            control_handle: MemoryMonitorControlHandle {
325                                inner: this.inner.clone(),
326                            },
327                            method_type: fidl::MethodType::OneWay,
328                        })
329                    }
330                    _ if header
331                        .dynamic_flags()
332                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
333                    {
334                        this.inner.send_framework_err(
335                            fidl::encoding::FrameworkErr::UnknownMethod,
336                            header.tx_id,
337                            header.ordinal,
338                            header.dynamic_flags(),
339                            (bytes, handles),
340                        )?;
341                        Ok(MemoryMonitorRequest::_UnknownMethod {
342                            ordinal: header.ordinal,
343                            control_handle: MemoryMonitorControlHandle {
344                                inner: this.inner.clone(),
345                            },
346                            method_type: fidl::MethodType::TwoWay,
347                        })
348                    }
349                    _ => Err(fidl::Error::UnknownOrdinal {
350                        ordinal: header.ordinal,
351                        protocol_name:
352                            <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
353                    }),
354                }))
355            },
356        )
357    }
358}
359
360#[derive(Debug)]
361pub enum MemoryMonitorRequest {
362    GetSnapshot {
363        snapshot: fidl::Socket,
364        control_handle: MemoryMonitorControlHandle,
365    },
366    /// An interaction was received which does not match any known method.
367    #[non_exhaustive]
368    _UnknownMethod {
369        /// Ordinal of the method that was called.
370        ordinal: u64,
371        control_handle: MemoryMonitorControlHandle,
372        method_type: fidl::MethodType,
373    },
374}
375
376impl MemoryMonitorRequest {
377    #[allow(irrefutable_let_patterns)]
378    pub fn into_get_snapshot(self) -> Option<(fidl::Socket, MemoryMonitorControlHandle)> {
379        if let MemoryMonitorRequest::GetSnapshot { snapshot, control_handle } = self {
380            Some((snapshot, control_handle))
381        } else {
382            None
383        }
384    }
385
386    /// Name of the method defined in FIDL
387    pub fn method_name(&self) -> &'static str {
388        match *self {
389            MemoryMonitorRequest::GetSnapshot { .. } => "get_snapshot",
390            MemoryMonitorRequest::_UnknownMethod {
391                method_type: fidl::MethodType::OneWay, ..
392            } => "unknown one-way method",
393            MemoryMonitorRequest::_UnknownMethod {
394                method_type: fidl::MethodType::TwoWay, ..
395            } => "unknown two-way method",
396        }
397    }
398}
399
400#[derive(Debug, Clone)]
401pub struct MemoryMonitorControlHandle {
402    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
403}
404
405impl fidl::endpoints::ControlHandle for MemoryMonitorControlHandle {
406    fn shutdown(&self) {
407        self.inner.shutdown()
408    }
409    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
410        self.inner.shutdown_with_epitaph(status)
411    }
412
413    fn is_closed(&self) -> bool {
414        self.inner.channel().is_closed()
415    }
416    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
417        self.inner.channel().on_closed()
418    }
419
420    #[cfg(target_os = "fuchsia")]
421    fn signal_peer(
422        &self,
423        clear_mask: zx::Signals,
424        set_mask: zx::Signals,
425    ) -> Result<(), zx_status::Status> {
426        use fidl::Peered;
427        self.inner.channel().signal_peer(clear_mask, set_mask)
428    }
429}
430
431impl MemoryMonitorControlHandle {}
432
433mod internal {
434    use super::*;
435
436    impl fidl::encoding::ResourceTypeMarker for MemoryMonitorGetSnapshotRequest {
437        type Borrowed<'a> = &'a mut Self;
438        fn take_or_borrow<'a>(
439            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
440        ) -> Self::Borrowed<'a> {
441            value
442        }
443    }
444
445    unsafe impl fidl::encoding::TypeMarker for MemoryMonitorGetSnapshotRequest {
446        type Owned = Self;
447
448        #[inline(always)]
449        fn inline_align(_context: fidl::encoding::Context) -> usize {
450            4
451        }
452
453        #[inline(always)]
454        fn inline_size(_context: fidl::encoding::Context) -> usize {
455            4
456        }
457    }
458
459    unsafe impl
460        fidl::encoding::Encode<
461            MemoryMonitorGetSnapshotRequest,
462            fidl::encoding::DefaultFuchsiaResourceDialect,
463        > for &mut MemoryMonitorGetSnapshotRequest
464    {
465        #[inline]
466        unsafe fn encode(
467            self,
468            encoder: &mut fidl::encoding::Encoder<
469                '_,
470                fidl::encoding::DefaultFuchsiaResourceDialect,
471            >,
472            offset: usize,
473            _depth: fidl::encoding::Depth,
474        ) -> fidl::Result<()> {
475            encoder.debug_check_bounds::<MemoryMonitorGetSnapshotRequest>(offset);
476            // Delegate to tuple encoding.
477            fidl::encoding::Encode::<
478                MemoryMonitorGetSnapshotRequest,
479                fidl::encoding::DefaultFuchsiaResourceDialect,
480            >::encode(
481                (<fidl::encoding::HandleType<
482                    fidl::Socket,
483                    { fidl::ObjectType::SOCKET.into_raw() },
484                    2147483648,
485                > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
486                    &mut self.snapshot
487                ),),
488                encoder,
489                offset,
490                _depth,
491            )
492        }
493    }
494    unsafe impl<
495            T0: fidl::encoding::Encode<
496                fidl::encoding::HandleType<
497                    fidl::Socket,
498                    { fidl::ObjectType::SOCKET.into_raw() },
499                    2147483648,
500                >,
501                fidl::encoding::DefaultFuchsiaResourceDialect,
502            >,
503        >
504        fidl::encoding::Encode<
505            MemoryMonitorGetSnapshotRequest,
506            fidl::encoding::DefaultFuchsiaResourceDialect,
507        > for (T0,)
508    {
509        #[inline]
510        unsafe fn encode(
511            self,
512            encoder: &mut fidl::encoding::Encoder<
513                '_,
514                fidl::encoding::DefaultFuchsiaResourceDialect,
515            >,
516            offset: usize,
517            depth: fidl::encoding::Depth,
518        ) -> fidl::Result<()> {
519            encoder.debug_check_bounds::<MemoryMonitorGetSnapshotRequest>(offset);
520            // Zero out padding regions. There's no need to apply masks
521            // because the unmasked parts will be overwritten by fields.
522            // Write the fields.
523            self.0.encode(encoder, offset + 0, depth)?;
524            Ok(())
525        }
526    }
527
528    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
529        for MemoryMonitorGetSnapshotRequest
530    {
531        #[inline(always)]
532        fn new_empty() -> Self {
533            Self {
534                snapshot: fidl::new_empty!(fidl::encoding::HandleType<fidl::Socket, { fidl::ObjectType::SOCKET.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
535            }
536        }
537
538        #[inline]
539        unsafe fn decode(
540            &mut self,
541            decoder: &mut fidl::encoding::Decoder<
542                '_,
543                fidl::encoding::DefaultFuchsiaResourceDialect,
544            >,
545            offset: usize,
546            _depth: fidl::encoding::Depth,
547        ) -> fidl::Result<()> {
548            decoder.debug_check_bounds::<Self>(offset);
549            // Verify that padding bytes are zero.
550            fidl::decode!(fidl::encoding::HandleType<fidl::Socket, { fidl::ObjectType::SOCKET.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.snapshot, decoder, offset + 0, _depth)?;
551            Ok(())
552        }
553    }
554}