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