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_test_componentmanager_stresstests_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ChildRealmMarker;
16
17impl fidl::endpoints::ProtocolMarker for ChildRealmMarker {
18 type Proxy = ChildRealmProxy;
19 type RequestStream = ChildRealmRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ChildRealmSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "test.componentmanager.stresstests.ChildRealm";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for ChildRealmMarker {}
26
27pub trait ChildRealmProxyInterface: Send + Sync {
28 fn r#stop(&self) -> Result<(), fidl::Error>;
29 type StopChildrenResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
30 fn r#stop_children(&self) -> Self::StopChildrenResponseFut;
31 type CreateChildrenResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
32 fn r#create_children(
33 &self,
34 direct_children: u16,
35 tree_height: u16,
36 ) -> Self::CreateChildrenResponseFut;
37}
38#[derive(Debug)]
39#[cfg(target_os = "fuchsia")]
40pub struct ChildRealmSynchronousProxy {
41 client: fidl::client::sync::Client,
42}
43
44#[cfg(target_os = "fuchsia")]
45impl fidl::endpoints::SynchronousProxy for ChildRealmSynchronousProxy {
46 type Proxy = ChildRealmProxy;
47 type Protocol = ChildRealmMarker;
48
49 fn from_channel(inner: fidl::Channel) -> Self {
50 Self::new(inner)
51 }
52
53 fn into_channel(self) -> fidl::Channel {
54 self.client.into_channel()
55 }
56
57 fn as_channel(&self) -> &fidl::Channel {
58 self.client.as_channel()
59 }
60}
61
62#[cfg(target_os = "fuchsia")]
63impl ChildRealmSynchronousProxy {
64 pub fn new(channel: fidl::Channel) -> Self {
65 let protocol_name = <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
66 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
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<ChildRealmEvent, fidl::Error> {
79 ChildRealmEvent::decode(self.client.wait_for_event(deadline)?)
80 }
81
82 pub fn r#stop(&self) -> Result<(), fidl::Error> {
84 self.client.send::<fidl::encoding::EmptyPayload>(
85 (),
86 0x36c34aa66f2a56ab,
87 fidl::encoding::DynamicFlags::empty(),
88 )
89 }
90
91 pub fn r#stop_children(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
92 let _response =
93 self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
94 (),
95 0x61c8762c3aa05df7,
96 fidl::encoding::DynamicFlags::empty(),
97 ___deadline,
98 )?;
99 Ok(_response)
100 }
101
102 pub fn r#create_children(
107 &self,
108 mut direct_children: u16,
109 mut tree_height: u16,
110 ___deadline: zx::MonotonicInstant,
111 ) -> Result<(), fidl::Error> {
112 let _response = self
113 .client
114 .send_query::<ChildRealmCreateChildrenRequest, fidl::encoding::EmptyPayload>(
115 (direct_children, tree_height),
116 0x37a93e012377095c,
117 fidl::encoding::DynamicFlags::empty(),
118 ___deadline,
119 )?;
120 Ok(_response)
121 }
122}
123
124#[derive(Debug, Clone)]
125pub struct ChildRealmProxy {
126 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
127}
128
129impl fidl::endpoints::Proxy for ChildRealmProxy {
130 type Protocol = ChildRealmMarker;
131
132 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
133 Self::new(inner)
134 }
135
136 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
137 self.client.into_channel().map_err(|client| Self { client })
138 }
139
140 fn as_channel(&self) -> &::fidl::AsyncChannel {
141 self.client.as_channel()
142 }
143}
144
145impl ChildRealmProxy {
146 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
148 let protocol_name = <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
149 Self { client: fidl::client::Client::new(channel, protocol_name) }
150 }
151
152 pub fn take_event_stream(&self) -> ChildRealmEventStream {
158 ChildRealmEventStream { event_receiver: self.client.take_event_receiver() }
159 }
160
161 pub fn r#stop(&self) -> Result<(), fidl::Error> {
163 ChildRealmProxyInterface::r#stop(self)
164 }
165
166 pub fn r#stop_children(
167 &self,
168 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
169 ChildRealmProxyInterface::r#stop_children(self)
170 }
171
172 pub fn r#create_children(
177 &self,
178 mut direct_children: u16,
179 mut tree_height: u16,
180 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
181 ChildRealmProxyInterface::r#create_children(self, direct_children, tree_height)
182 }
183}
184
185impl ChildRealmProxyInterface for ChildRealmProxy {
186 fn r#stop(&self) -> Result<(), fidl::Error> {
187 self.client.send::<fidl::encoding::EmptyPayload>(
188 (),
189 0x36c34aa66f2a56ab,
190 fidl::encoding::DynamicFlags::empty(),
191 )
192 }
193
194 type StopChildrenResponseFut =
195 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
196 fn r#stop_children(&self) -> Self::StopChildrenResponseFut {
197 fn _decode(
198 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
199 ) -> Result<(), fidl::Error> {
200 let _response = fidl::client::decode_transaction_body::<
201 fidl::encoding::EmptyPayload,
202 fidl::encoding::DefaultFuchsiaResourceDialect,
203 0x61c8762c3aa05df7,
204 >(_buf?)?;
205 Ok(_response)
206 }
207 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
208 (),
209 0x61c8762c3aa05df7,
210 fidl::encoding::DynamicFlags::empty(),
211 _decode,
212 )
213 }
214
215 type CreateChildrenResponseFut =
216 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
217 fn r#create_children(
218 &self,
219 mut direct_children: u16,
220 mut tree_height: u16,
221 ) -> Self::CreateChildrenResponseFut {
222 fn _decode(
223 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
224 ) -> Result<(), fidl::Error> {
225 let _response = fidl::client::decode_transaction_body::<
226 fidl::encoding::EmptyPayload,
227 fidl::encoding::DefaultFuchsiaResourceDialect,
228 0x37a93e012377095c,
229 >(_buf?)?;
230 Ok(_response)
231 }
232 self.client.send_query_and_decode::<ChildRealmCreateChildrenRequest, ()>(
233 (direct_children, tree_height),
234 0x37a93e012377095c,
235 fidl::encoding::DynamicFlags::empty(),
236 _decode,
237 )
238 }
239}
240
241pub struct ChildRealmEventStream {
242 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
243}
244
245impl std::marker::Unpin for ChildRealmEventStream {}
246
247impl futures::stream::FusedStream for ChildRealmEventStream {
248 fn is_terminated(&self) -> bool {
249 self.event_receiver.is_terminated()
250 }
251}
252
253impl futures::Stream for ChildRealmEventStream {
254 type Item = Result<ChildRealmEvent, fidl::Error>;
255
256 fn poll_next(
257 mut self: std::pin::Pin<&mut Self>,
258 cx: &mut std::task::Context<'_>,
259 ) -> std::task::Poll<Option<Self::Item>> {
260 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
261 &mut self.event_receiver,
262 cx
263 )?) {
264 Some(buf) => std::task::Poll::Ready(Some(ChildRealmEvent::decode(buf))),
265 None => std::task::Poll::Ready(None),
266 }
267 }
268}
269
270#[derive(Debug)]
271pub enum ChildRealmEvent {
272 OnConnected {},
273}
274
275impl ChildRealmEvent {
276 #[allow(irrefutable_let_patterns)]
277 pub fn into_on_connected(self) -> Option<()> {
278 if let ChildRealmEvent::OnConnected {} = self {
279 Some(())
280 } else {
281 None
282 }
283 }
284
285 fn decode(
287 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
288 ) -> Result<ChildRealmEvent, fidl::Error> {
289 let (bytes, _handles) = buf.split_mut();
290 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
291 debug_assert_eq!(tx_header.tx_id, 0);
292 match tx_header.ordinal {
293 0x68a2f3384c114a61 => {
294 let mut out = fidl::new_empty!(
295 fidl::encoding::EmptyPayload,
296 fidl::encoding::DefaultFuchsiaResourceDialect
297 );
298 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&tx_header, _body_bytes, _handles, &mut out)?;
299 Ok((ChildRealmEvent::OnConnected {}))
300 }
301 _ => Err(fidl::Error::UnknownOrdinal {
302 ordinal: tx_header.ordinal,
303 protocol_name: <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
304 }),
305 }
306 }
307}
308
309pub struct ChildRealmRequestStream {
311 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
312 is_terminated: bool,
313}
314
315impl std::marker::Unpin for ChildRealmRequestStream {}
316
317impl futures::stream::FusedStream for ChildRealmRequestStream {
318 fn is_terminated(&self) -> bool {
319 self.is_terminated
320 }
321}
322
323impl fidl::endpoints::RequestStream for ChildRealmRequestStream {
324 type Protocol = ChildRealmMarker;
325 type ControlHandle = ChildRealmControlHandle;
326
327 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
328 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
329 }
330
331 fn control_handle(&self) -> Self::ControlHandle {
332 ChildRealmControlHandle { inner: self.inner.clone() }
333 }
334
335 fn into_inner(
336 self,
337 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
338 {
339 (self.inner, self.is_terminated)
340 }
341
342 fn from_inner(
343 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
344 is_terminated: bool,
345 ) -> Self {
346 Self { inner, is_terminated }
347 }
348}
349
350impl futures::Stream for ChildRealmRequestStream {
351 type Item = Result<ChildRealmRequest, fidl::Error>;
352
353 fn poll_next(
354 mut self: std::pin::Pin<&mut Self>,
355 cx: &mut std::task::Context<'_>,
356 ) -> std::task::Poll<Option<Self::Item>> {
357 let this = &mut *self;
358 if this.inner.check_shutdown(cx) {
359 this.is_terminated = true;
360 return std::task::Poll::Ready(None);
361 }
362 if this.is_terminated {
363 panic!("polled ChildRealmRequestStream after completion");
364 }
365 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
366 |bytes, handles| {
367 match this.inner.channel().read_etc(cx, bytes, handles) {
368 std::task::Poll::Ready(Ok(())) => {}
369 std::task::Poll::Pending => return std::task::Poll::Pending,
370 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
371 this.is_terminated = true;
372 return std::task::Poll::Ready(None);
373 }
374 std::task::Poll::Ready(Err(e)) => {
375 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
376 e.into(),
377 ))))
378 }
379 }
380
381 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
383
384 std::task::Poll::Ready(Some(match header.ordinal {
385 0x36c34aa66f2a56ab => {
386 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
387 let mut req = fidl::new_empty!(
388 fidl::encoding::EmptyPayload,
389 fidl::encoding::DefaultFuchsiaResourceDialect
390 );
391 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
392 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
393 Ok(ChildRealmRequest::Stop { control_handle })
394 }
395 0x61c8762c3aa05df7 => {
396 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
397 let mut req = fidl::new_empty!(
398 fidl::encoding::EmptyPayload,
399 fidl::encoding::DefaultFuchsiaResourceDialect
400 );
401 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
402 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
403 Ok(ChildRealmRequest::StopChildren {
404 responder: ChildRealmStopChildrenResponder {
405 control_handle: std::mem::ManuallyDrop::new(control_handle),
406 tx_id: header.tx_id,
407 },
408 })
409 }
410 0x37a93e012377095c => {
411 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
412 let mut req = fidl::new_empty!(
413 ChildRealmCreateChildrenRequest,
414 fidl::encoding::DefaultFuchsiaResourceDialect
415 );
416 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChildRealmCreateChildrenRequest>(&header, _body_bytes, handles, &mut req)?;
417 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
418 Ok(ChildRealmRequest::CreateChildren {
419 direct_children: req.direct_children,
420 tree_height: req.tree_height,
421
422 responder: ChildRealmCreateChildrenResponder {
423 control_handle: std::mem::ManuallyDrop::new(control_handle),
424 tx_id: header.tx_id,
425 },
426 })
427 }
428 _ => Err(fidl::Error::UnknownOrdinal {
429 ordinal: header.ordinal,
430 protocol_name:
431 <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
432 }),
433 }))
434 },
435 )
436 }
437}
438
439#[derive(Debug)]
441pub enum ChildRealmRequest {
442 Stop {
444 control_handle: ChildRealmControlHandle,
445 },
446 StopChildren {
447 responder: ChildRealmStopChildrenResponder,
448 },
449 CreateChildren {
454 direct_children: u16,
455 tree_height: u16,
456 responder: ChildRealmCreateChildrenResponder,
457 },
458}
459
460impl ChildRealmRequest {
461 #[allow(irrefutable_let_patterns)]
462 pub fn into_stop(self) -> Option<(ChildRealmControlHandle)> {
463 if let ChildRealmRequest::Stop { control_handle } = self {
464 Some((control_handle))
465 } else {
466 None
467 }
468 }
469
470 #[allow(irrefutable_let_patterns)]
471 pub fn into_stop_children(self) -> Option<(ChildRealmStopChildrenResponder)> {
472 if let ChildRealmRequest::StopChildren { responder } = self {
473 Some((responder))
474 } else {
475 None
476 }
477 }
478
479 #[allow(irrefutable_let_patterns)]
480 pub fn into_create_children(self) -> Option<(u16, u16, ChildRealmCreateChildrenResponder)> {
481 if let ChildRealmRequest::CreateChildren { direct_children, tree_height, responder } = self
482 {
483 Some((direct_children, tree_height, responder))
484 } else {
485 None
486 }
487 }
488
489 pub fn method_name(&self) -> &'static str {
491 match *self {
492 ChildRealmRequest::Stop { .. } => "stop",
493 ChildRealmRequest::StopChildren { .. } => "stop_children",
494 ChildRealmRequest::CreateChildren { .. } => "create_children",
495 }
496 }
497}
498
499#[derive(Debug, Clone)]
500pub struct ChildRealmControlHandle {
501 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
502}
503
504impl fidl::endpoints::ControlHandle for ChildRealmControlHandle {
505 fn shutdown(&self) {
506 self.inner.shutdown()
507 }
508 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
509 self.inner.shutdown_with_epitaph(status)
510 }
511
512 fn is_closed(&self) -> bool {
513 self.inner.channel().is_closed()
514 }
515 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
516 self.inner.channel().on_closed()
517 }
518
519 #[cfg(target_os = "fuchsia")]
520 fn signal_peer(
521 &self,
522 clear_mask: zx::Signals,
523 set_mask: zx::Signals,
524 ) -> Result<(), zx_status::Status> {
525 use fidl::Peered;
526 self.inner.channel().signal_peer(clear_mask, set_mask)
527 }
528}
529
530impl ChildRealmControlHandle {
531 pub fn send_on_connected(&self) -> Result<(), fidl::Error> {
532 self.inner.send::<fidl::encoding::EmptyPayload>(
533 (),
534 0,
535 0x68a2f3384c114a61,
536 fidl::encoding::DynamicFlags::empty(),
537 )
538 }
539}
540
541#[must_use = "FIDL methods require a response to be sent"]
542#[derive(Debug)]
543pub struct ChildRealmStopChildrenResponder {
544 control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
545 tx_id: u32,
546}
547
548impl std::ops::Drop for ChildRealmStopChildrenResponder {
552 fn drop(&mut self) {
553 self.control_handle.shutdown();
554 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
556 }
557}
558
559impl fidl::endpoints::Responder for ChildRealmStopChildrenResponder {
560 type ControlHandle = ChildRealmControlHandle;
561
562 fn control_handle(&self) -> &ChildRealmControlHandle {
563 &self.control_handle
564 }
565
566 fn drop_without_shutdown(mut self) {
567 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
569 std::mem::forget(self);
571 }
572}
573
574impl ChildRealmStopChildrenResponder {
575 pub fn send(self) -> Result<(), fidl::Error> {
579 let _result = self.send_raw();
580 if _result.is_err() {
581 self.control_handle.shutdown();
582 }
583 self.drop_without_shutdown();
584 _result
585 }
586
587 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
589 let _result = self.send_raw();
590 self.drop_without_shutdown();
591 _result
592 }
593
594 fn send_raw(&self) -> Result<(), fidl::Error> {
595 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
596 (),
597 self.tx_id,
598 0x61c8762c3aa05df7,
599 fidl::encoding::DynamicFlags::empty(),
600 )
601 }
602}
603
604#[must_use = "FIDL methods require a response to be sent"]
605#[derive(Debug)]
606pub struct ChildRealmCreateChildrenResponder {
607 control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
608 tx_id: u32,
609}
610
611impl std::ops::Drop for ChildRealmCreateChildrenResponder {
615 fn drop(&mut self) {
616 self.control_handle.shutdown();
617 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
619 }
620}
621
622impl fidl::endpoints::Responder for ChildRealmCreateChildrenResponder {
623 type ControlHandle = ChildRealmControlHandle;
624
625 fn control_handle(&self) -> &ChildRealmControlHandle {
626 &self.control_handle
627 }
628
629 fn drop_without_shutdown(mut self) {
630 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
632 std::mem::forget(self);
634 }
635}
636
637impl ChildRealmCreateChildrenResponder {
638 pub fn send(self) -> Result<(), fidl::Error> {
642 let _result = self.send_raw();
643 if _result.is_err() {
644 self.control_handle.shutdown();
645 }
646 self.drop_without_shutdown();
647 _result
648 }
649
650 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
652 let _result = self.send_raw();
653 self.drop_without_shutdown();
654 _result
655 }
656
657 fn send_raw(&self) -> Result<(), fidl::Error> {
658 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
659 (),
660 self.tx_id,
661 0x37a93e012377095c,
662 fidl::encoding::DynamicFlags::empty(),
663 )
664 }
665}
666
667mod internal {
668 use super::*;
669}