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