fidl_fuchsia_test_suspend/
fidl_fuchsia_test_suspend.rs
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_test_suspend_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct RealmMarker;
16
17impl fidl::endpoints::ProtocolMarker for RealmMarker {
18 type Proxy = RealmProxy;
19 type RequestStream = RealmRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = RealmSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.test.suspend.Realm";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for RealmMarker {}
26
27pub trait RealmProxyInterface: Send + Sync {
28 type CreateResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#create(&self) -> Self::CreateResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct RealmSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for RealmSynchronousProxy {
39 type Proxy = RealmProxy;
40 type Protocol = RealmMarker;
41
42 fn from_channel(inner: fidl::Channel) -> Self {
43 Self::new(inner)
44 }
45
46 fn into_channel(self) -> fidl::Channel {
47 self.client.into_channel()
48 }
49
50 fn as_channel(&self) -> &fidl::Channel {
51 self.client.as_channel()
52 }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl RealmSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <RealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60 }
61
62 pub fn into_channel(self) -> fidl::Channel {
63 self.client.into_channel()
64 }
65
66 pub fn wait_for_event(
69 &self,
70 deadline: zx::MonotonicInstant,
71 ) -> Result<RealmEvent, fidl::Error> {
72 RealmEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#create(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
78 let _response =
79 self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
80 (),
81 0xdd39db1f18a95ce,
82 fidl::encoding::DynamicFlags::empty(),
83 ___deadline,
84 )?;
85 Ok(_response)
86 }
87}
88
89#[derive(Debug, Clone)]
90pub struct RealmProxy {
91 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
92}
93
94impl fidl::endpoints::Proxy for RealmProxy {
95 type Protocol = RealmMarker;
96
97 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
98 Self::new(inner)
99 }
100
101 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
102 self.client.into_channel().map_err(|client| Self { client })
103 }
104
105 fn as_channel(&self) -> &::fidl::AsyncChannel {
106 self.client.as_channel()
107 }
108}
109
110impl RealmProxy {
111 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
113 let protocol_name = <RealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
114 Self { client: fidl::client::Client::new(channel, protocol_name) }
115 }
116
117 pub fn take_event_stream(&self) -> RealmEventStream {
123 RealmEventStream { event_receiver: self.client.take_event_receiver() }
124 }
125
126 pub fn r#create(
129 &self,
130 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
131 RealmProxyInterface::r#create(self)
132 }
133}
134
135impl RealmProxyInterface for RealmProxy {
136 type CreateResponseFut =
137 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
138 fn r#create(&self) -> Self::CreateResponseFut {
139 fn _decode(
140 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
141 ) -> Result<(), fidl::Error> {
142 let _response = fidl::client::decode_transaction_body::<
143 fidl::encoding::EmptyPayload,
144 fidl::encoding::DefaultFuchsiaResourceDialect,
145 0xdd39db1f18a95ce,
146 >(_buf?)?;
147 Ok(_response)
148 }
149 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
150 (),
151 0xdd39db1f18a95ce,
152 fidl::encoding::DynamicFlags::empty(),
153 _decode,
154 )
155 }
156}
157
158pub struct RealmEventStream {
159 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
160}
161
162impl std::marker::Unpin for RealmEventStream {}
163
164impl futures::stream::FusedStream for RealmEventStream {
165 fn is_terminated(&self) -> bool {
166 self.event_receiver.is_terminated()
167 }
168}
169
170impl futures::Stream for RealmEventStream {
171 type Item = Result<RealmEvent, fidl::Error>;
172
173 fn poll_next(
174 mut self: std::pin::Pin<&mut Self>,
175 cx: &mut std::task::Context<'_>,
176 ) -> std::task::Poll<Option<Self::Item>> {
177 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
178 &mut self.event_receiver,
179 cx
180 )?) {
181 Some(buf) => std::task::Poll::Ready(Some(RealmEvent::decode(buf))),
182 None => std::task::Poll::Ready(None),
183 }
184 }
185}
186
187#[derive(Debug)]
188pub enum RealmEvent {}
189
190impl RealmEvent {
191 fn decode(
193 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
194 ) -> Result<RealmEvent, fidl::Error> {
195 let (bytes, _handles) = buf.split_mut();
196 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
197 debug_assert_eq!(tx_header.tx_id, 0);
198 match tx_header.ordinal {
199 _ => Err(fidl::Error::UnknownOrdinal {
200 ordinal: tx_header.ordinal,
201 protocol_name: <RealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
202 }),
203 }
204 }
205}
206
207pub struct RealmRequestStream {
209 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
210 is_terminated: bool,
211}
212
213impl std::marker::Unpin for RealmRequestStream {}
214
215impl futures::stream::FusedStream for RealmRequestStream {
216 fn is_terminated(&self) -> bool {
217 self.is_terminated
218 }
219}
220
221impl fidl::endpoints::RequestStream for RealmRequestStream {
222 type Protocol = RealmMarker;
223 type ControlHandle = RealmControlHandle;
224
225 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
226 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
227 }
228
229 fn control_handle(&self) -> Self::ControlHandle {
230 RealmControlHandle { inner: self.inner.clone() }
231 }
232
233 fn into_inner(
234 self,
235 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
236 {
237 (self.inner, self.is_terminated)
238 }
239
240 fn from_inner(
241 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
242 is_terminated: bool,
243 ) -> Self {
244 Self { inner, is_terminated }
245 }
246}
247
248impl futures::Stream for RealmRequestStream {
249 type Item = Result<RealmRequest, fidl::Error>;
250
251 fn poll_next(
252 mut self: std::pin::Pin<&mut Self>,
253 cx: &mut std::task::Context<'_>,
254 ) -> std::task::Poll<Option<Self::Item>> {
255 let this = &mut *self;
256 if this.inner.check_shutdown(cx) {
257 this.is_terminated = true;
258 return std::task::Poll::Ready(None);
259 }
260 if this.is_terminated {
261 panic!("polled RealmRequestStream after completion");
262 }
263 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
264 |bytes, handles| {
265 match this.inner.channel().read_etc(cx, bytes, handles) {
266 std::task::Poll::Ready(Ok(())) => {}
267 std::task::Poll::Pending => return std::task::Poll::Pending,
268 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
269 this.is_terminated = true;
270 return std::task::Poll::Ready(None);
271 }
272 std::task::Poll::Ready(Err(e)) => {
273 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
274 e.into(),
275 ))))
276 }
277 }
278
279 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
281
282 std::task::Poll::Ready(Some(match header.ordinal {
283 0xdd39db1f18a95ce => {
284 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
285 let mut req = fidl::new_empty!(
286 fidl::encoding::EmptyPayload,
287 fidl::encoding::DefaultFuchsiaResourceDialect
288 );
289 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
290 let control_handle = RealmControlHandle { inner: this.inner.clone() };
291 Ok(RealmRequest::Create {
292 responder: RealmCreateResponder {
293 control_handle: std::mem::ManuallyDrop::new(control_handle),
294 tx_id: header.tx_id,
295 },
296 })
297 }
298 _ => Err(fidl::Error::UnknownOrdinal {
299 ordinal: header.ordinal,
300 protocol_name: <RealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
301 }),
302 }))
303 },
304 )
305 }
306}
307
308#[derive(Debug)]
311pub enum RealmRequest {
312 Create { responder: RealmCreateResponder },
315}
316
317impl RealmRequest {
318 #[allow(irrefutable_let_patterns)]
319 pub fn into_create(self) -> Option<(RealmCreateResponder)> {
320 if let RealmRequest::Create { responder } = self {
321 Some((responder))
322 } else {
323 None
324 }
325 }
326
327 pub fn method_name(&self) -> &'static str {
329 match *self {
330 RealmRequest::Create { .. } => "create",
331 }
332 }
333}
334
335#[derive(Debug, Clone)]
336pub struct RealmControlHandle {
337 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
338}
339
340impl fidl::endpoints::ControlHandle for RealmControlHandle {
341 fn shutdown(&self) {
342 self.inner.shutdown()
343 }
344 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
345 self.inner.shutdown_with_epitaph(status)
346 }
347
348 fn is_closed(&self) -> bool {
349 self.inner.channel().is_closed()
350 }
351 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
352 self.inner.channel().on_closed()
353 }
354
355 #[cfg(target_os = "fuchsia")]
356 fn signal_peer(
357 &self,
358 clear_mask: zx::Signals,
359 set_mask: zx::Signals,
360 ) -> Result<(), zx_status::Status> {
361 use fidl::Peered;
362 self.inner.channel().signal_peer(clear_mask, set_mask)
363 }
364}
365
366impl RealmControlHandle {}
367
368#[must_use = "FIDL methods require a response to be sent"]
369#[derive(Debug)]
370pub struct RealmCreateResponder {
371 control_handle: std::mem::ManuallyDrop<RealmControlHandle>,
372 tx_id: u32,
373}
374
375impl std::ops::Drop for RealmCreateResponder {
379 fn drop(&mut self) {
380 self.control_handle.shutdown();
381 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
383 }
384}
385
386impl fidl::endpoints::Responder for RealmCreateResponder {
387 type ControlHandle = RealmControlHandle;
388
389 fn control_handle(&self) -> &RealmControlHandle {
390 &self.control_handle
391 }
392
393 fn drop_without_shutdown(mut self) {
394 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
396 std::mem::forget(self);
398 }
399}
400
401impl RealmCreateResponder {
402 pub fn send(self) -> Result<(), fidl::Error> {
406 let _result = self.send_raw();
407 if _result.is_err() {
408 self.control_handle.shutdown();
409 }
410 self.drop_without_shutdown();
411 _result
412 }
413
414 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
416 let _result = self.send_raw();
417 self.drop_without_shutdown();
418 _result
419 }
420
421 fn send_raw(&self) -> Result<(), fidl::Error> {
422 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
423 (),
424 self.tx_id,
425 0xdd39db1f18a95ce,
426 fidl::encoding::DynamicFlags::empty(),
427 )
428 }
429}
430
431mod internal {
432 use super::*;
433}