Skip to main content

fidl_fuchsia_hardware_i2c/
fidl_fuchsia_hardware_i2c.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![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        Self { client: fidl::client::sync::Client::new(channel) }
65    }
66
67    pub fn into_channel(self) -> fidl::Channel {
68        self.client.into_channel()
69    }
70
71    /// Waits until an event arrives and returns it. It is safe for other
72    /// threads to make concurrent requests while waiting for an event.
73    pub fn wait_for_event(
74        &self,
75        deadline: zx::MonotonicInstant,
76    ) -> Result<DeviceEvent, fidl::Error> {
77        DeviceEvent::decode(self.client.wait_for_event::<DeviceMarker>(deadline)?)
78    }
79
80    /// Issue one or more transactions to a particular I2C device.
81    ///
82    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
83    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
84    /// each read transfer in `transactions`. Transaction processing continues until all transfers
85    /// have been completed, an error occurs, or the target issues a NACK in response to a write
86    /// transfer.
87    ///
88    /// The possible error values are:
89    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
90    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
91    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
92    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
93    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
94    pub fn r#transfer(
95        &self,
96        mut transactions: &[Transaction],
97        ___deadline: zx::MonotonicInstant,
98    ) -> Result<DeviceTransferResult, fidl::Error> {
99        let _response = self.client.send_query::<
100            DeviceTransferRequest,
101            fidl::encoding::ResultType<DeviceTransferResponse, i32>,
102            DeviceMarker,
103        >(
104            (transactions,),
105            0xc169f6c7849333b,
106            fidl::encoding::DynamicFlags::empty(),
107            ___deadline,
108        )?;
109        Ok(_response.map(|x| x.read_data))
110    }
111
112    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
113    /// name is unspecified or the empty string.
114    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            DeviceMarker,
122        >(
123            (),
124            0x745268a50651f102,
125            fidl::encoding::DynamicFlags::empty(),
126            ___deadline,
127        )?;
128        Ok(_response.map(|x| x.name))
129    }
130}
131
132#[cfg(target_os = "fuchsia")]
133impl From<DeviceSynchronousProxy> for zx::NullableHandle {
134    fn from(value: DeviceSynchronousProxy) -> Self {
135        value.into_channel().into()
136    }
137}
138
139#[cfg(target_os = "fuchsia")]
140impl From<fidl::Channel> for DeviceSynchronousProxy {
141    fn from(value: fidl::Channel) -> Self {
142        Self::new(value)
143    }
144}
145
146#[cfg(target_os = "fuchsia")]
147impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
148    type Protocol = DeviceMarker;
149
150    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
151        Self::new(value.into_channel())
152    }
153}
154
155#[derive(Debug, Clone)]
156pub struct DeviceProxy {
157    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
158}
159
160impl fidl::endpoints::Proxy for DeviceProxy {
161    type Protocol = DeviceMarker;
162
163    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
164        Self::new(inner)
165    }
166
167    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
168        self.client.into_channel().map_err(|client| Self { client })
169    }
170
171    fn as_channel(&self) -> &::fidl::AsyncChannel {
172        self.client.as_channel()
173    }
174}
175
176impl DeviceProxy {
177    /// Create a new Proxy for fuchsia.hardware.i2c/Device.
178    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
179        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
180        Self { client: fidl::client::Client::new(channel, protocol_name) }
181    }
182
183    /// Get a Stream of events from the remote end of the protocol.
184    ///
185    /// # Panics
186    ///
187    /// Panics if the event stream was already taken.
188    pub fn take_event_stream(&self) -> DeviceEventStream {
189        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
190    }
191
192    /// Issue one or more transactions to a particular I2C device.
193    ///
194    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
195    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
196    /// each read transfer in `transactions`. Transaction processing continues until all transfers
197    /// have been completed, an error occurs, or the target issues a NACK in response to a write
198    /// transfer.
199    ///
200    /// The possible error values are:
201    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
202    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
203    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
204    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
205    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
206    pub fn r#transfer(
207        &self,
208        mut transactions: &[Transaction],
209    ) -> fidl::client::QueryResponseFut<
210        DeviceTransferResult,
211        fidl::encoding::DefaultFuchsiaResourceDialect,
212    > {
213        DeviceProxyInterface::r#transfer(self, transactions)
214    }
215
216    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
217    /// name is unspecified or the empty string.
218    pub fn r#get_name(
219        &self,
220    ) -> fidl::client::QueryResponseFut<
221        DeviceGetNameResult,
222        fidl::encoding::DefaultFuchsiaResourceDialect,
223    > {
224        DeviceProxyInterface::r#get_name(self)
225    }
226}
227
228impl DeviceProxyInterface for DeviceProxy {
229    type TransferResponseFut = fidl::client::QueryResponseFut<
230        DeviceTransferResult,
231        fidl::encoding::DefaultFuchsiaResourceDialect,
232    >;
233    fn r#transfer(&self, mut transactions: &[Transaction]) -> Self::TransferResponseFut {
234        fn _decode(
235            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
236        ) -> Result<DeviceTransferResult, fidl::Error> {
237            let _response = fidl::client::decode_transaction_body::<
238                fidl::encoding::ResultType<DeviceTransferResponse, i32>,
239                fidl::encoding::DefaultFuchsiaResourceDialect,
240                0xc169f6c7849333b,
241            >(_buf?)?;
242            Ok(_response.map(|x| x.read_data))
243        }
244        self.client.send_query_and_decode::<DeviceTransferRequest, DeviceTransferResult>(
245            (transactions,),
246            0xc169f6c7849333b,
247            fidl::encoding::DynamicFlags::empty(),
248            _decode,
249        )
250    }
251
252    type GetNameResponseFut = fidl::client::QueryResponseFut<
253        DeviceGetNameResult,
254        fidl::encoding::DefaultFuchsiaResourceDialect,
255    >;
256    fn r#get_name(&self) -> Self::GetNameResponseFut {
257        fn _decode(
258            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
259        ) -> Result<DeviceGetNameResult, fidl::Error> {
260            let _response = fidl::client::decode_transaction_body::<
261                fidl::encoding::ResultType<DeviceGetNameResponse, i32>,
262                fidl::encoding::DefaultFuchsiaResourceDialect,
263                0x745268a50651f102,
264            >(_buf?)?;
265            Ok(_response.map(|x| x.name))
266        }
267        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceGetNameResult>(
268            (),
269            0x745268a50651f102,
270            fidl::encoding::DynamicFlags::empty(),
271            _decode,
272        )
273    }
274}
275
276pub struct DeviceEventStream {
277    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
278}
279
280impl std::marker::Unpin for DeviceEventStream {}
281
282impl futures::stream::FusedStream for DeviceEventStream {
283    fn is_terminated(&self) -> bool {
284        self.event_receiver.is_terminated()
285    }
286}
287
288impl futures::Stream for DeviceEventStream {
289    type Item = Result<DeviceEvent, fidl::Error>;
290
291    fn poll_next(
292        mut self: std::pin::Pin<&mut Self>,
293        cx: &mut std::task::Context<'_>,
294    ) -> std::task::Poll<Option<Self::Item>> {
295        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
296            &mut self.event_receiver,
297            cx
298        )?) {
299            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
300            None => std::task::Poll::Ready(None),
301        }
302    }
303}
304
305#[derive(Debug)]
306pub enum DeviceEvent {}
307
308impl DeviceEvent {
309    /// Decodes a message buffer as a [`DeviceEvent`].
310    fn decode(
311        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
312    ) -> Result<DeviceEvent, fidl::Error> {
313        let (bytes, _handles) = buf.split_mut();
314        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
315        debug_assert_eq!(tx_header.tx_id, 0);
316        match tx_header.ordinal {
317            _ => Err(fidl::Error::UnknownOrdinal {
318                ordinal: tx_header.ordinal,
319                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
320            }),
321        }
322    }
323}
324
325/// A Stream of incoming requests for fuchsia.hardware.i2c/Device.
326pub struct DeviceRequestStream {
327    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
328    is_terminated: bool,
329}
330
331impl std::marker::Unpin for DeviceRequestStream {}
332
333impl futures::stream::FusedStream for DeviceRequestStream {
334    fn is_terminated(&self) -> bool {
335        self.is_terminated
336    }
337}
338
339impl fidl::endpoints::RequestStream for DeviceRequestStream {
340    type Protocol = DeviceMarker;
341    type ControlHandle = DeviceControlHandle;
342
343    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
344        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
345    }
346
347    fn control_handle(&self) -> Self::ControlHandle {
348        DeviceControlHandle { inner: self.inner.clone() }
349    }
350
351    fn into_inner(
352        self,
353    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
354    {
355        (self.inner, self.is_terminated)
356    }
357
358    fn from_inner(
359        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
360        is_terminated: bool,
361    ) -> Self {
362        Self { inner, is_terminated }
363    }
364}
365
366impl futures::Stream for DeviceRequestStream {
367    type Item = Result<DeviceRequest, fidl::Error>;
368
369    fn poll_next(
370        mut self: std::pin::Pin<&mut Self>,
371        cx: &mut std::task::Context<'_>,
372    ) -> std::task::Poll<Option<Self::Item>> {
373        let this = &mut *self;
374        if this.inner.check_shutdown(cx) {
375            this.is_terminated = true;
376            return std::task::Poll::Ready(None);
377        }
378        if this.is_terminated {
379            panic!("polled DeviceRequestStream after completion");
380        }
381        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
382            |bytes, handles| {
383                match this.inner.channel().read_etc(cx, bytes, handles) {
384                    std::task::Poll::Ready(Ok(())) => {}
385                    std::task::Poll::Pending => return std::task::Poll::Pending,
386                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
387                        this.is_terminated = true;
388                        return std::task::Poll::Ready(None);
389                    }
390                    std::task::Poll::Ready(Err(e)) => {
391                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
392                            e.into(),
393                        ))));
394                    }
395                }
396
397                // A message has been received from the channel
398                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
399
400                std::task::Poll::Ready(Some(match header.ordinal {
401                    0xc169f6c7849333b => {
402                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
403                        let mut req = fidl::new_empty!(
404                            DeviceTransferRequest,
405                            fidl::encoding::DefaultFuchsiaResourceDialect
406                        );
407                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceTransferRequest>(&header, _body_bytes, handles, &mut req)?;
408                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
409                        Ok(DeviceRequest::Transfer {
410                            transactions: req.transactions,
411
412                            responder: DeviceTransferResponder {
413                                control_handle: std::mem::ManuallyDrop::new(control_handle),
414                                tx_id: header.tx_id,
415                            },
416                        })
417                    }
418                    0x745268a50651f102 => {
419                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
420                        let mut req = fidl::new_empty!(
421                            fidl::encoding::EmptyPayload,
422                            fidl::encoding::DefaultFuchsiaResourceDialect
423                        );
424                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
425                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
426                        Ok(DeviceRequest::GetName {
427                            responder: DeviceGetNameResponder {
428                                control_handle: std::mem::ManuallyDrop::new(control_handle),
429                                tx_id: header.tx_id,
430                            },
431                        })
432                    }
433                    _ => Err(fidl::Error::UnknownOrdinal {
434                        ordinal: header.ordinal,
435                        protocol_name:
436                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
437                    }),
438                }))
439            },
440        )
441    }
442}
443
444#[derive(Debug)]
445pub enum DeviceRequest {
446    /// Issue one or more transactions to a particular I2C device.
447    ///
448    /// Each `Transaction` is performed in the order in which it appears in `transactions`. Data for
449    /// read transfers (if there are any) is returned through `read_data`, which has one entry for
450    /// each read transfer in `transactions`. Transaction processing continues until all transfers
451    /// have been completed, an error occurs, or the target issues a NACK in response to a write
452    /// transfer.
453    ///
454    /// The possible error values are:
455    ///   ZX_ERR_INVALID_ARGS: `transactions` has zero elements, `data_transfer` was not specified
456    ///     for a `Transaction`, or there was a zero-length `DataTransfer`.
457    ///   ZX_ERR_OUT_OF_RANGE: A `DataTransfer` was too large to be handled by this I2C controller.
458    ///   ZX_ERR_IO_NOT_PRESENT: The device did not respond to its I2C address.
459    ///   ZX_ERR_IO_REFUSED: The device issued a NACK before the end of a write transfer.
460    Transfer { transactions: Vec<Transaction>, responder: DeviceTransferResponder },
461    /// Get the name of this I2C Device. Returns ZX_ERR_NOT_SUPPORTED if the
462    /// name is unspecified or the empty string.
463    GetName { responder: DeviceGetNameResponder },
464}
465
466impl DeviceRequest {
467    #[allow(irrefutable_let_patterns)]
468    pub fn into_transfer(self) -> Option<(Vec<Transaction>, DeviceTransferResponder)> {
469        if let DeviceRequest::Transfer { transactions, responder } = self {
470            Some((transactions, responder))
471        } else {
472            None
473        }
474    }
475
476    #[allow(irrefutable_let_patterns)]
477    pub fn into_get_name(self) -> Option<(DeviceGetNameResponder)> {
478        if let DeviceRequest::GetName { responder } = self { Some((responder)) } else { None }
479    }
480
481    /// Name of the method defined in FIDL
482    pub fn method_name(&self) -> &'static str {
483        match *self {
484            DeviceRequest::Transfer { .. } => "transfer",
485            DeviceRequest::GetName { .. } => "get_name",
486        }
487    }
488}
489
490#[derive(Debug, Clone)]
491pub struct DeviceControlHandle {
492    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
493}
494
495impl fidl::endpoints::ControlHandle for DeviceControlHandle {
496    fn shutdown(&self) {
497        self.inner.shutdown()
498    }
499
500    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
501        self.inner.shutdown_with_epitaph(status)
502    }
503
504    fn is_closed(&self) -> bool {
505        self.inner.channel().is_closed()
506    }
507    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
508        self.inner.channel().on_closed()
509    }
510
511    #[cfg(target_os = "fuchsia")]
512    fn signal_peer(
513        &self,
514        clear_mask: zx::Signals,
515        set_mask: zx::Signals,
516    ) -> Result<(), zx_status::Status> {
517        use fidl::Peered;
518        self.inner.channel().signal_peer(clear_mask, set_mask)
519    }
520}
521
522impl DeviceControlHandle {}
523
524#[must_use = "FIDL methods require a response to be sent"]
525#[derive(Debug)]
526pub struct DeviceTransferResponder {
527    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
528    tx_id: u32,
529}
530
531/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
532/// if the responder is dropped without sending a response, so that the client
533/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
534impl std::ops::Drop for DeviceTransferResponder {
535    fn drop(&mut self) {
536        self.control_handle.shutdown();
537        // Safety: drops once, never accessed again
538        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
539    }
540}
541
542impl fidl::endpoints::Responder for DeviceTransferResponder {
543    type ControlHandle = DeviceControlHandle;
544
545    fn control_handle(&self) -> &DeviceControlHandle {
546        &self.control_handle
547    }
548
549    fn drop_without_shutdown(mut self) {
550        // Safety: drops once, never accessed again due to mem::forget
551        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
552        // Prevent Drop from running (which would shut down the channel)
553        std::mem::forget(self);
554    }
555}
556
557impl DeviceTransferResponder {
558    /// Sends a response to the FIDL transaction.
559    ///
560    /// Sets the channel to shutdown if an error occurs.
561    pub fn send(self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
562        let _result = self.send_raw(result);
563        if _result.is_err() {
564            self.control_handle.shutdown();
565        }
566        self.drop_without_shutdown();
567        _result
568    }
569
570    /// Similar to "send" but does not shutdown the channel if an error occurs.
571    pub fn send_no_shutdown_on_err(
572        self,
573        mut result: Result<&[Vec<u8>], i32>,
574    ) -> Result<(), fidl::Error> {
575        let _result = self.send_raw(result);
576        self.drop_without_shutdown();
577        _result
578    }
579
580    fn send_raw(&self, mut result: Result<&[Vec<u8>], i32>) -> Result<(), fidl::Error> {
581        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceTransferResponse, i32>>(
582            result.map(|read_data| (read_data,)),
583            self.tx_id,
584            0xc169f6c7849333b,
585            fidl::encoding::DynamicFlags::empty(),
586        )
587    }
588}
589
590#[must_use = "FIDL methods require a response to be sent"]
591#[derive(Debug)]
592pub struct DeviceGetNameResponder {
593    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
594    tx_id: u32,
595}
596
597/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
598/// if the responder is dropped without sending a response, so that the client
599/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
600impl std::ops::Drop for DeviceGetNameResponder {
601    fn drop(&mut self) {
602        self.control_handle.shutdown();
603        // Safety: drops once, never accessed again
604        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
605    }
606}
607
608impl fidl::endpoints::Responder for DeviceGetNameResponder {
609    type ControlHandle = DeviceControlHandle;
610
611    fn control_handle(&self) -> &DeviceControlHandle {
612        &self.control_handle
613    }
614
615    fn drop_without_shutdown(mut self) {
616        // Safety: drops once, never accessed again due to mem::forget
617        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
618        // Prevent Drop from running (which would shut down the channel)
619        std::mem::forget(self);
620    }
621}
622
623impl DeviceGetNameResponder {
624    /// Sends a response to the FIDL transaction.
625    ///
626    /// Sets the channel to shutdown if an error occurs.
627    pub fn send(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
628        let _result = self.send_raw(result);
629        if _result.is_err() {
630            self.control_handle.shutdown();
631        }
632        self.drop_without_shutdown();
633        _result
634    }
635
636    /// Similar to "send" but does not shutdown the channel if an error occurs.
637    pub fn send_no_shutdown_on_err(self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
638        let _result = self.send_raw(result);
639        self.drop_without_shutdown();
640        _result
641    }
642
643    fn send_raw(&self, mut result: Result<&str, i32>) -> Result<(), fidl::Error> {
644        self.control_handle.inner.send::<fidl::encoding::ResultType<DeviceGetNameResponse, i32>>(
645            result.map(|name| (name,)),
646            self.tx_id,
647            0x745268a50651f102,
648            fidl::encoding::DynamicFlags::empty(),
649        )
650    }
651}
652
653#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
654pub struct ServiceMarker;
655
656#[cfg(target_os = "fuchsia")]
657impl fidl::endpoints::ServiceMarker for ServiceMarker {
658    type Proxy = ServiceProxy;
659    type Request = ServiceRequest;
660    const SERVICE_NAME: &'static str = "fuchsia.hardware.i2c.Service";
661}
662
663/// A request for one of the member protocols of Service.
664///
665#[cfg(target_os = "fuchsia")]
666pub enum ServiceRequest {
667    Device(DeviceRequestStream),
668}
669
670#[cfg(target_os = "fuchsia")]
671impl fidl::endpoints::ServiceRequest for ServiceRequest {
672    type Service = ServiceMarker;
673
674    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
675        match name {
676            "device" => Self::Device(
677                <DeviceRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
678            ),
679            _ => panic!("no such member protocol name for service Service"),
680        }
681    }
682
683    fn member_names() -> &'static [&'static str] {
684        &["device"]
685    }
686}
687#[cfg(target_os = "fuchsia")]
688pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
689
690#[cfg(target_os = "fuchsia")]
691impl fidl::endpoints::ServiceProxy for ServiceProxy {
692    type Service = ServiceMarker;
693
694    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
695        Self(opener)
696    }
697}
698
699#[cfg(target_os = "fuchsia")]
700impl ServiceProxy {
701    pub fn connect_to_device(&self) -> Result<DeviceProxy, fidl::Error> {
702        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceMarker>();
703        self.connect_channel_to_device(server_end)?;
704        Ok(proxy)
705    }
706
707    /// Like `connect_to_device`, but returns a sync proxy.
708    /// See [`Self::connect_to_device`] for more details.
709    pub fn connect_to_device_sync(&self) -> Result<DeviceSynchronousProxy, fidl::Error> {
710        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceMarker>();
711        self.connect_channel_to_device(server_end)?;
712        Ok(proxy)
713    }
714
715    /// Like `connect_to_device`, but accepts a server end.
716    /// See [`Self::connect_to_device`] for more details.
717    pub fn connect_channel_to_device(
718        &self,
719        server_end: fidl::endpoints::ServerEnd<DeviceMarker>,
720    ) -> Result<(), fidl::Error> {
721        self.0.open_member("device", server_end.into_channel())
722    }
723
724    pub fn instance_name(&self) -> &str {
725        self.0.instance_name()
726    }
727}
728
729mod internal {
730    use super::*;
731}