1#![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 Self { client: fidl::client::sync::Client::new(channel) }
67 }
68
69 pub fn into_channel(self) -> fidl::Channel {
70 self.client.into_channel()
71 }
72
73 pub fn wait_for_event(
76 &self,
77 deadline: zx::MonotonicInstant,
78 ) -> Result<SamplerEvent, fidl::Error> {
79 SamplerEvent::decode(self.client.wait_for_event::<SamplerMarker>(deadline)?)
80 }
81
82 pub fn r#record_allocation(
84 &self,
85 mut payload: &SamplerRecordAllocationRequest,
86 ) -> Result<(), fidl::Error> {
87 self.client.send::<SamplerRecordAllocationRequest>(
88 payload,
89 0x6b0add9f7769824d,
90 fidl::encoding::DynamicFlags::FLEXIBLE,
91 )
92 }
93
94 pub fn r#record_deallocation(
96 &self,
97 mut payload: &SamplerRecordDeallocationRequest,
98 ) -> Result<(), fidl::Error> {
99 self.client.send::<SamplerRecordDeallocationRequest>(
100 payload,
101 0x503bff5ec34dbeeb,
102 fidl::encoding::DynamicFlags::FLEXIBLE,
103 )
104 }
105
106 pub fn r#set_process_info(
113 &self,
114 mut payload: &SamplerSetProcessInfoRequest,
115 ) -> Result<(), fidl::Error> {
116 self.client.send::<SamplerSetProcessInfoRequest>(
117 payload,
118 0x68a0557106e51783,
119 fidl::encoding::DynamicFlags::FLEXIBLE,
120 )
121 }
122}
123
124#[cfg(target_os = "fuchsia")]
125impl From<SamplerSynchronousProxy> for zx::NullableHandle {
126 fn from(value: SamplerSynchronousProxy) -> Self {
127 value.into_channel().into()
128 }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<fidl::Channel> for SamplerSynchronousProxy {
133 fn from(value: fidl::Channel) -> Self {
134 Self::new(value)
135 }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl fidl::endpoints::FromClient for SamplerSynchronousProxy {
140 type Protocol = SamplerMarker;
141
142 fn from_client(value: fidl::endpoints::ClientEnd<SamplerMarker>) -> Self {
143 Self::new(value.into_channel())
144 }
145}
146
147#[derive(Debug, Clone)]
148pub struct SamplerProxy {
149 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
150}
151
152impl fidl::endpoints::Proxy for SamplerProxy {
153 type Protocol = SamplerMarker;
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 SamplerProxy {
169 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
171 let protocol_name = <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
172 Self { client: fidl::client::Client::new(channel, protocol_name) }
173 }
174
175 pub fn take_event_stream(&self) -> SamplerEventStream {
181 SamplerEventStream { event_receiver: self.client.take_event_receiver() }
182 }
183
184 pub fn r#record_allocation(
186 &self,
187 mut payload: &SamplerRecordAllocationRequest,
188 ) -> Result<(), fidl::Error> {
189 SamplerProxyInterface::r#record_allocation(self, payload)
190 }
191
192 pub fn r#record_deallocation(
194 &self,
195 mut payload: &SamplerRecordDeallocationRequest,
196 ) -> Result<(), fidl::Error> {
197 SamplerProxyInterface::r#record_deallocation(self, payload)
198 }
199
200 pub fn r#set_process_info(
207 &self,
208 mut payload: &SamplerSetProcessInfoRequest,
209 ) -> Result<(), fidl::Error> {
210 SamplerProxyInterface::r#set_process_info(self, payload)
211 }
212}
213
214impl SamplerProxyInterface for SamplerProxy {
215 fn r#record_allocation(
216 &self,
217 mut payload: &SamplerRecordAllocationRequest,
218 ) -> Result<(), fidl::Error> {
219 self.client.send::<SamplerRecordAllocationRequest>(
220 payload,
221 0x6b0add9f7769824d,
222 fidl::encoding::DynamicFlags::FLEXIBLE,
223 )
224 }
225
226 fn r#record_deallocation(
227 &self,
228 mut payload: &SamplerRecordDeallocationRequest,
229 ) -> Result<(), fidl::Error> {
230 self.client.send::<SamplerRecordDeallocationRequest>(
231 payload,
232 0x503bff5ec34dbeeb,
233 fidl::encoding::DynamicFlags::FLEXIBLE,
234 )
235 }
236
237 fn r#set_process_info(
238 &self,
239 mut payload: &SamplerSetProcessInfoRequest,
240 ) -> Result<(), fidl::Error> {
241 self.client.send::<SamplerSetProcessInfoRequest>(
242 payload,
243 0x68a0557106e51783,
244 fidl::encoding::DynamicFlags::FLEXIBLE,
245 )
246 }
247}
248
249pub struct SamplerEventStream {
250 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
251}
252
253impl std::marker::Unpin for SamplerEventStream {}
254
255impl futures::stream::FusedStream for SamplerEventStream {
256 fn is_terminated(&self) -> bool {
257 self.event_receiver.is_terminated()
258 }
259}
260
261impl futures::Stream for SamplerEventStream {
262 type Item = Result<SamplerEvent, fidl::Error>;
263
264 fn poll_next(
265 mut self: std::pin::Pin<&mut Self>,
266 cx: &mut std::task::Context<'_>,
267 ) -> std::task::Poll<Option<Self::Item>> {
268 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
269 &mut self.event_receiver,
270 cx
271 )?) {
272 Some(buf) => std::task::Poll::Ready(Some(SamplerEvent::decode(buf))),
273 None => std::task::Poll::Ready(None),
274 }
275 }
276}
277
278#[derive(Debug)]
279pub enum SamplerEvent {
280 #[non_exhaustive]
281 _UnknownEvent {
282 ordinal: u64,
284 },
285}
286
287impl SamplerEvent {
288 fn decode(
290 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
291 ) -> Result<SamplerEvent, fidl::Error> {
292 let (bytes, _handles) = buf.split_mut();
293 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
294 debug_assert_eq!(tx_header.tx_id, 0);
295 match tx_header.ordinal {
296 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
297 Ok(SamplerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
298 }
299 _ => Err(fidl::Error::UnknownOrdinal {
300 ordinal: tx_header.ordinal,
301 protocol_name: <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
302 }),
303 }
304 }
305}
306
307pub struct SamplerRequestStream {
309 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
310 is_terminated: bool,
311}
312
313impl std::marker::Unpin for SamplerRequestStream {}
314
315impl futures::stream::FusedStream for SamplerRequestStream {
316 fn is_terminated(&self) -> bool {
317 self.is_terminated
318 }
319}
320
321impl fidl::endpoints::RequestStream for SamplerRequestStream {
322 type Protocol = SamplerMarker;
323 type ControlHandle = SamplerControlHandle;
324
325 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
326 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
327 }
328
329 fn control_handle(&self) -> Self::ControlHandle {
330 SamplerControlHandle { inner: self.inner.clone() }
331 }
332
333 fn into_inner(
334 self,
335 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
336 {
337 (self.inner, self.is_terminated)
338 }
339
340 fn from_inner(
341 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
342 is_terminated: bool,
343 ) -> Self {
344 Self { inner, is_terminated }
345 }
346}
347
348impl futures::Stream for SamplerRequestStream {
349 type Item = Result<SamplerRequest, fidl::Error>;
350
351 fn poll_next(
352 mut self: std::pin::Pin<&mut Self>,
353 cx: &mut std::task::Context<'_>,
354 ) -> std::task::Poll<Option<Self::Item>> {
355 let this = &mut *self;
356 if this.inner.check_shutdown(cx) {
357 this.is_terminated = true;
358 return std::task::Poll::Ready(None);
359 }
360 if this.is_terminated {
361 panic!("polled SamplerRequestStream after completion");
362 }
363 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
364 |bytes, handles| {
365 match this.inner.channel().read_etc(cx, bytes, handles) {
366 std::task::Poll::Ready(Ok(())) => {}
367 std::task::Poll::Pending => return std::task::Poll::Pending,
368 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
369 this.is_terminated = true;
370 return std::task::Poll::Ready(None);
371 }
372 std::task::Poll::Ready(Err(e)) => {
373 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
374 e.into(),
375 ))));
376 }
377 }
378
379 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
381
382 std::task::Poll::Ready(Some(match header.ordinal {
383 0x6b0add9f7769824d => {
384 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
385 let mut req = fidl::new_empty!(
386 SamplerRecordAllocationRequest,
387 fidl::encoding::DefaultFuchsiaResourceDialect
388 );
389 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordAllocationRequest>(&header, _body_bytes, handles, &mut req)?;
390 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
391 Ok(SamplerRequest::RecordAllocation { payload: req, control_handle })
392 }
393 0x503bff5ec34dbeeb => {
394 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
395 let mut req = fidl::new_empty!(
396 SamplerRecordDeallocationRequest,
397 fidl::encoding::DefaultFuchsiaResourceDialect
398 );
399 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerRecordDeallocationRequest>(&header, _body_bytes, handles, &mut req)?;
400 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
401 Ok(SamplerRequest::RecordDeallocation { payload: req, control_handle })
402 }
403 0x68a0557106e51783 => {
404 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
405 let mut req = fidl::new_empty!(
406 SamplerSetProcessInfoRequest,
407 fidl::encoding::DefaultFuchsiaResourceDialect
408 );
409 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<SamplerSetProcessInfoRequest>(&header, _body_bytes, handles, &mut req)?;
410 let control_handle = SamplerControlHandle { inner: this.inner.clone() };
411 Ok(SamplerRequest::SetProcessInfo { payload: req, control_handle })
412 }
413 _ if header.tx_id == 0
414 && header
415 .dynamic_flags()
416 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
417 {
418 Ok(SamplerRequest::_UnknownMethod {
419 ordinal: header.ordinal,
420 control_handle: SamplerControlHandle { inner: this.inner.clone() },
421 method_type: fidl::MethodType::OneWay,
422 })
423 }
424 _ if header
425 .dynamic_flags()
426 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
427 {
428 this.inner.send_framework_err(
429 fidl::encoding::FrameworkErr::UnknownMethod,
430 header.tx_id,
431 header.ordinal,
432 header.dynamic_flags(),
433 (bytes, handles),
434 )?;
435 Ok(SamplerRequest::_UnknownMethod {
436 ordinal: header.ordinal,
437 control_handle: SamplerControlHandle { inner: this.inner.clone() },
438 method_type: fidl::MethodType::TwoWay,
439 })
440 }
441 _ => Err(fidl::Error::UnknownOrdinal {
442 ordinal: header.ordinal,
443 protocol_name:
444 <SamplerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
445 }),
446 }))
447 },
448 )
449 }
450}
451
452#[derive(Debug)]
454pub enum SamplerRequest {
455 RecordAllocation {
457 payload: SamplerRecordAllocationRequest,
458 control_handle: SamplerControlHandle,
459 },
460 RecordDeallocation {
462 payload: SamplerRecordDeallocationRequest,
463 control_handle: SamplerControlHandle,
464 },
465 SetProcessInfo { payload: SamplerSetProcessInfoRequest, control_handle: SamplerControlHandle },
472 #[non_exhaustive]
474 _UnknownMethod {
475 ordinal: u64,
477 control_handle: SamplerControlHandle,
478 method_type: fidl::MethodType,
479 },
480}
481
482impl SamplerRequest {
483 #[allow(irrefutable_let_patterns)]
484 pub fn into_record_allocation(
485 self,
486 ) -> Option<(SamplerRecordAllocationRequest, SamplerControlHandle)> {
487 if let SamplerRequest::RecordAllocation { payload, control_handle } = self {
488 Some((payload, control_handle))
489 } else {
490 None
491 }
492 }
493
494 #[allow(irrefutable_let_patterns)]
495 pub fn into_record_deallocation(
496 self,
497 ) -> Option<(SamplerRecordDeallocationRequest, SamplerControlHandle)> {
498 if let SamplerRequest::RecordDeallocation { payload, control_handle } = self {
499 Some((payload, control_handle))
500 } else {
501 None
502 }
503 }
504
505 #[allow(irrefutable_let_patterns)]
506 pub fn into_set_process_info(
507 self,
508 ) -> Option<(SamplerSetProcessInfoRequest, SamplerControlHandle)> {
509 if let SamplerRequest::SetProcessInfo { payload, control_handle } = self {
510 Some((payload, control_handle))
511 } else {
512 None
513 }
514 }
515
516 pub fn method_name(&self) -> &'static str {
518 match *self {
519 SamplerRequest::RecordAllocation { .. } => "record_allocation",
520 SamplerRequest::RecordDeallocation { .. } => "record_deallocation",
521 SamplerRequest::SetProcessInfo { .. } => "set_process_info",
522 SamplerRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
523 "unknown one-way method"
524 }
525 SamplerRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
526 "unknown two-way method"
527 }
528 }
529 }
530}
531
532#[derive(Debug, Clone)]
533pub struct SamplerControlHandle {
534 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
535}
536
537impl fidl::endpoints::ControlHandle for SamplerControlHandle {
538 fn shutdown(&self) {
539 self.inner.shutdown()
540 }
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}