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_process_lifecycle_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Default, PartialEq)]
15pub struct LifecycleOnEscrowRequest {
16 pub outgoing_dir: Option<fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>>,
20 pub escrowed_dictionary: Option<fidl_fuchsia_component_sandbox::DictionaryRef>,
33 #[doc(hidden)]
34 pub __source_breaking: fidl::marker::SourceBreaking,
35}
36
37impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for LifecycleOnEscrowRequest {}
38
39#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
40pub struct LifecycleMarker;
41
42impl fidl::endpoints::ProtocolMarker for LifecycleMarker {
43 type Proxy = LifecycleProxy;
44 type RequestStream = LifecycleRequestStream;
45 #[cfg(target_os = "fuchsia")]
46 type SynchronousProxy = LifecycleSynchronousProxy;
47
48 const DEBUG_NAME: &'static str = "(anonymous) Lifecycle";
49}
50
51pub trait LifecycleProxyInterface: Send + Sync {
52 fn r#stop(&self) -> Result<(), fidl::Error>;
53}
54#[derive(Debug)]
55#[cfg(target_os = "fuchsia")]
56pub struct LifecycleSynchronousProxy {
57 client: fidl::client::sync::Client,
58}
59
60#[cfg(target_os = "fuchsia")]
61impl fidl::endpoints::SynchronousProxy for LifecycleSynchronousProxy {
62 type Proxy = LifecycleProxy;
63 type Protocol = LifecycleMarker;
64
65 fn from_channel(inner: fidl::Channel) -> Self {
66 Self::new(inner)
67 }
68
69 fn into_channel(self) -> fidl::Channel {
70 self.client.into_channel()
71 }
72
73 fn as_channel(&self) -> &fidl::Channel {
74 self.client.as_channel()
75 }
76}
77
78#[cfg(target_os = "fuchsia")]
79impl LifecycleSynchronousProxy {
80 pub fn new(channel: fidl::Channel) -> Self {
81 let protocol_name = <LifecycleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
82 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
83 }
84
85 pub fn into_channel(self) -> fidl::Channel {
86 self.client.into_channel()
87 }
88
89 pub fn wait_for_event(
92 &self,
93 deadline: zx::MonotonicInstant,
94 ) -> Result<LifecycleEvent, fidl::Error> {
95 LifecycleEvent::decode(self.client.wait_for_event(deadline)?)
96 }
97
98 pub fn r#stop(&self) -> Result<(), fidl::Error> {
104 self.client.send::<fidl::encoding::EmptyPayload>(
105 (),
106 0x64b176f1744c6f15,
107 fidl::encoding::DynamicFlags::empty(),
108 )
109 }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl From<LifecycleSynchronousProxy> for zx::Handle {
114 fn from(value: LifecycleSynchronousProxy) -> Self {
115 value.into_channel().into()
116 }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl From<fidl::Channel> for LifecycleSynchronousProxy {
121 fn from(value: fidl::Channel) -> Self {
122 Self::new(value)
123 }
124}
125
126#[derive(Debug, Clone)]
127pub struct LifecycleProxy {
128 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
129}
130
131impl fidl::endpoints::Proxy for LifecycleProxy {
132 type Protocol = LifecycleMarker;
133
134 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
135 Self::new(inner)
136 }
137
138 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
139 self.client.into_channel().map_err(|client| Self { client })
140 }
141
142 fn as_channel(&self) -> &::fidl::AsyncChannel {
143 self.client.as_channel()
144 }
145}
146
147impl LifecycleProxy {
148 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
150 let protocol_name = <LifecycleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
151 Self { client: fidl::client::Client::new(channel, protocol_name) }
152 }
153
154 pub fn take_event_stream(&self) -> LifecycleEventStream {
160 LifecycleEventStream { event_receiver: self.client.take_event_receiver() }
161 }
162
163 pub fn r#stop(&self) -> Result<(), fidl::Error> {
169 LifecycleProxyInterface::r#stop(self)
170 }
171}
172
173impl LifecycleProxyInterface for LifecycleProxy {
174 fn r#stop(&self) -> Result<(), fidl::Error> {
175 self.client.send::<fidl::encoding::EmptyPayload>(
176 (),
177 0x64b176f1744c6f15,
178 fidl::encoding::DynamicFlags::empty(),
179 )
180 }
181}
182
183pub struct LifecycleEventStream {
184 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
185}
186
187impl std::marker::Unpin for LifecycleEventStream {}
188
189impl futures::stream::FusedStream for LifecycleEventStream {
190 fn is_terminated(&self) -> bool {
191 self.event_receiver.is_terminated()
192 }
193}
194
195impl futures::Stream for LifecycleEventStream {
196 type Item = Result<LifecycleEvent, fidl::Error>;
197
198 fn poll_next(
199 mut self: std::pin::Pin<&mut Self>,
200 cx: &mut std::task::Context<'_>,
201 ) -> std::task::Poll<Option<Self::Item>> {
202 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
203 &mut self.event_receiver,
204 cx
205 )?) {
206 Some(buf) => std::task::Poll::Ready(Some(LifecycleEvent::decode(buf))),
207 None => std::task::Poll::Ready(None),
208 }
209 }
210}
211
212#[derive(Debug)]
213pub enum LifecycleEvent {
214 OnEscrow { payload: LifecycleOnEscrowRequest },
215}
216
217impl LifecycleEvent {
218 #[allow(irrefutable_let_patterns)]
219 pub fn into_on_escrow(self) -> Option<LifecycleOnEscrowRequest> {
220 if let LifecycleEvent::OnEscrow { payload } = self {
221 Some((payload))
222 } else {
223 None
224 }
225 }
226
227 fn decode(
229 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
230 ) -> Result<LifecycleEvent, fidl::Error> {
231 let (bytes, _handles) = buf.split_mut();
232 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
233 debug_assert_eq!(tx_header.tx_id, 0);
234 match tx_header.ordinal {
235 0x3de9c2fcb734ed48 => {
236 let mut out = fidl::new_empty!(
237 LifecycleOnEscrowRequest,
238 fidl::encoding::DefaultFuchsiaResourceDialect
239 );
240 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<LifecycleOnEscrowRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
241 Ok((LifecycleEvent::OnEscrow { payload: out }))
242 }
243 _ => Err(fidl::Error::UnknownOrdinal {
244 ordinal: tx_header.ordinal,
245 protocol_name: <LifecycleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
246 }),
247 }
248 }
249}
250
251pub struct LifecycleRequestStream {
253 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
254 is_terminated: bool,
255}
256
257impl std::marker::Unpin for LifecycleRequestStream {}
258
259impl futures::stream::FusedStream for LifecycleRequestStream {
260 fn is_terminated(&self) -> bool {
261 self.is_terminated
262 }
263}
264
265impl fidl::endpoints::RequestStream for LifecycleRequestStream {
266 type Protocol = LifecycleMarker;
267 type ControlHandle = LifecycleControlHandle;
268
269 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
270 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
271 }
272
273 fn control_handle(&self) -> Self::ControlHandle {
274 LifecycleControlHandle { inner: self.inner.clone() }
275 }
276
277 fn into_inner(
278 self,
279 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
280 {
281 (self.inner, self.is_terminated)
282 }
283
284 fn from_inner(
285 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
286 is_terminated: bool,
287 ) -> Self {
288 Self { inner, is_terminated }
289 }
290}
291
292impl futures::Stream for LifecycleRequestStream {
293 type Item = Result<LifecycleRequest, fidl::Error>;
294
295 fn poll_next(
296 mut self: std::pin::Pin<&mut Self>,
297 cx: &mut std::task::Context<'_>,
298 ) -> std::task::Poll<Option<Self::Item>> {
299 let this = &mut *self;
300 if this.inner.check_shutdown(cx) {
301 this.is_terminated = true;
302 return std::task::Poll::Ready(None);
303 }
304 if this.is_terminated {
305 panic!("polled LifecycleRequestStream after completion");
306 }
307 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
308 |bytes, handles| {
309 match this.inner.channel().read_etc(cx, bytes, handles) {
310 std::task::Poll::Ready(Ok(())) => {}
311 std::task::Poll::Pending => return std::task::Poll::Pending,
312 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
313 this.is_terminated = true;
314 return std::task::Poll::Ready(None);
315 }
316 std::task::Poll::Ready(Err(e)) => {
317 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
318 e.into(),
319 ))))
320 }
321 }
322
323 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
325
326 std::task::Poll::Ready(Some(match header.ordinal {
327 0x64b176f1744c6f15 => {
328 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
329 let mut req = fidl::new_empty!(
330 fidl::encoding::EmptyPayload,
331 fidl::encoding::DefaultFuchsiaResourceDialect
332 );
333 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
334 let control_handle = LifecycleControlHandle { inner: this.inner.clone() };
335 Ok(LifecycleRequest::Stop { control_handle })
336 }
337 _ => Err(fidl::Error::UnknownOrdinal {
338 ordinal: header.ordinal,
339 protocol_name:
340 <LifecycleMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
341 }),
342 }))
343 },
344 )
345 }
346}
347
348#[derive(Debug)]
356pub enum LifecycleRequest {
357 Stop { control_handle: LifecycleControlHandle },
363}
364
365impl LifecycleRequest {
366 #[allow(irrefutable_let_patterns)]
367 pub fn into_stop(self) -> Option<(LifecycleControlHandle)> {
368 if let LifecycleRequest::Stop { control_handle } = self {
369 Some((control_handle))
370 } else {
371 None
372 }
373 }
374
375 pub fn method_name(&self) -> &'static str {
377 match *self {
378 LifecycleRequest::Stop { .. } => "stop",
379 }
380 }
381}
382
383#[derive(Debug, Clone)]
384pub struct LifecycleControlHandle {
385 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
386}
387
388impl fidl::endpoints::ControlHandle for LifecycleControlHandle {
389 fn shutdown(&self) {
390 self.inner.shutdown()
391 }
392 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
393 self.inner.shutdown_with_epitaph(status)
394 }
395
396 fn is_closed(&self) -> bool {
397 self.inner.channel().is_closed()
398 }
399 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
400 self.inner.channel().on_closed()
401 }
402
403 #[cfg(target_os = "fuchsia")]
404 fn signal_peer(
405 &self,
406 clear_mask: zx::Signals,
407 set_mask: zx::Signals,
408 ) -> Result<(), zx_status::Status> {
409 use fidl::Peered;
410 self.inner.channel().signal_peer(clear_mask, set_mask)
411 }
412}
413
414impl LifecycleControlHandle {
415 pub fn send_on_escrow(&self, mut payload: LifecycleOnEscrowRequest) -> Result<(), fidl::Error> {
416 self.inner.send::<LifecycleOnEscrowRequest>(
417 &mut payload,
418 0,
419 0x3de9c2fcb734ed48,
420 fidl::encoding::DynamicFlags::empty(),
421 )
422 }
423}
424
425mod internal {
426 use super::*;
427
428 impl LifecycleOnEscrowRequest {
429 #[inline(always)]
430 fn max_ordinal_present(&self) -> u64 {
431 if let Some(_) = self.escrowed_dictionary {
432 return 2;
433 }
434 if let Some(_) = self.outgoing_dir {
435 return 1;
436 }
437 0
438 }
439 }
440
441 impl fidl::encoding::ResourceTypeMarker for LifecycleOnEscrowRequest {
442 type Borrowed<'a> = &'a mut Self;
443 fn take_or_borrow<'a>(
444 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
445 ) -> Self::Borrowed<'a> {
446 value
447 }
448 }
449
450 unsafe impl fidl::encoding::TypeMarker for LifecycleOnEscrowRequest {
451 type Owned = Self;
452
453 #[inline(always)]
454 fn inline_align(_context: fidl::encoding::Context) -> usize {
455 8
456 }
457
458 #[inline(always)]
459 fn inline_size(_context: fidl::encoding::Context) -> usize {
460 16
461 }
462 }
463
464 unsafe impl
465 fidl::encoding::Encode<
466 LifecycleOnEscrowRequest,
467 fidl::encoding::DefaultFuchsiaResourceDialect,
468 > for &mut LifecycleOnEscrowRequest
469 {
470 unsafe fn encode(
471 self,
472 encoder: &mut fidl::encoding::Encoder<
473 '_,
474 fidl::encoding::DefaultFuchsiaResourceDialect,
475 >,
476 offset: usize,
477 mut depth: fidl::encoding::Depth,
478 ) -> fidl::Result<()> {
479 encoder.debug_check_bounds::<LifecycleOnEscrowRequest>(offset);
480 let max_ordinal: u64 = self.max_ordinal_present();
482 encoder.write_num(max_ordinal, offset);
483 encoder.write_num(fidl::encoding::ALLOC_PRESENT_U64, offset + 8);
484 if max_ordinal == 0 {
486 return Ok(());
487 }
488 depth.increment()?;
489 let envelope_size = 8;
490 let bytes_len = max_ordinal as usize * envelope_size;
491 #[allow(unused_variables)]
492 let offset = encoder.out_of_line_offset(bytes_len);
493 let mut _prev_end_offset: usize = 0;
494 if 1 > max_ordinal {
495 return Ok(());
496 }
497
498 let cur_offset: usize = (1 - 1) * envelope_size;
501
502 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
504
505 fidl::encoding::encode_in_envelope_optional::<
510 fidl::encoding::Endpoint<
511 fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
512 >,
513 fidl::encoding::DefaultFuchsiaResourceDialect,
514 >(
515 self.outgoing_dir.as_mut().map(
516 <fidl::encoding::Endpoint<
517 fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
518 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow,
519 ),
520 encoder,
521 offset + cur_offset,
522 depth,
523 )?;
524
525 _prev_end_offset = cur_offset + envelope_size;
526 if 2 > max_ordinal {
527 return Ok(());
528 }
529
530 let cur_offset: usize = (2 - 1) * envelope_size;
533
534 encoder.padding(offset + _prev_end_offset, cur_offset - _prev_end_offset);
536
537 fidl::encoding::encode_in_envelope_optional::<fidl_fuchsia_component_sandbox::DictionaryRef, fidl::encoding::DefaultFuchsiaResourceDialect>(
542 self.escrowed_dictionary.as_mut().map(<fidl_fuchsia_component_sandbox::DictionaryRef as fidl::encoding::ResourceTypeMarker>::take_or_borrow),
543 encoder, offset + cur_offset, depth
544 )?;
545
546 _prev_end_offset = cur_offset + envelope_size;
547
548 Ok(())
549 }
550 }
551
552 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
553 for LifecycleOnEscrowRequest
554 {
555 #[inline(always)]
556 fn new_empty() -> Self {
557 Self::default()
558 }
559
560 unsafe fn decode(
561 &mut self,
562 decoder: &mut fidl::encoding::Decoder<
563 '_,
564 fidl::encoding::DefaultFuchsiaResourceDialect,
565 >,
566 offset: usize,
567 mut depth: fidl::encoding::Depth,
568 ) -> fidl::Result<()> {
569 decoder.debug_check_bounds::<Self>(offset);
570 let len = match fidl::encoding::decode_vector_header(decoder, offset)? {
571 None => return Err(fidl::Error::NotNullable),
572 Some(len) => len,
573 };
574 if len == 0 {
576 return Ok(());
577 };
578 depth.increment()?;
579 let envelope_size = 8;
580 let bytes_len = len * envelope_size;
581 let offset = decoder.out_of_line_offset(bytes_len)?;
582 let mut _next_ordinal_to_read = 0;
584 let mut next_offset = offset;
585 let end_offset = offset + bytes_len;
586 _next_ordinal_to_read += 1;
587 if next_offset >= end_offset {
588 return Ok(());
589 }
590
591 while _next_ordinal_to_read < 1 {
593 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
594 _next_ordinal_to_read += 1;
595 next_offset += envelope_size;
596 }
597
598 let next_out_of_line = decoder.next_out_of_line();
599 let handles_before = decoder.remaining_handles();
600 if let Some((inlined, num_bytes, num_handles)) =
601 fidl::encoding::decode_envelope_header(decoder, next_offset)?
602 {
603 let member_inline_size = <fidl::encoding::Endpoint<
604 fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
605 > as fidl::encoding::TypeMarker>::inline_size(
606 decoder.context
607 );
608 if inlined != (member_inline_size <= 4) {
609 return Err(fidl::Error::InvalidInlineBitInEnvelope);
610 }
611 let inner_offset;
612 let mut inner_depth = depth.clone();
613 if inlined {
614 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
615 inner_offset = next_offset;
616 } else {
617 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
618 inner_depth.increment()?;
619 }
620 let val_ref = self.outgoing_dir.get_or_insert_with(|| {
621 fidl::new_empty!(
622 fidl::encoding::Endpoint<
623 fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
624 >,
625 fidl::encoding::DefaultFuchsiaResourceDialect
626 )
627 });
628 fidl::decode!(
629 fidl::encoding::Endpoint<
630 fidl::endpoints::ServerEnd<fidl_fuchsia_io::DirectoryMarker>,
631 >,
632 fidl::encoding::DefaultFuchsiaResourceDialect,
633 val_ref,
634 decoder,
635 inner_offset,
636 inner_depth
637 )?;
638 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
639 {
640 return Err(fidl::Error::InvalidNumBytesInEnvelope);
641 }
642 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
643 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
644 }
645 }
646
647 next_offset += envelope_size;
648 _next_ordinal_to_read += 1;
649 if next_offset >= end_offset {
650 return Ok(());
651 }
652
653 while _next_ordinal_to_read < 2 {
655 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
656 _next_ordinal_to_read += 1;
657 next_offset += envelope_size;
658 }
659
660 let next_out_of_line = decoder.next_out_of_line();
661 let handles_before = decoder.remaining_handles();
662 if let Some((inlined, num_bytes, num_handles)) =
663 fidl::encoding::decode_envelope_header(decoder, next_offset)?
664 {
665 let member_inline_size = <fidl_fuchsia_component_sandbox::DictionaryRef as fidl::encoding::TypeMarker>::inline_size(decoder.context);
666 if inlined != (member_inline_size <= 4) {
667 return Err(fidl::Error::InvalidInlineBitInEnvelope);
668 }
669 let inner_offset;
670 let mut inner_depth = depth.clone();
671 if inlined {
672 decoder.check_inline_envelope_padding(next_offset, member_inline_size)?;
673 inner_offset = next_offset;
674 } else {
675 inner_offset = decoder.out_of_line_offset(member_inline_size)?;
676 inner_depth.increment()?;
677 }
678 let val_ref = self.escrowed_dictionary.get_or_insert_with(|| {
679 fidl::new_empty!(
680 fidl_fuchsia_component_sandbox::DictionaryRef,
681 fidl::encoding::DefaultFuchsiaResourceDialect
682 )
683 });
684 fidl::decode!(
685 fidl_fuchsia_component_sandbox::DictionaryRef,
686 fidl::encoding::DefaultFuchsiaResourceDialect,
687 val_ref,
688 decoder,
689 inner_offset,
690 inner_depth
691 )?;
692 if !inlined && decoder.next_out_of_line() != next_out_of_line + (num_bytes as usize)
693 {
694 return Err(fidl::Error::InvalidNumBytesInEnvelope);
695 }
696 if handles_before != decoder.remaining_handles() + (num_handles as usize) {
697 return Err(fidl::Error::InvalidNumHandlesInEnvelope);
698 }
699 }
700
701 next_offset += envelope_size;
702
703 while next_offset < end_offset {
705 _next_ordinal_to_read += 1;
706 fidl::encoding::decode_unknown_envelope(decoder, next_offset, depth)?;
707 next_offset += envelope_size;
708 }
709
710 Ok(())
711 }
712 }
713}