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_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 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#[derive(Debug, Clone)]
108pub struct MemoryMonitorProxy {
109 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
110}
111
112impl fidl::endpoints::Proxy for MemoryMonitorProxy {
113 type Protocol = MemoryMonitorMarker;
114
115 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
116 Self::new(inner)
117 }
118
119 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
120 self.client.into_channel().map_err(|client| Self { client })
121 }
122
123 fn as_channel(&self) -> &::fidl::AsyncChannel {
124 self.client.as_channel()
125 }
126}
127
128impl MemoryMonitorProxy {
129 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
131 let protocol_name = <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
132 Self { client: fidl::client::Client::new(channel, protocol_name) }
133 }
134
135 pub fn take_event_stream(&self) -> MemoryMonitorEventStream {
141 MemoryMonitorEventStream { event_receiver: self.client.take_event_receiver() }
142 }
143
144 pub fn r#get_snapshot(&self, mut snapshot: fidl::Socket) -> Result<(), fidl::Error> {
145 MemoryMonitorProxyInterface::r#get_snapshot(self, snapshot)
146 }
147}
148
149impl MemoryMonitorProxyInterface for MemoryMonitorProxy {
150 fn r#get_snapshot(&self, mut snapshot: fidl::Socket) -> Result<(), fidl::Error> {
151 self.client.send::<MemoryMonitorGetSnapshotRequest>(
152 (snapshot,),
153 0x3af6caa4c6a6fdb7,
154 fidl::encoding::DynamicFlags::FLEXIBLE,
155 )
156 }
157}
158
159pub struct MemoryMonitorEventStream {
160 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
161}
162
163impl std::marker::Unpin for MemoryMonitorEventStream {}
164
165impl futures::stream::FusedStream for MemoryMonitorEventStream {
166 fn is_terminated(&self) -> bool {
167 self.event_receiver.is_terminated()
168 }
169}
170
171impl futures::Stream for MemoryMonitorEventStream {
172 type Item = Result<MemoryMonitorEvent, fidl::Error>;
173
174 fn poll_next(
175 mut self: std::pin::Pin<&mut Self>,
176 cx: &mut std::task::Context<'_>,
177 ) -> std::task::Poll<Option<Self::Item>> {
178 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
179 &mut self.event_receiver,
180 cx
181 )?) {
182 Some(buf) => std::task::Poll::Ready(Some(MemoryMonitorEvent::decode(buf))),
183 None => std::task::Poll::Ready(None),
184 }
185 }
186}
187
188#[derive(Debug)]
189pub enum MemoryMonitorEvent {
190 #[non_exhaustive]
191 _UnknownEvent {
192 ordinal: u64,
194 },
195}
196
197impl MemoryMonitorEvent {
198 fn decode(
200 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
201 ) -> Result<MemoryMonitorEvent, fidl::Error> {
202 let (bytes, _handles) = buf.split_mut();
203 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
204 debug_assert_eq!(tx_header.tx_id, 0);
205 match tx_header.ordinal {
206 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
207 Ok(MemoryMonitorEvent::_UnknownEvent { ordinal: tx_header.ordinal })
208 }
209 _ => Err(fidl::Error::UnknownOrdinal {
210 ordinal: tx_header.ordinal,
211 protocol_name: <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
212 }),
213 }
214 }
215}
216
217pub struct MemoryMonitorRequestStream {
219 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
220 is_terminated: bool,
221}
222
223impl std::marker::Unpin for MemoryMonitorRequestStream {}
224
225impl futures::stream::FusedStream for MemoryMonitorRequestStream {
226 fn is_terminated(&self) -> bool {
227 self.is_terminated
228 }
229}
230
231impl fidl::endpoints::RequestStream for MemoryMonitorRequestStream {
232 type Protocol = MemoryMonitorMarker;
233 type ControlHandle = MemoryMonitorControlHandle;
234
235 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
236 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
237 }
238
239 fn control_handle(&self) -> Self::ControlHandle {
240 MemoryMonitorControlHandle { inner: self.inner.clone() }
241 }
242
243 fn into_inner(
244 self,
245 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
246 {
247 (self.inner, self.is_terminated)
248 }
249
250 fn from_inner(
251 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
252 is_terminated: bool,
253 ) -> Self {
254 Self { inner, is_terminated }
255 }
256}
257
258impl futures::Stream for MemoryMonitorRequestStream {
259 type Item = Result<MemoryMonitorRequest, fidl::Error>;
260
261 fn poll_next(
262 mut self: std::pin::Pin<&mut Self>,
263 cx: &mut std::task::Context<'_>,
264 ) -> std::task::Poll<Option<Self::Item>> {
265 let this = &mut *self;
266 if this.inner.check_shutdown(cx) {
267 this.is_terminated = true;
268 return std::task::Poll::Ready(None);
269 }
270 if this.is_terminated {
271 panic!("polled MemoryMonitorRequestStream after completion");
272 }
273 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
274 |bytes, handles| {
275 match this.inner.channel().read_etc(cx, bytes, handles) {
276 std::task::Poll::Ready(Ok(())) => {}
277 std::task::Poll::Pending => return std::task::Poll::Pending,
278 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
279 this.is_terminated = true;
280 return std::task::Poll::Ready(None);
281 }
282 std::task::Poll::Ready(Err(e)) => {
283 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
284 e.into(),
285 ))))
286 }
287 }
288
289 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
291
292 std::task::Poll::Ready(Some(match header.ordinal {
293 0x3af6caa4c6a6fdb7 => {
294 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
295 let mut req = fidl::new_empty!(
296 MemoryMonitorGetSnapshotRequest,
297 fidl::encoding::DefaultFuchsiaResourceDialect
298 );
299 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MemoryMonitorGetSnapshotRequest>(&header, _body_bytes, handles, &mut req)?;
300 let control_handle =
301 MemoryMonitorControlHandle { inner: this.inner.clone() };
302 Ok(MemoryMonitorRequest::GetSnapshot {
303 snapshot: req.snapshot,
304
305 control_handle,
306 })
307 }
308 _ if header.tx_id == 0
309 && header
310 .dynamic_flags()
311 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
312 {
313 Ok(MemoryMonitorRequest::_UnknownMethod {
314 ordinal: header.ordinal,
315 control_handle: MemoryMonitorControlHandle {
316 inner: this.inner.clone(),
317 },
318 method_type: fidl::MethodType::OneWay,
319 })
320 }
321 _ if header
322 .dynamic_flags()
323 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
324 {
325 this.inner.send_framework_err(
326 fidl::encoding::FrameworkErr::UnknownMethod,
327 header.tx_id,
328 header.ordinal,
329 header.dynamic_flags(),
330 (bytes, handles),
331 )?;
332 Ok(MemoryMonitorRequest::_UnknownMethod {
333 ordinal: header.ordinal,
334 control_handle: MemoryMonitorControlHandle {
335 inner: this.inner.clone(),
336 },
337 method_type: fidl::MethodType::TwoWay,
338 })
339 }
340 _ => Err(fidl::Error::UnknownOrdinal {
341 ordinal: header.ordinal,
342 protocol_name:
343 <MemoryMonitorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
344 }),
345 }))
346 },
347 )
348 }
349}
350
351#[derive(Debug)]
352pub enum MemoryMonitorRequest {
353 GetSnapshot {
354 snapshot: fidl::Socket,
355 control_handle: MemoryMonitorControlHandle,
356 },
357 #[non_exhaustive]
359 _UnknownMethod {
360 ordinal: u64,
362 control_handle: MemoryMonitorControlHandle,
363 method_type: fidl::MethodType,
364 },
365}
366
367impl MemoryMonitorRequest {
368 #[allow(irrefutable_let_patterns)]
369 pub fn into_get_snapshot(self) -> Option<(fidl::Socket, MemoryMonitorControlHandle)> {
370 if let MemoryMonitorRequest::GetSnapshot { snapshot, control_handle } = self {
371 Some((snapshot, control_handle))
372 } else {
373 None
374 }
375 }
376
377 pub fn method_name(&self) -> &'static str {
379 match *self {
380 MemoryMonitorRequest::GetSnapshot { .. } => "get_snapshot",
381 MemoryMonitorRequest::_UnknownMethod {
382 method_type: fidl::MethodType::OneWay, ..
383 } => "unknown one-way method",
384 MemoryMonitorRequest::_UnknownMethod {
385 method_type: fidl::MethodType::TwoWay, ..
386 } => "unknown two-way method",
387 }
388 }
389}
390
391#[derive(Debug, Clone)]
392pub struct MemoryMonitorControlHandle {
393 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
394}
395
396impl fidl::endpoints::ControlHandle for MemoryMonitorControlHandle {
397 fn shutdown(&self) {
398 self.inner.shutdown()
399 }
400 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
401 self.inner.shutdown_with_epitaph(status)
402 }
403
404 fn is_closed(&self) -> bool {
405 self.inner.channel().is_closed()
406 }
407 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
408 self.inner.channel().on_closed()
409 }
410
411 #[cfg(target_os = "fuchsia")]
412 fn signal_peer(
413 &self,
414 clear_mask: zx::Signals,
415 set_mask: zx::Signals,
416 ) -> Result<(), zx_status::Status> {
417 use fidl::Peered;
418 self.inner.channel().signal_peer(clear_mask, set_mask)
419 }
420}
421
422impl MemoryMonitorControlHandle {}
423
424mod internal {
425 use super::*;
426
427 impl fidl::encoding::ResourceTypeMarker for MemoryMonitorGetSnapshotRequest {
428 type Borrowed<'a> = &'a mut Self;
429 fn take_or_borrow<'a>(
430 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
431 ) -> Self::Borrowed<'a> {
432 value
433 }
434 }
435
436 unsafe impl fidl::encoding::TypeMarker for MemoryMonitorGetSnapshotRequest {
437 type Owned = Self;
438
439 #[inline(always)]
440 fn inline_align(_context: fidl::encoding::Context) -> usize {
441 4
442 }
443
444 #[inline(always)]
445 fn inline_size(_context: fidl::encoding::Context) -> usize {
446 4
447 }
448 }
449
450 unsafe impl
451 fidl::encoding::Encode<
452 MemoryMonitorGetSnapshotRequest,
453 fidl::encoding::DefaultFuchsiaResourceDialect,
454 > for &mut MemoryMonitorGetSnapshotRequest
455 {
456 #[inline]
457 unsafe fn encode(
458 self,
459 encoder: &mut fidl::encoding::Encoder<
460 '_,
461 fidl::encoding::DefaultFuchsiaResourceDialect,
462 >,
463 offset: usize,
464 _depth: fidl::encoding::Depth,
465 ) -> fidl::Result<()> {
466 encoder.debug_check_bounds::<MemoryMonitorGetSnapshotRequest>(offset);
467 fidl::encoding::Encode::<
469 MemoryMonitorGetSnapshotRequest,
470 fidl::encoding::DefaultFuchsiaResourceDialect,
471 >::encode(
472 (<fidl::encoding::HandleType<
473 fidl::Socket,
474 { fidl::ObjectType::SOCKET.into_raw() },
475 2147483648,
476 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
477 &mut self.snapshot
478 ),),
479 encoder,
480 offset,
481 _depth,
482 )
483 }
484 }
485 unsafe impl<
486 T0: fidl::encoding::Encode<
487 fidl::encoding::HandleType<
488 fidl::Socket,
489 { fidl::ObjectType::SOCKET.into_raw() },
490 2147483648,
491 >,
492 fidl::encoding::DefaultFuchsiaResourceDialect,
493 >,
494 >
495 fidl::encoding::Encode<
496 MemoryMonitorGetSnapshotRequest,
497 fidl::encoding::DefaultFuchsiaResourceDialect,
498 > for (T0,)
499 {
500 #[inline]
501 unsafe fn encode(
502 self,
503 encoder: &mut fidl::encoding::Encoder<
504 '_,
505 fidl::encoding::DefaultFuchsiaResourceDialect,
506 >,
507 offset: usize,
508 depth: fidl::encoding::Depth,
509 ) -> fidl::Result<()> {
510 encoder.debug_check_bounds::<MemoryMonitorGetSnapshotRequest>(offset);
511 self.0.encode(encoder, offset + 0, depth)?;
515 Ok(())
516 }
517 }
518
519 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
520 for MemoryMonitorGetSnapshotRequest
521 {
522 #[inline(always)]
523 fn new_empty() -> Self {
524 Self {
525 snapshot: fidl::new_empty!(fidl::encoding::HandleType<fidl::Socket, { fidl::ObjectType::SOCKET.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
526 }
527 }
528
529 #[inline]
530 unsafe fn decode(
531 &mut self,
532 decoder: &mut fidl::encoding::Decoder<
533 '_,
534 fidl::encoding::DefaultFuchsiaResourceDialect,
535 >,
536 offset: usize,
537 _depth: fidl::encoding::Depth,
538 ) -> fidl::Result<()> {
539 decoder.debug_check_bounds::<Self>(offset);
540 fidl::decode!(fidl::encoding::HandleType<fidl::Socket, { fidl::ObjectType::SOCKET.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.snapshot, decoder, offset + 0, _depth)?;
542 Ok(())
543 }
544 }
545}