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 Self { client: fidl::client::sync::Client::new(channel) }
66 }
67
68 pub fn into_channel(self) -> fidl::Channel {
69 self.client.into_channel()
70 }
71
72 pub fn wait_for_event(
75 &self,
76 deadline: zx::MonotonicInstant,
77 ) -> Result<ChildRealmEvent, fidl::Error> {
78 ChildRealmEvent::decode(self.client.wait_for_event::<ChildRealmMarker>(deadline)?)
79 }
80
81 pub fn r#stop(&self) -> Result<(), fidl::Error> {
83 self.client.send::<fidl::encoding::EmptyPayload>(
84 (),
85 0x36c34aa66f2a56ab,
86 fidl::encoding::DynamicFlags::empty(),
87 )
88 }
89
90 pub fn r#stop_children(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
91 let _response = self.client.send_query::<
92 fidl::encoding::EmptyPayload,
93 fidl::encoding::EmptyPayload,
94 ChildRealmMarker,
95 >(
96 (),
97 0x61c8762c3aa05df7,
98 fidl::encoding::DynamicFlags::empty(),
99 ___deadline,
100 )?;
101 Ok(_response)
102 }
103
104 pub fn r#create_children(
109 &self,
110 mut direct_children: u16,
111 mut tree_height: u16,
112 ___deadline: zx::MonotonicInstant,
113 ) -> Result<(), fidl::Error> {
114 let _response = self.client.send_query::<
115 ChildRealmCreateChildrenRequest,
116 fidl::encoding::EmptyPayload,
117 ChildRealmMarker,
118 >(
119 (direct_children, tree_height,),
120 0x37a93e012377095c,
121 fidl::encoding::DynamicFlags::empty(),
122 ___deadline,
123 )?;
124 Ok(_response)
125 }
126}
127
128#[cfg(target_os = "fuchsia")]
129impl From<ChildRealmSynchronousProxy> for zx::NullableHandle {
130 fn from(value: ChildRealmSynchronousProxy) -> Self {
131 value.into_channel().into()
132 }
133}
134
135#[cfg(target_os = "fuchsia")]
136impl From<fidl::Channel> for ChildRealmSynchronousProxy {
137 fn from(value: fidl::Channel) -> Self {
138 Self::new(value)
139 }
140}
141
142#[cfg(target_os = "fuchsia")]
143impl fidl::endpoints::FromClient for ChildRealmSynchronousProxy {
144 type Protocol = ChildRealmMarker;
145
146 fn from_client(value: fidl::endpoints::ClientEnd<ChildRealmMarker>) -> Self {
147 Self::new(value.into_channel())
148 }
149}
150
151#[derive(Debug, Clone)]
152pub struct ChildRealmProxy {
153 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
154}
155
156impl fidl::endpoints::Proxy for ChildRealmProxy {
157 type Protocol = ChildRealmMarker;
158
159 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
160 Self::new(inner)
161 }
162
163 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
164 self.client.into_channel().map_err(|client| Self { client })
165 }
166
167 fn as_channel(&self) -> &::fidl::AsyncChannel {
168 self.client.as_channel()
169 }
170}
171
172impl ChildRealmProxy {
173 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
175 let protocol_name = <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
176 Self { client: fidl::client::Client::new(channel, protocol_name) }
177 }
178
179 pub fn take_event_stream(&self) -> ChildRealmEventStream {
185 ChildRealmEventStream { event_receiver: self.client.take_event_receiver() }
186 }
187
188 pub fn r#stop(&self) -> Result<(), fidl::Error> {
190 ChildRealmProxyInterface::r#stop(self)
191 }
192
193 pub fn r#stop_children(
194 &self,
195 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
196 ChildRealmProxyInterface::r#stop_children(self)
197 }
198
199 pub fn r#create_children(
204 &self,
205 mut direct_children: u16,
206 mut tree_height: u16,
207 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
208 ChildRealmProxyInterface::r#create_children(self, direct_children, tree_height)
209 }
210}
211
212impl ChildRealmProxyInterface for ChildRealmProxy {
213 fn r#stop(&self) -> Result<(), fidl::Error> {
214 self.client.send::<fidl::encoding::EmptyPayload>(
215 (),
216 0x36c34aa66f2a56ab,
217 fidl::encoding::DynamicFlags::empty(),
218 )
219 }
220
221 type StopChildrenResponseFut =
222 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
223 fn r#stop_children(&self) -> Self::StopChildrenResponseFut {
224 fn _decode(
225 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
226 ) -> Result<(), fidl::Error> {
227 let _response = fidl::client::decode_transaction_body::<
228 fidl::encoding::EmptyPayload,
229 fidl::encoding::DefaultFuchsiaResourceDialect,
230 0x61c8762c3aa05df7,
231 >(_buf?)?;
232 Ok(_response)
233 }
234 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
235 (),
236 0x61c8762c3aa05df7,
237 fidl::encoding::DynamicFlags::empty(),
238 _decode,
239 )
240 }
241
242 type CreateChildrenResponseFut =
243 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
244 fn r#create_children(
245 &self,
246 mut direct_children: u16,
247 mut tree_height: u16,
248 ) -> Self::CreateChildrenResponseFut {
249 fn _decode(
250 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
251 ) -> Result<(), fidl::Error> {
252 let _response = fidl::client::decode_transaction_body::<
253 fidl::encoding::EmptyPayload,
254 fidl::encoding::DefaultFuchsiaResourceDialect,
255 0x37a93e012377095c,
256 >(_buf?)?;
257 Ok(_response)
258 }
259 self.client.send_query_and_decode::<ChildRealmCreateChildrenRequest, ()>(
260 (direct_children, tree_height),
261 0x37a93e012377095c,
262 fidl::encoding::DynamicFlags::empty(),
263 _decode,
264 )
265 }
266}
267
268pub struct ChildRealmEventStream {
269 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
270}
271
272impl std::marker::Unpin for ChildRealmEventStream {}
273
274impl futures::stream::FusedStream for ChildRealmEventStream {
275 fn is_terminated(&self) -> bool {
276 self.event_receiver.is_terminated()
277 }
278}
279
280impl futures::Stream for ChildRealmEventStream {
281 type Item = Result<ChildRealmEvent, fidl::Error>;
282
283 fn poll_next(
284 mut self: std::pin::Pin<&mut Self>,
285 cx: &mut std::task::Context<'_>,
286 ) -> std::task::Poll<Option<Self::Item>> {
287 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
288 &mut self.event_receiver,
289 cx
290 )?) {
291 Some(buf) => std::task::Poll::Ready(Some(ChildRealmEvent::decode(buf))),
292 None => std::task::Poll::Ready(None),
293 }
294 }
295}
296
297#[derive(Debug)]
298pub enum ChildRealmEvent {
299 OnConnected {},
300}
301
302impl ChildRealmEvent {
303 #[allow(irrefutable_let_patterns)]
304 pub fn into_on_connected(self) -> Option<()> {
305 if let ChildRealmEvent::OnConnected {} = self { Some(()) } else { None }
306 }
307
308 fn decode(
310 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
311 ) -> Result<ChildRealmEvent, fidl::Error> {
312 let (bytes, _handles) = buf.split_mut();
313 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
314 debug_assert_eq!(tx_header.tx_id, 0);
315 match tx_header.ordinal {
316 0x68a2f3384c114a61 => {
317 let mut out = fidl::new_empty!(
318 fidl::encoding::EmptyPayload,
319 fidl::encoding::DefaultFuchsiaResourceDialect
320 );
321 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&tx_header, _body_bytes, _handles, &mut out)?;
322 Ok((ChildRealmEvent::OnConnected {}))
323 }
324 _ => Err(fidl::Error::UnknownOrdinal {
325 ordinal: tx_header.ordinal,
326 protocol_name: <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327 }),
328 }
329 }
330}
331
332pub struct ChildRealmRequestStream {
334 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
335 is_terminated: bool,
336}
337
338impl std::marker::Unpin for ChildRealmRequestStream {}
339
340impl futures::stream::FusedStream for ChildRealmRequestStream {
341 fn is_terminated(&self) -> bool {
342 self.is_terminated
343 }
344}
345
346impl fidl::endpoints::RequestStream for ChildRealmRequestStream {
347 type Protocol = ChildRealmMarker;
348 type ControlHandle = ChildRealmControlHandle;
349
350 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
351 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
352 }
353
354 fn control_handle(&self) -> Self::ControlHandle {
355 ChildRealmControlHandle { inner: self.inner.clone() }
356 }
357
358 fn into_inner(
359 self,
360 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
361 {
362 (self.inner, self.is_terminated)
363 }
364
365 fn from_inner(
366 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
367 is_terminated: bool,
368 ) -> Self {
369 Self { inner, is_terminated }
370 }
371}
372
373impl futures::Stream for ChildRealmRequestStream {
374 type Item = Result<ChildRealmRequest, fidl::Error>;
375
376 fn poll_next(
377 mut self: std::pin::Pin<&mut Self>,
378 cx: &mut std::task::Context<'_>,
379 ) -> std::task::Poll<Option<Self::Item>> {
380 let this = &mut *self;
381 if this.inner.check_shutdown(cx) {
382 this.is_terminated = true;
383 return std::task::Poll::Ready(None);
384 }
385 if this.is_terminated {
386 panic!("polled ChildRealmRequestStream after completion");
387 }
388 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
389 |bytes, handles| {
390 match this.inner.channel().read_etc(cx, bytes, handles) {
391 std::task::Poll::Ready(Ok(())) => {}
392 std::task::Poll::Pending => return std::task::Poll::Pending,
393 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
394 this.is_terminated = true;
395 return std::task::Poll::Ready(None);
396 }
397 std::task::Poll::Ready(Err(e)) => {
398 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
399 e.into(),
400 ))));
401 }
402 }
403
404 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
406
407 std::task::Poll::Ready(Some(match header.ordinal {
408 0x36c34aa66f2a56ab => {
409 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
410 let mut req = fidl::new_empty!(
411 fidl::encoding::EmptyPayload,
412 fidl::encoding::DefaultFuchsiaResourceDialect
413 );
414 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
415 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
416 Ok(ChildRealmRequest::Stop { control_handle })
417 }
418 0x61c8762c3aa05df7 => {
419 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
420 let mut req = fidl::new_empty!(
421 fidl::encoding::EmptyPayload,
422 fidl::encoding::DefaultFuchsiaResourceDialect
423 );
424 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
425 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
426 Ok(ChildRealmRequest::StopChildren {
427 responder: ChildRealmStopChildrenResponder {
428 control_handle: std::mem::ManuallyDrop::new(control_handle),
429 tx_id: header.tx_id,
430 },
431 })
432 }
433 0x37a93e012377095c => {
434 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
435 let mut req = fidl::new_empty!(
436 ChildRealmCreateChildrenRequest,
437 fidl::encoding::DefaultFuchsiaResourceDialect
438 );
439 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChildRealmCreateChildrenRequest>(&header, _body_bytes, handles, &mut req)?;
440 let control_handle = ChildRealmControlHandle { inner: this.inner.clone() };
441 Ok(ChildRealmRequest::CreateChildren {
442 direct_children: req.direct_children,
443 tree_height: req.tree_height,
444
445 responder: ChildRealmCreateChildrenResponder {
446 control_handle: std::mem::ManuallyDrop::new(control_handle),
447 tx_id: header.tx_id,
448 },
449 })
450 }
451 _ => Err(fidl::Error::UnknownOrdinal {
452 ordinal: header.ordinal,
453 protocol_name:
454 <ChildRealmMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
455 }),
456 }))
457 },
458 )
459 }
460}
461
462#[derive(Debug)]
464pub enum ChildRealmRequest {
465 Stop {
467 control_handle: ChildRealmControlHandle,
468 },
469 StopChildren {
470 responder: ChildRealmStopChildrenResponder,
471 },
472 CreateChildren {
477 direct_children: u16,
478 tree_height: u16,
479 responder: ChildRealmCreateChildrenResponder,
480 },
481}
482
483impl ChildRealmRequest {
484 #[allow(irrefutable_let_patterns)]
485 pub fn into_stop(self) -> Option<(ChildRealmControlHandle)> {
486 if let ChildRealmRequest::Stop { control_handle } = self {
487 Some((control_handle))
488 } else {
489 None
490 }
491 }
492
493 #[allow(irrefutable_let_patterns)]
494 pub fn into_stop_children(self) -> Option<(ChildRealmStopChildrenResponder)> {
495 if let ChildRealmRequest::StopChildren { responder } = self {
496 Some((responder))
497 } else {
498 None
499 }
500 }
501
502 #[allow(irrefutable_let_patterns)]
503 pub fn into_create_children(self) -> Option<(u16, u16, ChildRealmCreateChildrenResponder)> {
504 if let ChildRealmRequest::CreateChildren { direct_children, tree_height, responder } = self
505 {
506 Some((direct_children, tree_height, responder))
507 } else {
508 None
509 }
510 }
511
512 pub fn method_name(&self) -> &'static str {
514 match *self {
515 ChildRealmRequest::Stop { .. } => "stop",
516 ChildRealmRequest::StopChildren { .. } => "stop_children",
517 ChildRealmRequest::CreateChildren { .. } => "create_children",
518 }
519 }
520}
521
522#[derive(Debug, Clone)]
523pub struct ChildRealmControlHandle {
524 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
525}
526
527impl ChildRealmControlHandle {
528 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
529 self.inner.shutdown_with_epitaph(status.into())
530 }
531}
532
533impl fidl::endpoints::ControlHandle for ChildRealmControlHandle {
534 fn shutdown(&self) {
535 self.inner.shutdown()
536 }
537
538 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
539 self.inner.shutdown_with_epitaph(status)
540 }
541
542 fn is_closed(&self) -> bool {
543 self.inner.channel().is_closed()
544 }
545 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
546 self.inner.channel().on_closed()
547 }
548
549 #[cfg(target_os = "fuchsia")]
550 fn signal_peer(
551 &self,
552 clear_mask: zx::Signals,
553 set_mask: zx::Signals,
554 ) -> Result<(), zx_status::Status> {
555 use fidl::Peered;
556 self.inner.channel().signal_peer(clear_mask, set_mask)
557 }
558}
559
560impl ChildRealmControlHandle {
561 pub fn send_on_connected(&self) -> Result<(), fidl::Error> {
562 self.inner.send::<fidl::encoding::EmptyPayload>(
563 (),
564 0,
565 0x68a2f3384c114a61,
566 fidl::encoding::DynamicFlags::empty(),
567 )
568 }
569}
570
571#[must_use = "FIDL methods require a response to be sent"]
572#[derive(Debug)]
573pub struct ChildRealmStopChildrenResponder {
574 control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
575 tx_id: u32,
576}
577
578impl std::ops::Drop for ChildRealmStopChildrenResponder {
582 fn drop(&mut self) {
583 self.control_handle.shutdown();
584 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
586 }
587}
588
589impl fidl::endpoints::Responder for ChildRealmStopChildrenResponder {
590 type ControlHandle = ChildRealmControlHandle;
591
592 fn control_handle(&self) -> &ChildRealmControlHandle {
593 &self.control_handle
594 }
595
596 fn drop_without_shutdown(mut self) {
597 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
599 std::mem::forget(self);
601 }
602}
603
604impl ChildRealmStopChildrenResponder {
605 pub fn send(self) -> Result<(), fidl::Error> {
609 let _result = self.send_raw();
610 if _result.is_err() {
611 self.control_handle.shutdown();
612 }
613 self.drop_without_shutdown();
614 _result
615 }
616
617 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
619 let _result = self.send_raw();
620 self.drop_without_shutdown();
621 _result
622 }
623
624 fn send_raw(&self) -> Result<(), fidl::Error> {
625 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
626 (),
627 self.tx_id,
628 0x61c8762c3aa05df7,
629 fidl::encoding::DynamicFlags::empty(),
630 )
631 }
632}
633
634#[must_use = "FIDL methods require a response to be sent"]
635#[derive(Debug)]
636pub struct ChildRealmCreateChildrenResponder {
637 control_handle: std::mem::ManuallyDrop<ChildRealmControlHandle>,
638 tx_id: u32,
639}
640
641impl std::ops::Drop for ChildRealmCreateChildrenResponder {
645 fn drop(&mut self) {
646 self.control_handle.shutdown();
647 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
649 }
650}
651
652impl fidl::endpoints::Responder for ChildRealmCreateChildrenResponder {
653 type ControlHandle = ChildRealmControlHandle;
654
655 fn control_handle(&self) -> &ChildRealmControlHandle {
656 &self.control_handle
657 }
658
659 fn drop_without_shutdown(mut self) {
660 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
662 std::mem::forget(self);
664 }
665}
666
667impl ChildRealmCreateChildrenResponder {
668 pub fn send(self) -> Result<(), fidl::Error> {
672 let _result = self.send_raw();
673 if _result.is_err() {
674 self.control_handle.shutdown();
675 }
676 self.drop_without_shutdown();
677 _result
678 }
679
680 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
682 let _result = self.send_raw();
683 self.drop_without_shutdown();
684 _result
685 }
686
687 fn send_raw(&self) -> Result<(), fidl::Error> {
688 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
689 (),
690 self.tx_id,
691 0x37a93e012377095c,
692 fidl::encoding::DynamicFlags::empty(),
693 )
694 }
695}
696
697mod internal {
698 use super::*;
699}