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::NullableHandle,
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::NullableHandle, 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::NullableHandle {
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(
509 self,
510 mut result: Result<fidl::NullableHandle, HandoffError>,
511 ) -> Result<(), fidl::Error> {
512 let _result = self.send_raw(result);
513 if _result.is_err() {
514 self.control_handle.shutdown();
515 }
516 self.drop_without_shutdown();
517 _result
518 }
519
520 pub fn send_no_shutdown_on_err(
522 self,
523 mut result: Result<fidl::NullableHandle, HandoffError>,
524 ) -> Result<(), fidl::Error> {
525 let _result = self.send_raw(result);
526 self.drop_without_shutdown();
527 _result
528 }
529
530 fn send_raw(
531 &self,
532 mut result: Result<fidl::NullableHandle, HandoffError>,
533 ) -> Result<(), fidl::Error> {
534 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
535 HandoffTakeResponse,
536 HandoffError,
537 >>(
538 fidl::encoding::FlexibleResult::new(result.map(|lease| (lease,))),
539 self.tx_id,
540 0x7150089bdc73770b,
541 fidl::encoding::DynamicFlags::FLEXIBLE,
542 )
543 }
544}
545
546mod internal {
547 use super::*;
548
549 impl fidl::encoding::ResourceTypeMarker for HandoffTakeResponse {
550 type Borrowed<'a> = &'a mut Self;
551 fn take_or_borrow<'a>(
552 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
553 ) -> Self::Borrowed<'a> {
554 value
555 }
556 }
557
558 unsafe impl fidl::encoding::TypeMarker for HandoffTakeResponse {
559 type Owned = Self;
560
561 #[inline(always)]
562 fn inline_align(_context: fidl::encoding::Context) -> usize {
563 4
564 }
565
566 #[inline(always)]
567 fn inline_size(_context: fidl::encoding::Context) -> usize {
568 4
569 }
570 }
571
572 unsafe impl
573 fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
574 for &mut HandoffTakeResponse
575 {
576 #[inline]
577 unsafe fn encode(
578 self,
579 encoder: &mut fidl::encoding::Encoder<
580 '_,
581 fidl::encoding::DefaultFuchsiaResourceDialect,
582 >,
583 offset: usize,
584 _depth: fidl::encoding::Depth,
585 ) -> fidl::Result<()> {
586 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
587 fidl::encoding::Encode::<
589 HandoffTakeResponse,
590 fidl::encoding::DefaultFuchsiaResourceDialect,
591 >::encode(
592 (<fidl::encoding::HandleType<
593 fidl::NullableHandle,
594 { fidl::ObjectType::NONE.into_raw() },
595 2147483648,
596 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
597 &mut self.lease
598 ),),
599 encoder,
600 offset,
601 _depth,
602 )
603 }
604 }
605 unsafe impl<
606 T0: fidl::encoding::Encode<
607 fidl::encoding::HandleType<
608 fidl::NullableHandle,
609 { fidl::ObjectType::NONE.into_raw() },
610 2147483648,
611 >,
612 fidl::encoding::DefaultFuchsiaResourceDialect,
613 >,
614 > fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
615 for (T0,)
616 {
617 #[inline]
618 unsafe fn encode(
619 self,
620 encoder: &mut fidl::encoding::Encoder<
621 '_,
622 fidl::encoding::DefaultFuchsiaResourceDialect,
623 >,
624 offset: usize,
625 depth: fidl::encoding::Depth,
626 ) -> fidl::Result<()> {
627 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
628 self.0.encode(encoder, offset + 0, depth)?;
632 Ok(())
633 }
634 }
635
636 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
637 for HandoffTakeResponse
638 {
639 #[inline(always)]
640 fn new_empty() -> Self {
641 Self {
642 lease: fidl::new_empty!(fidl::encoding::HandleType<fidl::NullableHandle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
643 }
644 }
645
646 #[inline]
647 unsafe fn decode(
648 &mut self,
649 decoder: &mut fidl::encoding::Decoder<
650 '_,
651 fidl::encoding::DefaultFuchsiaResourceDialect,
652 >,
653 offset: usize,
654 _depth: fidl::encoding::Depth,
655 ) -> fidl::Result<()> {
656 decoder.debug_check_bounds::<Self>(offset);
657 fidl::decode!(fidl::encoding::HandleType<fidl::NullableHandle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.lease, decoder, offset + 0, _depth)?;
659 Ok(())
660 }
661 }
662}