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_i2c_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18 type Proxy = DeviceProxy;
19 type RequestStream = DeviceRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = DeviceSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.hardware.i2c.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26pub type DeviceTransferResult = Result<Vec<Vec<u8>>, i32>;
27pub type DeviceGetNameResult = Result<String, i32>;
28
29pub trait DeviceProxyInterface: Send + Sync {
30 type TransferResponseFut: std::future::Future<Output = Result<DeviceTransferResult, fidl::Error>>
31 + Send;
32 fn r#transfer(&self, transactions: &[Transaction]) -> Self::TransferResponseFut;
33 type GetNameResponseFut: std::future::Future<Output = Result<DeviceGetNameResult, fidl::Error>>
34 + Send;
35 fn r#get_name(&self) -> Self::GetNameResponseFut;
36}
37#[derive(Debug)]
38#[cfg(target_os = "fuchsia")]
39pub struct DeviceSynchronousProxy {
40 client: fidl::client::sync::Client,
41}
42
43#[cfg(target_os = "fuchsia")]
44impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
45 type Proxy = DeviceProxy;
46 type Protocol = DeviceMarker;
47
48 fn from_channel(inner: fidl::Channel) -> Self {
49 Self::new(inner)
50 }
51
52 fn into_channel(self) -> fidl::Channel {
53 self.client.into_channel()
54 }
55
56 fn as_channel(&self) -> &fidl::Channel {
57 self.client.as_channel()
58 }
59}
60
61#[cfg(target_os = "fuchsia")]
62impl DeviceSynchronousProxy {
63 pub fn new(channel: fidl::Channel) -> Self {
64 let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
65 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
66 }
67
68 pub fn into_channel(self) -> fidl::Channel {
69 self.client.into_channel()
70 }
71
72 pub fn wait_for_event(
75 &self,
76 deadline: zx::MonotonicInstant,
77 ) -> Result<DeviceEvent, fidl::Error> {
78 DeviceEvent::decode(self.client.wait_for_event(deadline)?)
79 }
80
81 pub fn r#transfer(
96 &self,
97 mut transactions: &[Transaction],
98 ___deadline: zx::MonotonicInstant,
99 ) -> Result<DeviceTransferResult, fidl::Error> {
100 let _response = self.client.send_query::<
101 DeviceTransferRequest,
102 fidl::encoding::ResultType<DeviceTransferResponse, i32>,
103 >(
104 (transactions,),
105 0xc169f6c7849333b,
106 fidl::encoding::DynamicFlags::empty(),
107 ___deadline,
108 )?;
109 Ok(_response.map(|x| x.read_data))
110 }
111
112 pub fn r#get_name(
115 &self,
116 ___deadline: zx::MonotonicInstant,
117 ) -> Result<DeviceGetNameResult, fidl::Error> {
118 let _response = self.client.send_query::<
119 fidl::encoding::EmptyPayload,
120 fidl::encoding::ResultType<DeviceGetNameResponse, i32>,
121 >(
122 (),
123 0x745268a50651f102,
124 fidl::encoding::DynamicFlags::empty(),
125 ___deadline,
126 )?;
127 Ok(_response.map(|x| x.name))
128 }
129}
130
131#[cfg(target_os = "fuchsia")]
132impl From<DeviceSynchronousProxy> for zx::Handle {
133 fn from(value: DeviceSynchronousProxy) -> Self {
134 value.into_channel().into()
135 }
136}
137
138#[cfg(target_os = "fuchsia")]
139impl From<fidl::Channel> for DeviceSynchronousProxy {
140 fn from(value: fidl::Channel) -> Self {
141 Self::new(value)
142 }
143}
144
145#[derive(Debug, Clone)]
146pub struct DeviceProxy {
147 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
148}
149
150impl fidl::endpoints::Proxy for DeviceProxy {
151 type Protocol = DeviceMarker;
152
153 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
154 Self::new(inner)
155 }
156
157 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
158 self.client.into_channel().map_err(|client| Self { client })
159 }
160
161 fn as_channel(&self) -> &::fidl::AsyncChannel {
162 self.client.as_channel()
163 }
164}
165
166impl DeviceProxy {
167 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
169 let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
170 Self { client: fidl::client::Client::new(channel, protocol_name) }
171 }
172
173 pub fn take_event_stream(&self) -> DeviceEventStream {
179 DeviceEventStream { event_receiver: self.client.take_event_receiver() }
180 }
181
182 pub fn r#transfer(
197 &self,
198 mut transactions: &[Transaction],
199 ) -> fidl::client::QueryResponseFut<
200 DeviceTransferResult,
201 fidl::encoding::DefaultFuchsiaResourceDialect,
202 > {
203 DeviceProxyInterface::r#transfer(self, transactions)
204 }
205
206 pub fn r#get_name(
209 &self,
210 ) -> fidl::client::QueryResponseFut<
211 DeviceGetNameResult,
212 fidl::encoding::DefaultFuchsiaResourceDialect,
213 > {
214 DeviceProxyInterface::r#get_name(self)
215 }
216}
217
218impl DeviceProxyInterface for DeviceProxy {
219 type TransferResponseFut = fidl::client::QueryResponseFut<
220 DeviceTransferResult,
221 fidl::encoding::DefaultFuchsiaResourceDialect,
222 >;
223 fn r#transfer(&self, mut transactions: &[Transaction]) -> Self::TransferResponseFut {
224 fn _decode(
225 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
226 ) -> Result<DeviceTransferResult, fidl::Error> {
227 let _response = fidl::client::decode_transaction_body::<
228 fidl::encoding::ResultType<DeviceTransferResponse, i32>,
229 fidl::encoding::DefaultFuchsiaResourceDialect,
230 0xc169f6c7849333b,
231 >(_buf?)?;
232 Ok(_response.map(|x| x.read_data))
233 }
234 self.client.send_query_and_decode::<DeviceTransferRequest, DeviceTransferResult>(
235 (transactions,),
236 0xc169f6c7849333b,
237 fidl::encoding::DynamicFlags::empty(),
238 _decode,
239 )
240 }
241
242 type GetNameResponseFut = fidl::client::QueryResponseFut<
243 DeviceGetNameResult,
244 fidl::encoding::DefaultFuchsiaResourceDialect,
245 >;
246 fn r#get_name(&self) -> Self::GetNameResponseFut {
247 fn _decode(
248 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
249 ) -> Result<DeviceGetNameResult, fidl::Error> {
250 let _response = fidl::client::decode_transaction_body::<
251 fidl::encoding::ResultType<DeviceGetNameResponse, i32>,
252 fidl::encoding::DefaultFuchsiaResourceDialect,
253 0x745268a50651f102,
254 >(_buf?)?;
255 Ok(_response.map(|x| x.name))
256 }
257 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetNameResult>(
258 (),
259 0x745268a50651f102,
260 fidl::encoding::DynamicFlags::empty(),
261 _decode,
262 )
263 }
264}
265
266pub struct DeviceEventStream {
267 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
268}
269
270impl std::marker::Unpin for DeviceEventStream {}
271
272impl futures::stream::FusedStream for DeviceEventStream {
273 fn is_terminated(&self) -> bool {
274 self.event_receiver.is_terminated()
275 }
276}
277
278impl futures::Stream for DeviceEventStream {
279 type Item = Result<DeviceEvent, fidl::Error>;
280
281 fn poll_next(
282 mut self: std::pin::Pin<&mut Self>,
283 cx: &mut std::task::Context<'_>,
284 ) -> std::task::Poll<Option<Self::Item>> {
285 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
286 &mut self.event_receiver,
287 cx
288 )?) {
289 Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
290 None => std::task::Poll::Ready(None),
291 }
292 }
293}
294
295#[derive(Debug)]
296pub enum DeviceEvent {}
297
298impl DeviceEvent {
299 fn decode(
301 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
302 ) -> Result<DeviceEvent, fidl::Error> {
303 let (bytes, _handles) = buf.split_mut();
304 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
305 debug_assert_eq!(tx_header.tx_id, 0);
306 match tx_header.ordinal {
307 _ => Err(fidl::Error::UnknownOrdinal {
308 ordinal: tx_header.ordinal,
309 protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
310 }),
311 }
312 }
313}
314
315pub struct DeviceRequestStream {
317 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
318 is_terminated: bool,
319}
320
321impl std::marker::Unpin for DeviceRequestStream {}
322
323impl futures::stream::FusedStream for DeviceRequestStream {
324 fn is_terminated(&self) -> bool {
325 self.is_terminated
326 }
327}
328
329impl fidl::endpoints::RequestStream for DeviceRequestStream {
330 type Protocol = DeviceMarker;
331 type ControlHandle = DeviceControlHandle;
332
333 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
334 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
335 }
336
337 fn control_handle(&self) -> Self::ControlHandle {
338 DeviceControlHandle { inner: self.inner.clone() }
339 }
340
341 fn into_inner(
342 self,
343 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
344 {
345 (self.inner, self.is_terminated)
346 }
347
348 fn from_inner(
349 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
350 is_terminated: bool,
351 ) -> Self {
352 Self { inner, is_terminated }
353 }
354}
355
356impl futures::Stream for DeviceRequestStream {
357 type Item = Result<DeviceRequest, fidl::Error>;
358
359 fn poll_next(
360 mut self: std::pin::Pin<&mut Self>,
361 cx: &mut std::task::Context<'_>,
362 ) -> std::task::Poll<Option<Self::Item>> {
363 let this = &mut *self;
364 if this.inner.check_shutdown(cx) {
365 this.is_terminated = true;
366 return std::task::Poll::Ready(None);
367 }
368 if this.is_terminated {
369 panic!("polled DeviceRequestStream after completion");
370 }
371 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
372 |bytes, handles| {
373 match this.inner.channel().read_etc(cx, bytes, handles) {
374 std::task::Poll::Ready(Ok(())) => {}
375 std::task::Poll::Pending => return std::task::Poll::Pending,
376 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
377 this.is_terminated = true;
378 return std::task::Poll::Ready(None);
379 }
380 std::task::Poll::Ready(Err(e)) => {
381 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
382 e.into(),
383 ))))
384 }
385 }
386
387 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
389
390 std::task::Poll::Ready(Some(match header.ordinal {
391 0xc169f6c7849333b => {
392 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
393 let mut req = fidl::new_empty!(
394 DeviceTransferRequest,
395 fidl::encoding::DefaultFuchsiaResourceDialect
396 );
397 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceTransferRequest>(&header, _body_bytes, handles, &mut req)?;
398 let control_handle = DeviceControlHandle { inner: this.inner.clone() };
399 Ok(DeviceRequest::Transfer {
400 transactions: req.transactions,
401
402 responder: DeviceTransferResponder {
403 control_handle: std::mem::ManuallyDrop::new(control_handle),
404 tx_id: header.tx_id,
405 },
406 })
407 }
408 0x745268a50651f102 => {
409 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
410 let mut req = fidl::new_empty!(
411 fidl::encoding::EmptyPayload,
412 fidl::encoding::DefaultFuchsiaResourceDialect
413 );
414 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
415 let control_handle = DeviceControlHandle { inner: this.inner.clone() };
416 Ok(DeviceRequest::GetName {
417 responder: DeviceGetNameResponder {
418 control_handle: std::mem::ManuallyDrop::new(control_handle),
419 tx_id: header.tx_id,
420 },
421 })
422 }
423 _ => Err(fidl::Error::UnknownOrdinal {
424 ordinal: header.ordinal,
425 protocol_name:
426 <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
427 }),
428 }))
429 },
430 )
431 }
432}
433
434#[derive(Debug)]
435pub enum DeviceRequest {
436 Transfer { transactions: Vec<Transaction>, responder: DeviceTransferResponder },
451 GetName { responder: DeviceGetNameResponder },
454}
455
456impl DeviceRequest {
457 #[allow(irrefutable_let_patterns)]
458 pub fn into_transfer(self) -> Option<(Vec<Transaction>, DeviceTransferResponder)> {
459 if let DeviceRequest::Transfer { transactions, responder } = self {
460 Some((transactions, responder))
461 } else {
462 None
463 }
464 }
465
466 #[allow(irrefutable_let_patterns)]
467 pub fn into_get_name(self) -> Option<(DeviceGetNameResponder)> {
468 if let DeviceRequest::GetName { responder } = self {
469 Some((responder))
470 } else {
471 None
472 }
473 }
474
475 pub fn method_name(&self) -> &'static str {
477 match *self {
478 DeviceRequest::Transfer { .. } => "transfer",
479 DeviceRequest::GetName { .. } => "get_name",
480 }
481 }
482}
483
484#[derive(Debug, Clone)]
485pub struct DeviceControlHandle {
486 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
487}
488
489impl fidl::endpoints::ControlHandle for DeviceControlHandle {
490 fn shutdown(&self) {
491 self.inner.shutdown()
492 }
493 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
494 self.inner.shutdown_with_epitaph(status)
495 }
496
497 fn is_closed(&self) -> bool {
498 self.inner.channel().is_closed()
499 }
500 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
501 self.inner.channel().on_closed()
502 }
503
504 #[cfg(target_os = "fuchsia")]
505 fn signal_peer(
506 &self,
507 clear_mask: zx::Signals,
508 set_mask: zx::Signals,
509 ) -> Result<(), zx_status::Status> {
510 use fidl::Peered;
511 self.inner.channel().signal_peer(clear_mask, set_mask)
512 }
513}
514
515impl DeviceControlHandle {}
516
517#[must_use = "FIDL methods require a response to be sent"]
518#[derive(Debug)]
519pub struct DeviceTransferResponder {
520 control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
521 tx_id: u32,
522}
523
524impl std::ops::Drop for DeviceTransferResponder {
528 fn drop(&mut self) {
529 self.control_handle.shutdown();
530 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
532 }
533}
534
535impl fidl::endpoints::Responder for DeviceTransferResponder {
536 type ControlHandle = DeviceControlHandle;
537
538 fn control_handle(&self) -> &DeviceControlHandle {
539 &self.control_handle
540 }
541
542 fn drop_without_shutdown(mut self) {
543 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
545 std::mem::forget(self);
547 }
548}
549
550impl DeviceTransferResponder {
551 pub fn send(self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
555 let _result = self.send_raw(result);
556 if _result.is_err() {
557 self.control_handle.shutdown();
558 }
559 self.drop_without_shutdown();
560 _result
561 }
562
563 pub fn send_no_shutdown_on_err(
565 self,
566 mut result: Result<&[Vec<u8>], i32>,
567 ) -> Result<(), fidl::Error> {
568 let _result = self.send_raw(result);
569 self.drop_without_shutdown();
570 _result
571 }
572
573 fn send_raw(&self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
574 self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceTransferResponse, i32>>(
575 result.map(|read_data| (read_data,)),
576 self.tx_id,
577 0xc169f6c7849333b,
578 fidl::encoding::DynamicFlags::empty(),
579 )
580 }
581}
582
583#[must_use = "FIDL methods require a response to be sent"]
584#[derive(Debug)]
585pub struct DeviceGetNameResponder {
586 control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
587 tx_id: u32,
588}
589
590impl std::ops::Drop for DeviceGetNameResponder {
594 fn drop(&mut self) {
595 self.control_handle.shutdown();
596 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
598 }
599}
600
601impl fidl::endpoints::Responder for DeviceGetNameResponder {
602 type ControlHandle = DeviceControlHandle;
603
604 fn control_handle(&self) -> &DeviceControlHandle {
605 &self.control_handle
606 }
607
608 fn drop_without_shutdown(mut self) {
609 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
611 std::mem::forget(self);
613 }
614}
615
616impl DeviceGetNameResponder {
617 pub fn send(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
621 let _result = self.send_raw(result);
622 if _result.is_err() {
623 self.control_handle.shutdown();
624 }
625 self.drop_without_shutdown();
626 _result
627 }
628
629 pub fn send_no_shutdown_on_err(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
631 let _result = self.send_raw(result);
632 self.drop_without_shutdown();
633 _result
634 }
635
636 fn send_raw(&self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
637 self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceGetNameResponse, i32>>(
638 result.map(|name| (name,)),
639 self.tx_id,
640 0x745268a50651f102,
641 fidl::encoding::DynamicFlags::empty(),
642 )
643 }
644}
645
646#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
647pub struct ServiceMarker;
648
649#[cfg(target_os = "fuchsia")]
650impl fidl::endpoints::ServiceMarker for ServiceMarker {
651 type Proxy = ServiceProxy;
652 type Request = ServiceRequest;
653 const SERVICE_NAME: &'static str = "fuchsia.hardware.i2c.Service";
654}
655
656#[cfg(target_os = "fuchsia")]
659pub enum ServiceRequest {
660 Device(DeviceRequestStream),
661}
662
663#[cfg(target_os = "fuchsia")]
664impl fidl::endpoints::ServiceRequest for ServiceRequest {
665 type Service = ServiceMarker;
666
667 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
668 match name {
669 "device" => Self::Device(
670 <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
671 ),
672 _ => panic!("no such member protocol name for service Service"),
673 }
674 }
675
676 fn member_names() -> &'static [&'static str] {
677 &["device"]
678 }
679}
680#[cfg(target_os = "fuchsia")]
681pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
682
683#[cfg(target_os = "fuchsia")]
684impl fidl::endpoints::ServiceProxy for ServiceProxy {
685 type Service = ServiceMarker;
686
687 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
688 Self(opener)
689 }
690}
691
692#[cfg(target_os = "fuchsia")]
693impl ServiceProxy {
694 pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
695 let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
696 self.connect_channel_to_device(server_end)?;
697 Ok(proxy)
698 }
699
700 pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
703 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
704 self.connect_channel_to_device(server_end)?;
705 Ok(proxy)
706 }
707
708 pub fn connect_channel_to_device(
711 &self,
712 server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
713 ) -> Result<(), fidl::Error> {
714 self.0.open_member("device", server_end.into_channel())
715 }
716
717 pub fn instance_name(&self) -> &str {
718 self.0.instance_name()
719 }
720}
721
722mod internal {
723 use super::*;
724}