fidl_fuchsia_memory_sampler/
fidl_fuchsia_memory_sampler.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_sampler__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct SamplerMarker;
16
17impl fidl::endpoints::ProtocolMarker for SamplerMarker {
18    type Proxy = SamplerProxy;
19    type RequestStream = SamplerRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = SamplerSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.memory.sampler.Sampler";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for SamplerMarker {}
26
27pub trait SamplerProxyInterface: Send + Sync {
28    fn r#record_allocation(
29        &self,
30        payload: &SamplerRecordAllocationRequest,
31    ) -> Result<(), fidl::Error>;
32    fn r#record_deallocation(
33        &self,
34        payload: &SamplerRecordDeallocationRequest,
35    ) -> Result<(), fidl::Error>;
36    fn r#set_process_info(&self, payload: &SamplerSetProcessInfoRequest)
37    -> Result<(), fidl::Error>;
38}
39#[derive(Debug)]
40#[cfg(target_os = "fuchsia")]
41pub struct SamplerSynchronousProxy {
42    client: fidl::client::sync::Client,
43}
44
45#[cfg(target_os = "fuchsia")]
46impl fidl::endpoints::SynchronousProxy for SamplerSynchronousProxy {
47    type Proxy = SamplerProxy;
48    type Protocol = SamplerMarker;
49
50    fn from_channel(inner: fidl::Channel) -> Self {
51        Self::new(inner)
52    }
53
54    fn into_channel(self) -> fidl::Channel {
55        self.client.into_channel()
56    }
57
58    fn as_channel(&self) -> &fidl::Channel {
59        self.client.as_channel()
60    }
61}
62
63#[cfg(target_os = "fuchsia")]
64impl SamplerSynchronousProxy {
65    pub fn new(channel: fidl::Channel) -> Self {
66        let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
67        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
68    }
69
70    pub fn into_channel(self) -> fidl::Channel {
71        self.client.into_channel()
72    }
73
74    /// Waits until an event arrives and returns it. It is safe for other
75    /// threads to make concurrent requests while waiting for an event.
76    pub fn wait_for_event(
77        &self,
78        deadline: zx::MonotonicInstant,
79    ) -> Result<SamplerEvent, fidl::Error> {
80        SamplerEvent::decode(self.client.wait_for_event(deadline)?)
81    }
82
83    /// Record an allocation.
84    pub fn r#record_allocation(
85        &self,
86        mut payload: &SamplerRecordAllocationRequest,
87    ) -> Result<(), fidl::Error> {
88        self.client.send::<SamplerRecordAllocationRequest>(
89            payload,
90            0x6b0add9f7769824d,
91            fidl::encoding::DynamicFlags::FLEXIBLE,
92        )
93    }
94
95    /// Record a deallocation.
96    pub fn r#record_deallocation(
97        &self,
98        mut payload: &SamplerRecordDeallocationRequest,
99    ) -> Result<(), fidl::Error> {
100        self.client.send::<SamplerRecordDeallocationRequest>(
101            payload,
102            0x503bff5ec34dbeeb,
103            fidl::encoding::DynamicFlags::FLEXIBLE,
104        )
105    }
106
107    /// Communicate relevant process information to facilitate symbolization.
108    ///
109    /// If called several times, the last `process_name` prevails, but the
110    /// `module_map` is added to the existing map for the process. If a client
111    /// needs to send a `module_map` that does not fit in a single message, they
112    /// can split it and send it across several messages.
113    pub fn r#set_process_info(
114        &self,
115        mut payload: &SamplerSetProcessInfoRequest,
116    ) -> Result<(), fidl::Error> {
117        self.client.send::<SamplerSetProcessInfoRequest>(
118            payload,
119            0x68a0557106e51783,
120            fidl::encoding::DynamicFlags::FLEXIBLE,
121        )
122    }
123}
124
125#[cfg(target_os = "fuchsia")]
126impl From<SamplerSynchronousProxy> for zx::Handle {
127    fn from(value: SamplerSynchronousProxy) -> Self {
128        value.into_channel().into()
129    }
130}
131
132#[cfg(target_os = "fuchsia")]
133impl From<fidl::Channel> for SamplerSynchronousProxy {
134    fn from(value: fidl::Channel) -> Self {
135        Self::new(value)
136    }
137}
138
139#[cfg(target_os = "fuchsia")]
140impl fidl::endpoints::FromClient for SamplerSynchronousProxy {
141    type Protocol = SamplerMarker;
142
143    fn from_client(value: fidl::endpoints::ClientEnd<SamplerMarker>) -> Self {
144        Self::new(value.into_channel())
145    }
146}
147
148#[derive(Debug, Clone)]
149pub struct SamplerProxy {
150    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
151}
152
153impl fidl::endpoints::Proxy for SamplerProxy {
154    type Protocol = SamplerMarker;
155
156    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
157        Self::new(inner)
158    }
159
160    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
161        self.client.into_channel().map_err(|client| Self { client })
162    }
163
164    fn as_channel(&self) -> &::fidl::AsyncChannel {
165        self.client.as_channel()
166    }
167}
168
169impl SamplerProxy {
170    /// Create a new Proxy for fuchsia.memory.sampler/Sampler.
171    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
172        let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
173        Self { client: fidl::client::Client::new(channel, protocol_name) }
174    }
175
176    /// Get a Stream of events from the remote end of the protocol.
177    ///
178    /// # Panics
179    ///
180    /// Panics if the event stream was already taken.
181    pub fn take_event_stream(&self) -> SamplerEventStream {
182        SamplerEventStream { event_receiver: self.client.take_event_receiver() }
183    }
184
185    /// Record an allocation.
186    pub fn r#record_allocation(
187        &self,
188        mut payload: &SamplerRecordAllocationRequest,
189    ) -> Result<(), fidl::Error> {
190        SamplerProxyInterface::r#record_allocation(self, payload)
191    }
192
193    /// Record a deallocation.
194    pub fn r#record_deallocation(
195        &self,
196        mut payload: &SamplerRecordDeallocationRequest,
197    ) -> Result<(), fidl::Error> {
198        SamplerProxyInterface::r#record_deallocation(self, payload)
199    }
200
201    /// Communicate relevant process information to facilitate symbolization.
202    ///
203    /// If called several times, the last `process_name` prevails, but the
204    /// `module_map` is added to the existing map for the process. If a client
205    /// needs to send a `module_map` that does not fit in a single message, they
206    /// can split it and send it across several messages.
207    pub fn r#set_process_info(
208        &self,
209        mut payload: &SamplerSetProcessInfoRequest,
210    ) -> Result<(), fidl::Error> {
211        SamplerProxyInterface::r#set_process_info(self, payload)
212    }
213}
214
215impl SamplerProxyInterface for SamplerProxy {
216    fn r#record_allocation(
217        &self,
218        mut payload: &SamplerRecordAllocationRequest,
219    ) -> Result<(), fidl::Error> {
220        self.client.send::<SamplerRecordAllocationRequest>(
221            payload,
222            0x6b0add9f7769824d,
223            fidl::encoding::DynamicFlags::FLEXIBLE,
224        )
225    }
226
227    fn r#record_deallocation(
228        &self,
229        mut payload: &SamplerRecordDeallocationRequest,
230    ) -> Result<(), fidl::Error> {
231        self.client.send::<SamplerRecordDeallocationRequest>(
232            payload,
233            0x503bff5ec34dbeeb,
234            fidl::encoding::DynamicFlags::FLEXIBLE,
235        )
236    }
237
238    fn r#set_process_info(
239        &self,
240        mut payload: &SamplerSetProcessInfoRequest,
241    ) -> Result<(), fidl::Error> {
242        self.client.send::<SamplerSetProcessInfoRequest>(
243            payload,
244            0x68a0557106e51783,
245            fidl::encoding::DynamicFlags::FLEXIBLE,
246        )
247    }
248}
249
250pub struct SamplerEventStream {
251    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
252}
253
254impl std::marker::Unpin for SamplerEventStream {}
255
256impl futures::stream::FusedStream for SamplerEventStream {
257    fn is_terminated(&self) -> bool {
258        self.event_receiver.is_terminated()
259    }
260}
261
262impl futures::Stream for SamplerEventStream {
263    type Item = Result<SamplerEvent, fidl::Error>;
264
265    fn poll_next(
266        mut self: std::pin::Pin<&mut Self>,
267        cx: &mut std::task::Context<'_>,
268    ) -> std::task::Poll<Option<Self::Item>> {
269        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
270            &mut self.event_receiver,
271            cx
272        )?) {
273            Some(buf) => std::task::Poll::Ready(Some(SamplerEvent::decode(buf))),
274            None => std::task::Poll::Ready(None),
275        }
276    }
277}
278
279#[derive(Debug)]
280pub enum SamplerEvent {
281    #[non_exhaustive]
282    _UnknownEvent {
283        /// Ordinal of the event that was sent.
284        ordinal: u64,
285    },
286}
287
288impl SamplerEvent {
289    /// Decodes a message buffer as a [`SamplerEvent`].
290    fn decode(
291        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
292    ) -> Result<SamplerEvent, fidl::Error> {
293        let (bytes, _handles) = buf.split_mut();
294        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
295        debug_assert_eq!(tx_header.tx_id, 0);
296        match tx_header.ordinal {
297            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
298                Ok(SamplerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
299            }
300            _ => Err(fidl::Error::UnknownOrdinal {
301                ordinal: tx_header.ordinal,
302                protocol_name: <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
303            }),
304        }
305    }
306}
307
308/// A Stream of incoming requests for fuchsia.memory.sampler/Sampler.
309pub struct SamplerRequestStream {
310    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
311    is_terminated: bool,
312}
313
314impl std::marker::Unpin for SamplerRequestStream {}
315
316impl futures::stream::FusedStream for SamplerRequestStream {
317    fn is_terminated(&self) -> bool {
318        self.is_terminated
319    }
320}
321
322impl fidl::endpoints::RequestStream for SamplerRequestStream {
323    type Protocol = SamplerMarker;
324    type ControlHandle = SamplerControlHandle;
325
326    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
327        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
328    }
329
330    fn control_handle(&self) -> Self::ControlHandle {
331        SamplerControlHandle { inner: self.inner.clone() }
332    }
333
334    fn into_inner(
335        self,
336    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
337    {
338        (self.inner, self.is_terminated)
339    }
340
341    fn from_inner(
342        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
343        is_terminated: bool,
344    ) -> Self {
345        Self { inner, is_terminated }
346    }
347}
348
349impl futures::Stream for SamplerRequestStream {
350    type Item = Result<SamplerRequest, fidl::Error>;
351
352    fn poll_next(
353        mut self: std::pin::Pin<&mut Self>,
354        cx: &mut std::task::Context<'_>,
355    ) -> std::task::Poll<Option<Self::Item>> {
356        let this = &mut *self;
357        if this.inner.check_shutdown(cx) {
358            this.is_terminated = true;
359            return std::task::Poll::Ready(None);
360        }
361        if this.is_terminated {
362            panic!("polled SamplerRequestStream after completion");
363        }
364        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
365            |bytes, handles| {
366                match this.inner.channel().read_etc(cx, bytes, handles) {
367                    std::task::Poll::Ready(Ok(())) => {}
368                    std::task::Poll::Pending => return std::task::Poll::Pending,
369                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
370                        this.is_terminated = true;
371                        return std::task::Poll::Ready(None);
372                    }
373                    std::task::Poll::Ready(Err(e)) => {
374                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
375                            e.into(),
376                        ))));
377                    }
378                }
379
380                // A message has been received from the channel
381                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
382
383                std::task::Poll::Ready(Some(match header.ordinal {
384                    0x6b0add9f7769824d => {
385                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
386                        let mut req = fidl::new_empty!(
387                            SamplerRecordAllocationRequest,
388                            fidl::encoding::DefaultFuchsiaResourceDialect
389                        );
390                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordAllocationRequest>(&header, _body_bytes, handles, &mut req)?;
391                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
392                        Ok(SamplerRequest::RecordAllocation { payload: req, control_handle })
393                    }
394                    0x503bff5ec34dbeeb => {
395                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
396                        let mut req = fidl::new_empty!(
397                            SamplerRecordDeallocationRequest,
398                            fidl::encoding::DefaultFuchsiaResourceDialect
399                        );
400                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordDeallocationRequest>(&header, _body_bytes, handles, &mut req)?;
401                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
402                        Ok(SamplerRequest::RecordDeallocation { payload: req, control_handle })
403                    }
404                    0x68a0557106e51783 => {
405                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
406                        let mut req = fidl::new_empty!(
407                            SamplerSetProcessInfoRequest,
408                            fidl::encoding::DefaultFuchsiaResourceDialect
409                        );
410                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerSetProcessInfoRequest>(&header, _body_bytes, handles, &mut req)?;
411                        let control_handle = SamplerControlHandle { inner: this.inner.clone() };
412                        Ok(SamplerRequest::SetProcessInfo { payload: req, control_handle })
413                    }
414                    _ if header.tx_id == 0
415                        && header
416                            .dynamic_flags()
417                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
418                    {
419                        Ok(SamplerRequest::_UnknownMethod {
420                            ordinal: header.ordinal,
421                            control_handle: SamplerControlHandle { inner: this.inner.clone() },
422                            method_type: fidl::MethodType::OneWay,
423                        })
424                    }
425                    _ if header
426                        .dynamic_flags()
427                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
428                    {
429                        this.inner.send_framework_err(
430                            fidl::encoding::FrameworkErr::UnknownMethod,
431                            header.tx_id,
432                            header.ordinal,
433                            header.dynamic_flags(),
434                            (bytes, handles),
435                        )?;
436                        Ok(SamplerRequest::_UnknownMethod {
437                            ordinal: header.ordinal,
438                            control_handle: SamplerControlHandle { inner: this.inner.clone() },
439                            method_type: fidl::MethodType::TwoWay,
440                        })
441                    }
442                    _ => Err(fidl::Error::UnknownOrdinal {
443                        ordinal: header.ordinal,
444                        protocol_name:
445                            <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
446                    }),
447                }))
448            },
449        )
450    }
451}
452
453/// Interface used to exfiltrate process allocation information.
454#[derive(Debug)]
455pub enum SamplerRequest {
456    /// Record an allocation.
457    RecordAllocation {
458        payload: SamplerRecordAllocationRequest,
459        control_handle: SamplerControlHandle,
460    },
461    /// Record a deallocation.
462    RecordDeallocation {
463        payload: SamplerRecordDeallocationRequest,
464        control_handle: SamplerControlHandle,
465    },
466    /// Communicate relevant process information to facilitate symbolization.
467    ///
468    /// If called several times, the last `process_name` prevails, but the
469    /// `module_map` is added to the existing map for the process. If a client
470    /// needs to send a `module_map` that does not fit in a single message, they
471    /// can split it and send it across several messages.
472    SetProcessInfo { payload: SamplerSetProcessInfoRequest, control_handle: SamplerControlHandle },
473    /// An interaction was received which does not match any known method.
474    #[non_exhaustive]
475    _UnknownMethod {
476        /// Ordinal of the method that was called.
477        ordinal: u64,
478        control_handle: SamplerControlHandle,
479        method_type: fidl::MethodType,
480    },
481}
482
483impl SamplerRequest {
484    #[allow(irrefutable_let_patterns)]
485    pub fn into_record_allocation(
486        self,
487    ) -> Option<(SamplerRecordAllocationRequest, SamplerControlHandle)> {
488        if let SamplerRequest::RecordAllocation { payload, control_handle } = self {
489            Some((payload, control_handle))
490        } else {
491            None
492        }
493    }
494
495    #[allow(irrefutable_let_patterns)]
496    pub fn into_record_deallocation(
497        self,
498    ) -> Option<(SamplerRecordDeallocationRequest, SamplerControlHandle)> {
499        if let SamplerRequest::RecordDeallocation { payload, control_handle } = self {
500            Some((payload, control_handle))
501        } else {
502            None
503        }
504    }
505
506    #[allow(irrefutable_let_patterns)]
507    pub fn into_set_process_info(
508        self,
509    ) -> Option<(SamplerSetProcessInfoRequest, SamplerControlHandle)> {
510        if let SamplerRequest::SetProcessInfo { payload, control_handle } = self {
511            Some((payload, control_handle))
512        } else {
513            None
514        }
515    }
516
517    /// Name of the method defined in FIDL
518    pub fn method_name(&self) -> &'static str {
519        match *self {
520            SamplerRequest::RecordAllocation { .. } => "record_allocation",
521            SamplerRequest::RecordDeallocation { .. } => "record_deallocation",
522            SamplerRequest::SetProcessInfo { .. } => "set_process_info",
523            SamplerRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
524                "unknown one-way method"
525            }
526            SamplerRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
527                "unknown two-way method"
528            }
529        }
530    }
531}
532
533#[derive(Debug, Clone)]
534pub struct SamplerControlHandle {
535    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
536}
537
538impl fidl::endpoints::ControlHandle for SamplerControlHandle {
539    fn shutdown(&self) {
540        self.inner.shutdown()
541    }
542    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
543        self.inner.shutdown_with_epitaph(status)
544    }
545
546    fn is_closed(&self) -> bool {
547        self.inner.channel().is_closed()
548    }
549    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
550        self.inner.channel().on_closed()
551    }
552
553    #[cfg(target_os = "fuchsia")]
554    fn signal_peer(
555        &self,
556        clear_mask: zx::Signals,
557        set_mask: zx::Signals,
558    ) -> Result<(), zx_status::Status> {
559        use fidl::Peered;
560        self.inner.channel().signal_peer(clear_mask, set_mask)
561    }
562}
563
564impl SamplerControlHandle {}
565
566mod internal {
567    use super::*;
568}