fidl_fuchsia_memory_debug/
fidl_fuchsia_memory_debug.rs1#![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_debug_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct MemoryPressureMarker;
16
17impl fidl::endpoints::ProtocolMarker for MemoryPressureMarker {
18 type Proxy = MemoryPressureProxy;
19 type RequestStream = MemoryPressureRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = MemoryPressureSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.memory.debug.MemoryPressure";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for MemoryPressureMarker {}
26
27pub trait MemoryPressureProxyInterface: Send + Sync {
28 fn r#signal(&self, level: fidl_fuchsia_memorypressure::Level) -> Result<(), fidl::Error>;
29}
30#[derive(Debug)]
31#[cfg(target_os = "fuchsia")]
32pub struct MemoryPressureSynchronousProxy {
33 client: fidl::client::sync::Client,
34}
35
36#[cfg(target_os = "fuchsia")]
37impl fidl::endpoints::SynchronousProxy for MemoryPressureSynchronousProxy {
38 type Proxy = MemoryPressureProxy;
39 type Protocol = MemoryPressureMarker;
40
41 fn from_channel(inner: fidl::Channel) -> Self {
42 Self::new(inner)
43 }
44
45 fn into_channel(self) -> fidl::Channel {
46 self.client.into_channel()
47 }
48
49 fn as_channel(&self) -> &fidl::Channel {
50 self.client.as_channel()
51 }
52}
53
54#[cfg(target_os = "fuchsia")]
55impl MemoryPressureSynchronousProxy {
56 pub fn new(channel: fidl::Channel) -> Self {
57 Self { client: fidl::client::sync::Client::new(channel) }
58 }
59
60 pub fn into_channel(self) -> fidl::Channel {
61 self.client.into_channel()
62 }
63
64 pub fn wait_for_event(
67 &self,
68 deadline: zx::MonotonicInstant,
69 ) -> Result<MemoryPressureEvent, fidl::Error> {
70 MemoryPressureEvent::decode(self.client.wait_for_event::<MemoryPressureMarker>(deadline)?)
71 }
72
73 pub fn r#signal(
81 &self,
82 mut level: fidl_fuchsia_memorypressure::Level,
83 ) -> Result<(), fidl::Error> {
84 self.client.send::<MemoryPressureSignalRequest>(
85 (level,),
86 0x7eaa45c1812124d4,
87 fidl::encoding::DynamicFlags::empty(),
88 )
89 }
90}
91
92#[cfg(target_os = "fuchsia")]
93impl From<MemoryPressureSynchronousProxy> for zx::NullableHandle {
94 fn from(value: MemoryPressureSynchronousProxy) -> Self {
95 value.into_channel().into()
96 }
97}
98
99#[cfg(target_os = "fuchsia")]
100impl From<fidl::Channel> for MemoryPressureSynchronousProxy {
101 fn from(value: fidl::Channel) -> Self {
102 Self::new(value)
103 }
104}
105
106#[cfg(target_os = "fuchsia")]
107impl fidl::endpoints::FromClient for MemoryPressureSynchronousProxy {
108 type Protocol = MemoryPressureMarker;
109
110 fn from_client(value: fidl::endpoints::ClientEnd<MemoryPressureMarker>) -> Self {
111 Self::new(value.into_channel())
112 }
113}
114
115#[derive(Debug, Clone)]
116pub struct MemoryPressureProxy {
117 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
118}
119
120impl fidl::endpoints::Proxy for MemoryPressureProxy {
121 type Protocol = MemoryPressureMarker;
122
123 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
124 Self::new(inner)
125 }
126
127 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
128 self.client.into_channel().map_err(|client| Self { client })
129 }
130
131 fn as_channel(&self) -> &::fidl::AsyncChannel {
132 self.client.as_channel()
133 }
134}
135
136impl MemoryPressureProxy {
137 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
139 let protocol_name = <MemoryPressureMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
140 Self { client: fidl::client::Client::new(channel, protocol_name) }
141 }
142
143 pub fn take_event_stream(&self) -> MemoryPressureEventStream {
149 MemoryPressureEventStream { event_receiver: self.client.take_event_receiver() }
150 }
151
152 pub fn r#signal(
160 &self,
161 mut level: fidl_fuchsia_memorypressure::Level,
162 ) -> Result<(), fidl::Error> {
163 MemoryPressureProxyInterface::r#signal(self, level)
164 }
165}
166
167impl MemoryPressureProxyInterface for MemoryPressureProxy {
168 fn r#signal(&self, mut level: fidl_fuchsia_memorypressure::Level) -> Result<(), fidl::Error> {
169 self.client.send::<MemoryPressureSignalRequest>(
170 (level,),
171 0x7eaa45c1812124d4,
172 fidl::encoding::DynamicFlags::empty(),
173 )
174 }
175}
176
177pub struct MemoryPressureEventStream {
178 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
179}
180
181impl std::marker::Unpin for MemoryPressureEventStream {}
182
183impl futures::stream::FusedStream for MemoryPressureEventStream {
184 fn is_terminated(&self) -> bool {
185 self.event_receiver.is_terminated()
186 }
187}
188
189impl futures::Stream for MemoryPressureEventStream {
190 type Item = Result<MemoryPressureEvent, fidl::Error>;
191
192 fn poll_next(
193 mut self: std::pin::Pin<&mut Self>,
194 cx: &mut std::task::Context<'_>,
195 ) -> std::task::Poll<Option<Self::Item>> {
196 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
197 &mut self.event_receiver,
198 cx
199 )?) {
200 Some(buf) => std::task::Poll::Ready(Some(MemoryPressureEvent::decode(buf))),
201 None => std::task::Poll::Ready(None),
202 }
203 }
204}
205
206#[derive(Debug)]
207pub enum MemoryPressureEvent {}
208
209impl MemoryPressureEvent {
210 fn decode(
212 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
213 ) -> Result<MemoryPressureEvent, fidl::Error> {
214 let (bytes, _handles) = buf.split_mut();
215 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
216 debug_assert_eq!(tx_header.tx_id, 0);
217 match tx_header.ordinal {
218 _ => Err(fidl::Error::UnknownOrdinal {
219 ordinal: tx_header.ordinal,
220 protocol_name:
221 <MemoryPressureMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
222 }),
223 }
224 }
225}
226
227pub struct MemoryPressureRequestStream {
229 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
230 is_terminated: bool,
231}
232
233impl std::marker::Unpin for MemoryPressureRequestStream {}
234
235impl futures::stream::FusedStream for MemoryPressureRequestStream {
236 fn is_terminated(&self) -> bool {
237 self.is_terminated
238 }
239}
240
241impl fidl::endpoints::RequestStream for MemoryPressureRequestStream {
242 type Protocol = MemoryPressureMarker;
243 type ControlHandle = MemoryPressureControlHandle;
244
245 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
246 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
247 }
248
249 fn control_handle(&self) -> Self::ControlHandle {
250 MemoryPressureControlHandle { inner: self.inner.clone() }
251 }
252
253 fn into_inner(
254 self,
255 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
256 {
257 (self.inner, self.is_terminated)
258 }
259
260 fn from_inner(
261 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
262 is_terminated: bool,
263 ) -> Self {
264 Self { inner, is_terminated }
265 }
266}
267
268impl futures::Stream for MemoryPressureRequestStream {
269 type Item = Result<MemoryPressureRequest, fidl::Error>;
270
271 fn poll_next(
272 mut self: std::pin::Pin<&mut Self>,
273 cx: &mut std::task::Context<'_>,
274 ) -> std::task::Poll<Option<Self::Item>> {
275 let this = &mut *self;
276 if this.inner.check_shutdown(cx) {
277 this.is_terminated = true;
278 return std::task::Poll::Ready(None);
279 }
280 if this.is_terminated {
281 panic!("polled MemoryPressureRequestStream after completion");
282 }
283 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
284 |bytes, handles| {
285 match this.inner.channel().read_etc(cx, bytes, handles) {
286 std::task::Poll::Ready(Ok(())) => {}
287 std::task::Poll::Pending => return std::task::Poll::Pending,
288 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
289 this.is_terminated = true;
290 return std::task::Poll::Ready(None);
291 }
292 std::task::Poll::Ready(Err(e)) => {
293 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
294 e.into(),
295 ))));
296 }
297 }
298
299 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
301
302 std::task::Poll::Ready(Some(match header.ordinal {
303 0x7eaa45c1812124d4 => {
304 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
305 let mut req = fidl::new_empty!(
306 MemoryPressureSignalRequest,
307 fidl::encoding::DefaultFuchsiaResourceDialect
308 );
309 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<MemoryPressureSignalRequest>(&header, _body_bytes, handles, &mut req)?;
310 let control_handle =
311 MemoryPressureControlHandle { inner: this.inner.clone() };
312 Ok(MemoryPressureRequest::Signal { level: req.level, control_handle })
313 }
314 _ => Err(fidl::Error::UnknownOrdinal {
315 ordinal: header.ordinal,
316 protocol_name:
317 <MemoryPressureMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
318 }),
319 }))
320 },
321 )
322 }
323}
324
325#[derive(Debug)]
327pub enum MemoryPressureRequest {
328 Signal {
336 level: fidl_fuchsia_memorypressure::Level,
337 control_handle: MemoryPressureControlHandle,
338 },
339}
340
341impl MemoryPressureRequest {
342 #[allow(irrefutable_let_patterns)]
343 pub fn into_signal(
344 self,
345 ) -> Option<(fidl_fuchsia_memorypressure::Level, MemoryPressureControlHandle)> {
346 if let MemoryPressureRequest::Signal { level, control_handle } = self {
347 Some((level, control_handle))
348 } else {
349 None
350 }
351 }
352
353 pub fn method_name(&self) -> &'static str {
355 match *self {
356 MemoryPressureRequest::Signal { .. } => "signal",
357 }
358 }
359}
360
361#[derive(Debug, Clone)]
362pub struct MemoryPressureControlHandle {
363 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
364}
365
366impl fidl::endpoints::ControlHandle for MemoryPressureControlHandle {
367 fn shutdown(&self) {
368 self.inner.shutdown()
369 }
370
371 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
372 self.inner.shutdown_with_epitaph(status)
373 }
374
375 fn is_closed(&self) -> bool {
376 self.inner.channel().is_closed()
377 }
378 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
379 self.inner.channel().on_closed()
380 }
381
382 #[cfg(target_os = "fuchsia")]
383 fn signal_peer(
384 &self,
385 clear_mask: zx::Signals,
386 set_mask: zx::Signals,
387 ) -> Result<(), zx_status::Status> {
388 use fidl::Peered;
389 self.inner.channel().signal_peer(clear_mask, set_mask)
390 }
391}
392
393impl MemoryPressureControlHandle {}
394
395mod internal {
396 use super::*;
397}