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 {
422 Some((responder))
423 } else {
424 None
425 }
426 }
427
428 pub fn method_name(&self) -> &'static str {
430 match *self {
431 HandoffRequest::Take { .. } => "take",
432 HandoffRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
433 "unknown one-way method"
434 }
435 HandoffRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
436 "unknown two-way method"
437 }
438 }
439 }
440}
441
442#[derive(Debug, Clone)]
443pub struct HandoffControlHandle {
444 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
445}
446
447impl fidl::endpoints::ControlHandle for HandoffControlHandle {
448 fn shutdown(&self) {
449 self.inner.shutdown()
450 }
451 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
452 self.inner.shutdown_with_epitaph(status)
453 }
454
455 fn is_closed(&self) -> bool {
456 self.inner.channel().is_closed()
457 }
458 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
459 self.inner.channel().on_closed()
460 }
461
462 #[cfg(target_os = "fuchsia")]
463 fn signal_peer(
464 &self,
465 clear_mask: zx::Signals,
466 set_mask: zx::Signals,
467 ) -> Result<(), zx_status::Status> {
468 use fidl::Peered;
469 self.inner.channel().signal_peer(clear_mask, set_mask)
470 }
471}
472
473impl HandoffControlHandle {}
474
475#[must_use = "FIDL methods require a response to be sent"]
476#[derive(Debug)]
477pub struct HandoffTakeResponder {
478 control_handle: std::mem::ManuallyDrop<HandoffControlHandle>,
479 tx_id: u32,
480}
481
482impl std::ops::Drop for HandoffTakeResponder {
486 fn drop(&mut self) {
487 self.control_handle.shutdown();
488 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
490 }
491}
492
493impl fidl::endpoints::Responder for HandoffTakeResponder {
494 type ControlHandle = HandoffControlHandle;
495
496 fn control_handle(&self) -> &HandoffControlHandle {
497 &self.control_handle
498 }
499
500 fn drop_without_shutdown(mut self) {
501 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
503 std::mem::forget(self);
505 }
506}
507
508impl HandoffTakeResponder {
509 pub fn send(self, mut result: Result<fidl::Handle, HandoffError>) -> Result<(), fidl::Error> {
513 let _result = self.send_raw(result);
514 if _result.is_err() {
515 self.control_handle.shutdown();
516 }
517 self.drop_without_shutdown();
518 _result
519 }
520
521 pub fn send_no_shutdown_on_err(
523 self,
524 mut result: Result<fidl::Handle, HandoffError>,
525 ) -> Result<(), fidl::Error> {
526 let _result = self.send_raw(result);
527 self.drop_without_shutdown();
528 _result
529 }
530
531 fn send_raw(&self, mut result: Result<fidl::Handle, HandoffError>) -> Result<(), fidl::Error> {
532 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
533 HandoffTakeResponse,
534 HandoffError,
535 >>(
536 fidl::encoding::FlexibleResult::new(result.map(|lease| (lease,))),
537 self.tx_id,
538 0x7150089bdc73770b,
539 fidl::encoding::DynamicFlags::FLEXIBLE,
540 )
541 }
542}
543
544mod internal {
545 use super::*;
546
547 impl fidl::encoding::ResourceTypeMarker for HandoffTakeResponse {
548 type Borrowed<'a> = &'a mut Self;
549 fn take_or_borrow<'a>(
550 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
551 ) -> Self::Borrowed<'a> {
552 value
553 }
554 }
555
556 unsafe impl fidl::encoding::TypeMarker for HandoffTakeResponse {
557 type Owned = Self;
558
559 #[inline(always)]
560 fn inline_align(_context: fidl::encoding::Context) -> usize {
561 4
562 }
563
564 #[inline(always)]
565 fn inline_size(_context: fidl::encoding::Context) -> usize {
566 4
567 }
568 }
569
570 unsafe impl
571 fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
572 for &mut HandoffTakeResponse
573 {
574 #[inline]
575 unsafe fn encode(
576 self,
577 encoder: &mut fidl::encoding::Encoder<
578 '_,
579 fidl::encoding::DefaultFuchsiaResourceDialect,
580 >,
581 offset: usize,
582 _depth: fidl::encoding::Depth,
583 ) -> fidl::Result<()> {
584 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
585 fidl::encoding::Encode::<
587 HandoffTakeResponse,
588 fidl::encoding::DefaultFuchsiaResourceDialect,
589 >::encode(
590 (<fidl::encoding::HandleType<
591 fidl::Handle,
592 { fidl::ObjectType::NONE.into_raw() },
593 2147483648,
594 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
595 &mut self.lease
596 ),),
597 encoder,
598 offset,
599 _depth,
600 )
601 }
602 }
603 unsafe impl<
604 T0: fidl::encoding::Encode<
605 fidl::encoding::HandleType<
606 fidl::Handle,
607 { fidl::ObjectType::NONE.into_raw() },
608 2147483648,
609 >,
610 fidl::encoding::DefaultFuchsiaResourceDialect,
611 >,
612 >
613 fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
614 for (T0,)
615 {
616 #[inline]
617 unsafe fn encode(
618 self,
619 encoder: &mut fidl::encoding::Encoder<
620 '_,
621 fidl::encoding::DefaultFuchsiaResourceDialect,
622 >,
623 offset: usize,
624 depth: fidl::encoding::Depth,
625 ) -> fidl::Result<()> {
626 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
627 self.0.encode(encoder, offset + 0, depth)?;
631 Ok(())
632 }
633 }
634
635 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
636 for HandoffTakeResponse
637 {
638 #[inline(always)]
639 fn new_empty() -> Self {
640 Self {
641 lease: fidl::new_empty!(fidl::encoding::HandleType<fidl::Handle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
642 }
643 }
644
645 #[inline]
646 unsafe fn decode(
647 &mut self,
648 decoder: &mut fidl::encoding::Decoder<
649 '_,
650 fidl::encoding::DefaultFuchsiaResourceDialect,
651 >,
652 offset: usize,
653 _depth: fidl::encoding::Depth,
654 ) -> fidl::Result<()> {
655 decoder.debug_check_bounds::<Self>(offset);
656 fidl::decode!(fidl::encoding::HandleType<fidl::Handle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.lease, decoder, offset + 0, _depth)?;
658 Ok(())
659 }
660 }
661}