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
448 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
449 self.inner.shutdown_with_epitaph(status)
450 }
451
452 fn is_closed(&self) -> bool {
453 self.inner.channel().is_closed()
454 }
455 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
456 self.inner.channel().on_closed()
457 }
458
459 #[cfg(target_os = "fuchsia")]
460 fn signal_peer(
461 &self,
462 clear_mask: zx::Signals,
463 set_mask: zx::Signals,
464 ) -> Result<(), zx_status::Status> {
465 use fidl::Peered;
466 self.inner.channel().signal_peer(clear_mask, set_mask)
467 }
468}
469
470impl HandoffControlHandle {}
471
472#[must_use = "FIDL methods require a response to be sent"]
473#[derive(Debug)]
474pub struct HandoffTakeResponder {
475 control_handle: std::mem::ManuallyDrop<HandoffControlHandle>,
476 tx_id: u32,
477}
478
479impl std::ops::Drop for HandoffTakeResponder {
483 fn drop(&mut self) {
484 self.control_handle.shutdown();
485 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
487 }
488}
489
490impl fidl::endpoints::Responder for HandoffTakeResponder {
491 type ControlHandle = HandoffControlHandle;
492
493 fn control_handle(&self) -> &HandoffControlHandle {
494 &self.control_handle
495 }
496
497 fn drop_without_shutdown(mut self) {
498 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
500 std::mem::forget(self);
502 }
503}
504
505impl HandoffTakeResponder {
506 pub fn send(
510 self,
511 mut result: Result<fidl::NullableHandle, HandoffError>,
512 ) -> 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::NullableHandle, 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(
532 &self,
533 mut result: Result<fidl::NullableHandle, HandoffError>,
534 ) -> Result<(), fidl::Error> {
535 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
536 HandoffTakeResponse,
537 HandoffError,
538 >>(
539 fidl::encoding::FlexibleResult::new(result.map(|lease| (lease,))),
540 self.tx_id,
541 0x7150089bdc73770b,
542 fidl::encoding::DynamicFlags::FLEXIBLE,
543 )
544 }
545}
546
547mod internal {
548 use super::*;
549
550 impl fidl::encoding::ResourceTypeMarker for HandoffTakeResponse {
551 type Borrowed<'a> = &'a mut Self;
552 fn take_or_borrow<'a>(
553 value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
554 ) -> Self::Borrowed<'a> {
555 value
556 }
557 }
558
559 unsafe impl fidl::encoding::TypeMarker for HandoffTakeResponse {
560 type Owned = Self;
561
562 #[inline(always)]
563 fn inline_align(_context: fidl::encoding::Context) -> usize {
564 4
565 }
566
567 #[inline(always)]
568 fn inline_size(_context: fidl::encoding::Context) -> usize {
569 4
570 }
571 }
572
573 unsafe impl
574 fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
575 for &mut HandoffTakeResponse
576 {
577 #[inline]
578 unsafe fn encode(
579 self,
580 encoder: &mut fidl::encoding::Encoder<
581 '_,
582 fidl::encoding::DefaultFuchsiaResourceDialect,
583 >,
584 offset: usize,
585 _depth: fidl::encoding::Depth,
586 ) -> fidl::Result<()> {
587 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
588 fidl::encoding::Encode::<
590 HandoffTakeResponse,
591 fidl::encoding::DefaultFuchsiaResourceDialect,
592 >::encode(
593 (<fidl::encoding::HandleType<
594 fidl::NullableHandle,
595 { fidl::ObjectType::NONE.into_raw() },
596 2147483648,
597 > as fidl::encoding::ResourceTypeMarker>::take_or_borrow(
598 &mut self.lease
599 ),),
600 encoder,
601 offset,
602 _depth,
603 )
604 }
605 }
606 unsafe impl<
607 T0: fidl::encoding::Encode<
608 fidl::encoding::HandleType<
609 fidl::NullableHandle,
610 { fidl::ObjectType::NONE.into_raw() },
611 2147483648,
612 >,
613 fidl::encoding::DefaultFuchsiaResourceDialect,
614 >,
615 > fidl::encoding::Encode<HandoffTakeResponse, fidl::encoding::DefaultFuchsiaResourceDialect>
616 for (T0,)
617 {
618 #[inline]
619 unsafe fn encode(
620 self,
621 encoder: &mut fidl::encoding::Encoder<
622 '_,
623 fidl::encoding::DefaultFuchsiaResourceDialect,
624 >,
625 offset: usize,
626 depth: fidl::encoding::Depth,
627 ) -> fidl::Result<()> {
628 encoder.debug_check_bounds::<HandoffTakeResponse>(offset);
629 self.0.encode(encoder, offset + 0, depth)?;
633 Ok(())
634 }
635 }
636
637 impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
638 for HandoffTakeResponse
639 {
640 #[inline(always)]
641 fn new_empty() -> Self {
642 Self {
643 lease: fidl::new_empty!(fidl::encoding::HandleType<fidl::NullableHandle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect),
644 }
645 }
646
647 #[inline]
648 unsafe fn decode(
649 &mut self,
650 decoder: &mut fidl::encoding::Decoder<
651 '_,
652 fidl::encoding::DefaultFuchsiaResourceDialect,
653 >,
654 offset: usize,
655 _depth: fidl::encoding::Depth,
656 ) -> fidl::Result<()> {
657 decoder.debug_check_bounds::<Self>(offset);
658 fidl::decode!(fidl::encoding::HandleType<fidl::NullableHandle, { fidl::ObjectType::NONE.into_raw() }, 2147483648>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.lease, decoder, offset + 0, _depth)?;
660 Ok(())
661 }
662 }
663}