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_session_power__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct HandoffTakeResponse {
16 pub lease: fidl::Handle,
26}
27
28impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect> for HandoffTakeResponse {}
29
30#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
31pub struct HandoffMarker;
32
33impl fidl::endpoints::ProtocolMarker for HandoffMarker {
34 type Proxy = HandoffProxy;
35 type RequestStream = HandoffRequestStream;
36 #[cfg(target_os = "fuchsia")]
37 type SynchronousProxy = HandoffSynchronousProxy;
38
39 const DEBUG_NAME: &'static str = "fuchsia.session.power.Handoff";
40}
41impl fidl::endpoints::DiscoverableProtocolMarker for HandoffMarker {}
42pub type HandoffTakeResult = Result<fidl::Handle, HandoffError>;
43
44pub trait HandoffProxyInterface: Send + Sync {
45 type TakeResponseFut: std::future::Future<Output = Result<HandoffTakeResult, fidl::Error>>
46 + Send;
47 fn r#take(&self) -> Self::TakeResponseFut;
48}
49#[derive(Debug)]
50#[cfg(target_os = "fuchsia")]
51pub struct HandoffSynchronousProxy {
52 client: fidl::client::sync::Client,
53}
54
55#[cfg(target_os = "fuchsia")]
56impl fidl::endpoints::SynchronousProxy for HandoffSynchronousProxy {
57 type Proxy = HandoffProxy;
58 type Protocol = HandoffMarker;
59
60 fn from_channel(inner: fidl::Channel) -> Self {
61 Self::new(inner)
62 }
63
64 fn into_channel(self) -> fidl::Channel {
65 self.client.into_channel()
66 }
67
68 fn as_channel(&self) -> &fidl::Channel {
69 self.client.as_channel()
70 }
71}
72
73#[cfg(target_os = "fuchsia")]
74impl HandoffSynchronousProxy {
75 pub fn new(channel: fidl::Channel) -> Self {
76 let protocol_name = <HandoffMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
77 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
78 }
79
80 pub fn into_channel(self) -> fidl::Channel {
81 self.client.into_channel()
82 }
83
84 pub fn wait_for_event(
87 &self,
88 deadline: zx::MonotonicInstant,
89 ) -> Result<HandoffEvent, fidl::Error> {
90 HandoffEvent::decode(self.client.wait_for_event(deadline)?)
91 }
92
93 pub fn r#take(
95 &self,
96 ___deadline: zx::MonotonicInstant,
97 ) -> Result<HandoffTakeResult, fidl::Error> {
98 let _response = self.client.send_query::<
99 fidl::encoding::EmptyPayload,
100 fidl::encoding::FlexibleResultType<HandoffTakeResponse, HandoffError>,
101 >(
102 (),
103 0x7150089bdc73770b,
104 fidl::encoding::DynamicFlags::FLEXIBLE,
105 ___deadline,
106 )?
107 .into_result::<HandoffMarker>("take")?;
108 Ok(_response.map(|x| x.lease))
109 }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl From<HandoffSynchronousProxy> for zx::Handle {
114 fn from(value: HandoffSynchronousProxy) -> Self {
115 value.into_channel().into()
116 }
117}
118
119#[cfg(target_os = "fuchsia")]
120impl From<fidl::Channel> for HandoffSynchronousProxy {
121 fn from(value: fidl::Channel) -> Self {
122 Self::new(value)
123 }
124}
125
126#[cfg(target_os = "fuchsia")]
127impl fidl::endpoints::FromClient for HandoffSynchronousProxy {
128 type Protocol = HandoffMarker;
129
130 fn from_client(value: fidl::endpoints::ClientEnd<HandoffMarker>) -> Self {
131 Self::new(value.into_channel())
132 }
133}
134
135#[derive(Debug, Clone)]
136pub struct HandoffProxy {
137 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
138}
139
140impl fidl::endpoints::Proxy for HandoffProxy {
141 type Protocol = HandoffMarker;
142
143 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
144 Self::new(inner)
145 }
146
147 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
148 self.client.into_channel().map_err(|client| Self { client })
149 }
150
151 fn as_channel(&self) -> &::fidl::AsyncChannel {
152 self.client.as_channel()
153 }
154}
155
156impl HandoffProxy {
157 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
159 let protocol_name = <HandoffMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
160 Self { client: fidl::client::Client::new(channel, protocol_name) }
161 }
162
163 pub fn take_event_stream(&self) -> HandoffEventStream {
169 HandoffEventStream { event_receiver: self.client.take_event_receiver() }
170 }
171
172 pub fn r#take(
174 &self,
175 ) -> fidl::client::QueryResponseFut<
176 HandoffTakeResult,
177 fidl::encoding::DefaultFuchsiaResourceDialect,
178 > {
179 HandoffProxyInterface::r#take(self)
180 }
181}
182
183impl HandoffProxyInterface for HandoffProxy {
184 type TakeResponseFut = fidl::client::QueryResponseFut<
185 HandoffTakeResult,
186 fidl::encoding::DefaultFuchsiaResourceDialect,
187 >;
188 fn r#take(&self) -> Self::TakeResponseFut {
189 fn _decode(
190 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
191 ) -> Result<HandoffTakeResult, fidl::Error> {
192 let _response = fidl::client::decode_transaction_body::<
193 fidl::encoding::FlexibleResultType<HandoffTakeResponse, HandoffError>,
194 fidl::encoding::DefaultFuchsiaResourceDialect,
195 0x7150089bdc73770b,
196 >(_buf?)?
197 .into_result::<HandoffMarker>("take")?;
198 Ok(_response.map(|x| x.lease))
199 }
200 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, HandoffTakeResult>(
201 (),
202 0x7150089bdc73770b,
203 fidl::encoding::DynamicFlags::FLEXIBLE,
204 _decode,
205 )
206 }
207}
208
209pub struct HandoffEventStream {
210 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
211}
212
213impl std::marker::Unpin for HandoffEventStream {}
214
215impl futures::stream::FusedStream for HandoffEventStream {
216 fn is_terminated(&self) -> bool {
217 self.event_receiver.is_terminated()
218 }
219}
220
221impl futures::Stream for HandoffEventStream {
222 type Item = Result<HandoffEvent, fidl::Error>;
223
224 fn poll_next(
225 mut self: std::pin::Pin<&mut Self>,
226 cx: &mut std::task::Context<'_>,
227 ) -> std::task::Poll<Option<Self::Item>> {
228 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
229 &mut self.event_receiver,
230 cx
231 )?) {
232 Some(buf) => std::task::Poll::Ready(Some(HandoffEvent::decode(buf))),
233 None => std::task::Poll::Ready(None),
234 }
235 }
236}
237
238#[derive(Debug)]
239pub enum HandoffEvent {
240 #[non_exhaustive]
241 _UnknownEvent {
242 ordinal: u64,
244 },
245}
246
247impl HandoffEvent {
248 fn decode(
250 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
251 ) -> Result<HandoffEvent, fidl::Error> {
252 let (bytes, _handles) = buf.split_mut();
253 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
254 debug_assert_eq!(tx_header.tx_id, 0);
255 match tx_header.ordinal {
256 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
257 Ok(HandoffEvent::_UnknownEvent { ordinal: tx_header.ordinal })
258 }
259 _ => Err(fidl::Error::UnknownOrdinal {
260 ordinal: tx_header.ordinal,
261 protocol_name: <HandoffMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
262 }),
263 }
264 }
265}
266
267pub struct HandoffRequestStream {
269 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
270 is_terminated: bool,
271}
272
273impl std::marker::Unpin for HandoffRequestStream {}
274
275impl futures::stream::FusedStream for HandoffRequestStream {
276 fn is_terminated(&self) -> bool {
277 self.is_terminated
278 }
279}
280
281impl fidl::endpoints::RequestStream for HandoffRequestStream {
282 type Protocol = HandoffMarker;
283 type ControlHandle = HandoffControlHandle;
284
285 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
286 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
287 }
288
289 fn control_handle(&self) -> Self::ControlHandle {
290 HandoffControlHandle { inner: self.inner.clone() }
291 }
292
293 fn into_inner(
294 self,
295 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
296 {
297 (self.inner, self.is_terminated)
298 }
299
300 fn from_inner(
301 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
302 is_terminated: bool,
303 ) -> Self {
304 Self { inner, is_terminated }
305 }
306}
307
308impl futures::Stream for HandoffRequestStream {
309 type Item = Result<HandoffRequest, fidl::Error>;
310
311 fn poll_next(
312 mut self: std::pin::Pin<&mut Self>,
313 cx: &mut std::task::Context<'_>,
314 ) -> std::task::Poll<Option<Self::Item>> {
315 let this = &mut *self;
316 if this.inner.check_shutdown(cx) {
317 this.is_terminated = true;
318 return std::task::Poll::Ready(None);
319 }
320 if this.is_terminated {
321 panic!("polled HandoffRequestStream after completion");
322 }
323 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
324 |bytes, handles| {
325 match this.inner.channel().read_etc(cx, bytes, handles) {
326 std::task::Poll::Ready(Ok(())) => {}
327 std::task::Poll::Pending => return std::task::Poll::Pending,
328 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
329 this.is_terminated = true;
330 return std::task::Poll::Ready(None);
331 }
332 std::task::Poll::Ready(Err(e)) => {
333 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
334 e.into(),
335 ))));
336 }
337 }
338
339 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
341
342 std::task::Poll::Ready(Some(match header.ordinal {
343 0x7150089bdc73770b => {
344 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
345 let mut req = fidl::new_empty!(
346 fidl::encoding::EmptyPayload,
347 fidl::encoding::DefaultFuchsiaResourceDialect
348 );
349 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
350 let control_handle = HandoffControlHandle { inner: this.inner.clone() };
351 Ok(HandoffRequest::Take {
352 responder: HandoffTakeResponder {
353 control_handle: std::mem::ManuallyDrop::new(control_handle),
354 tx_id: header.tx_id,
355 },
356 })
357 }
358 _ if header.tx_id == 0
359 && header
360 .dynamic_flags()
361 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
362 {
363 Ok(HandoffRequest::_UnknownMethod {
364 ordinal: header.ordinal,
365 control_handle: HandoffControlHandle { inner: this.inner.clone() },
366 method_type: fidl::MethodType::OneWay,
367 })
368 }
369 _ if header
370 .dynamic_flags()
371 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
372 {
373 this.inner.send_framework_err(
374 fidl::encoding::FrameworkErr::UnknownMethod,
375 header.tx_id,
376 header.ordinal,
377 header.dynamic_flags(),
378 (bytes, handles),
379 )?;
380 Ok(HandoffRequest::_UnknownMethod {
381 ordinal: header.ordinal,
382 control_handle: HandoffControlHandle { inner: this.inner.clone() },
383 method_type: fidl::MethodType::TwoWay,
384 })
385 }
386 _ => Err(fidl::Error::UnknownOrdinal {
387 ordinal: header.ordinal,
388 protocol_name:
389 <HandoffMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
390 }),
391 }))
392 },
393 )
394 }
395}
396
397#[derive(Debug)]
405pub enum HandoffRequest {
406 Take { responder: HandoffTakeResponder },
408 #[non_exhaustive]
410 _UnknownMethod {
411 ordinal: u64,
413 control_handle: HandoffControlHandle,
414 method_type: fidl::MethodType,
415 },
416}
417
418impl HandoffRequest {
419 #[allow(irrefutable_let_patterns)]
420 pub fn into_take(self) -> Option<(HandoffTakeResponder)> {
421 if let HandoffRequest::Take { responder } = self { Some((responder)) } else { None }
422 }
423
424 pub fn method_name(&self) -> &'static str {
426 match *self {
427 HandoffRequest::Take { .. } => "take",
428 HandoffRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
429 "unknown one-way method"
430 }
431 HandoffRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
432 "unknown two-way method"
433 }
434 }
435 }
436}
437
438#[derive(Debug, Clone)]
439pub struct HandoffControlHandle {
440 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
441}
442
443impl fidl::endpoints::ControlHandle for HandoffControlHandle {
444 fn shutdown(&self) {
445 self.inner.shutdown()
446 }
447 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
448 self.inner.shutdown_with_epitaph(status)
449 }
450
451 fn is_closed(&self) -> bool {
452 self.inner.channel().is_closed()
453 }
454 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
455 self.inner.channel().on_closed()
456 }
457
458 #[cfg(target_os = "fuchsia")]
459 fn signal_peer(
460 &self,
461 clear_mask: zx::Signals,
462 set_mask: zx::Signals,
463 ) -> Result<(), zx_status::Status> {
464 use fidl::Peered;
465 self.inner.channel().signal_peer(clear_mask, set_mask)
466 }
467}
468
469impl HandoffControlHandle {}
470
471#[must_use = "FIDL methods require a response to be sent"]
472#[derive(Debug)]
473pub struct HandoffTakeResponder {
474 control_handle: std::mem::ManuallyDrop<HandoffControlHandle>,
475 tx_id: u32,
476}
477
478impl std::ops::Drop for HandoffTakeResponder {
482 fn drop(&mut self) {
483 self.control_handle.shutdown();
484 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
486 }
487}
488
489impl fidl::endpoints::Responder for HandoffTakeResponder {
490 type ControlHandle = HandoffControlHandle;
491
492 fn control_handle(&self) -> &HandoffControlHandle {
493 &self.control_handle
494 }
495
496 fn drop_without_shutdown(mut self) {
497 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
499 std::mem::forget(self);
501 }
502}
503
504impl HandoffTakeResponder {
505 pub fn send(self, mut result: Result<fidl::Handle, HandoffError>) -> Result<(), fidl::Error> {
509 let _result = self.send_raw(result);
510 if _result.is_err() {
511 self.control_handle.shutdown();
512 }
513 self.drop_without_shutdown();
514 _result
515 }
516
517 pub fn send_no_shutdown_on_err(
519 self,
520 mut result: Result<fidl::Handle, HandoffError>,
521 ) -> Result<(), fidl::Error> {
522 let _result = self.send_raw(result);
523 self.drop_without_shutdown();
524 _result
525 }
526
527 fn send_raw(&self, mut result: Result<fidl::Handle, HandoffError>) -> Result<(), fidl::Error> {
528 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
529 HandoffTakeResponse,
530 HandoffError,
531 >>(
532 fidl::encoding::FlexibleResult::new(result.map(|lease| (lease,))),
533 self.tx_id,
534 0x7150089bdc73770b,
535 fidl::encoding::DynamicFlags::FLEXIBLE,
536 )
537 }
538}
539
540mod internal {
541 use super::*;
542
543 impl fidl::encoding::ResourceTypeMarker for HandoffTakeResponse {
544 type Borrowed<'a> = &'a mut Self;
545 fn take_or_borrow<'a>(
546 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
547 ) -> Self::Borrowed<'a> {
548 value
549 }
550 }
551
552 unsafe impl fidl::encoding::TypeMarker for HandoffTakeResponse {
553 type Owned = Self;
554
555 #[inline(always)]
556 fn inline_align(_context: fidl::encoding::Context) -> usize {
557 4
558 }
559
560 #[inline(always)]
561 fn inline_size(_context: fidl::encoding::Context) -> usize {
562 4
563 }
564 }
565
566 unsafe impl
567 fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
568 for &mut HandoffTakeResponse
569 {
570 #[inline]
571 unsafe fn encode(
572 self,
573 encoder: &mut fidl::encoding::Encoder<
574 '_,
575 fidl::encoding::DefaultFuchsiaResourceDialect,
576 >,
577 offset: usize,
578 _depth: fidl::encoding::Depth,
579 ) -> fidl::Result<()> {
580 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
581 fidl::encoding::Encode::<
583 HandoffTakeResponse,
584 fidl::encoding::DefaultFuchsiaResourceDialect,
585 >::encode(
586 (<fidl::encoding::HandleType<
587 fidl::Handle,
588 { fidl::ObjectType::NONE.into_raw() },
589 2147483648,
590 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
591 &mut self.lease
592 ),),
593 encoder,
594 offset,
595 _depth,
596 )
597 }
598 }
599 unsafe impl<
600 T0: fidl::encoding::Encode<
601 fidl::encoding::HandleType<
602 fidl::Handle,
603 { fidl::ObjectType::NONE.into_raw() },
604 2147483648,
605 >,
606 fidl::encoding::DefaultFuchsiaResourceDialect,
607 >,
608 > fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
609 for (T0,)
610 {
611 #[inline]
612 unsafe fn encode(
613 self,
614 encoder: &mut fidl::encoding::Encoder<
615 '_,
616 fidl::encoding::DefaultFuchsiaResourceDialect,
617 >,
618 offset: usize,
619 depth: fidl::encoding::Depth,
620 ) -> fidl::Result<()> {
621 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
622 self.0.encode(encoder, offset + 0, depth)?;
626 Ok(())
627 }
628 }
629
630 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
631 for HandoffTakeResponse
632 {
633 #[inline(always)]
634 fn new_empty() -> Self {
635 Self {
636 lease: fidl::new_empty!(fidl::encoding::HandleType<fidl::Handle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
637 }
638 }
639
640 #[inline]
641 unsafe fn decode(
642 &mut self,
643 decoder: &mut fidl::encoding::Decoder<
644 '_,
645 fidl::encoding::DefaultFuchsiaResourceDialect,
646 >,
647 offset: usize,
648 _depth: fidl::encoding::Depth,
649 ) -> fidl::Result<()> {
650 decoder.debug_check_bounds::<Self>(offset);
651 fidl::decode!(fidl::encoding::HandleType<fidl::Handle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.lease, decoder, offset + 0, _depth)?;
653 Ok(())
654 }
655 }
656}