fidl_fuchsia_lowpan_spinel/
fidl_fuchsia_lowpan_spinel.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_lowpan_spinel__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
15pub struct DeviceSetupSetChannelRequest {
16    pub req: fidl::endpoints::ServerEnd<DeviceMarker>,
17}
18
19impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
20    for DeviceSetupSetChannelRequest
21{
22}
23
24#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
25pub struct DeviceMarker;
26
27impl fidl::endpoints::ProtocolMarker for DeviceMarker {
28    type Proxy = DeviceProxy;
29    type RequestStream = DeviceRequestStream;
30    #[cfg(target_os = "fuchsia")]
31    type SynchronousProxy = DeviceSynchronousProxy;
32
33    const DEBUG_NAME: &'static str = "fuchsia.lowpan.spinel.Device";
34}
35impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
36pub type DeviceOpenResult = Result<(), Error>;
37pub type DeviceCloseResult = Result<(), Error>;
38
39pub trait DeviceProxyInterface: Send + Sync {
40    type OpenResponseFut: std::future::Future<Output = Result<DeviceOpenResult, fidl::Error>> + Send;
41    fn r#open(&self) -> Self::OpenResponseFut;
42    type CloseResponseFut: std::future::Future<Output = Result<DeviceCloseResult, fidl::Error>>
43        + Send;
44    fn r#close(&self) -> Self::CloseResponseFut;
45    type GetMaxFrameSizeResponseFut: std::future::Future<Output = Result<u32, fidl::Error>> + Send;
46    fn r#get_max_frame_size(&self) -> Self::GetMaxFrameSizeResponseFut;
47    fn r#send_frame(&self, data: &[u8]) -> Result<(), fidl::Error>;
48    fn r#ready_to_receive_frames(&self, number_of_frames: u32) -> Result<(), fidl::Error>;
49}
50#[derive(Debug)]
51#[cfg(target_os = "fuchsia")]
52pub struct DeviceSynchronousProxy {
53    client: fidl::client::sync::Client,
54}
55
56#[cfg(target_os = "fuchsia")]
57impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
58    type Proxy = DeviceProxy;
59    type Protocol = DeviceMarker;
60
61    fn from_channel(inner: fidl::Channel) -> Self {
62        Self::new(inner)
63    }
64
65    fn into_channel(self) -> fidl::Channel {
66        self.client.into_channel()
67    }
68
69    fn as_channel(&self) -> &fidl::Channel {
70        self.client.as_channel()
71    }
72}
73
74#[cfg(target_os = "fuchsia")]
75impl DeviceSynchronousProxy {
76    pub fn new(channel: fidl::Channel) -> Self {
77        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
78        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
79    }
80
81    pub fn into_channel(self) -> fidl::Channel {
82        self.client.into_channel()
83    }
84
85    /// Waits until an event arrives and returns it. It is safe for other
86    /// threads to make concurrent requests while waiting for an event.
87    pub fn wait_for_event(
88        &self,
89        deadline: zx::MonotonicInstant,
90    ) -> Result<DeviceEvent, fidl::Error> {
91        DeviceEvent::decode(self.client.wait_for_event(deadline)?)
92    }
93
94    /// Opens the Spinel connection and performs initialization.
95    ///
96    /// This method will block until the Device is ready to use or
97    /// an error has been encountered. If an error is indicated,
98    /// the device is still considered closed.
99    ///
100    /// Calling this method will typically induce reset if
101    /// supported by the underlying hardware. It may be called
102    /// while the device is already open in order to trigger a
103    /// reset.
104    ///
105    /// Possible error codes:
106    ///
107    /// * `Error::IO_ERROR`: An IO error occurred.
108    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
109    ///                         See logs for more details.
110    pub fn r#open(
111        &self,
112        ___deadline: zx::MonotonicInstant,
113    ) -> Result<DeviceOpenResult, fidl::Error> {
114        let _response = self.client.send_query::<
115            fidl::encoding::EmptyPayload,
116            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
117        >(
118            (),
119            0x508cecb73a776ef7,
120            fidl::encoding::DynamicFlags::empty(),
121            ___deadline,
122        )?;
123        Ok(_response.map(|x| x))
124    }
125
126    /// Close the Spinel connection.
127    ///
128    /// This method will block until the Device has successfully
129    /// been put into a closed (preferably low-power) state. An
130    /// error may be indicated if a problem was encountered that
131    /// may indicate the device did not close cleanly.
132    ///
133    /// Calling this method will always cause this interface to be
134    /// closed, even if an error is reported. Thus, the error may
135    /// be simply ignored or logged.
136    ///
137    /// Calling this method when the device is already closed
138    /// will do nothing.
139    ///
140    /// Possible error codes:
141    ///
142    /// * `Error::IO_ERROR`: An IO error occurred.
143    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
144    ///                         See logs for more details.
145    pub fn r#close(
146        &self,
147        ___deadline: zx::MonotonicInstant,
148    ) -> Result<DeviceCloseResult, fidl::Error> {
149        let _response = self.client.send_query::<
150            fidl::encoding::EmptyPayload,
151            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
152        >(
153            (),
154            0x621a0f31b867781a,
155            fidl::encoding::DynamicFlags::empty(),
156            ___deadline,
157        )?;
158        Ok(_response.map(|x| x))
159    }
160
161    /// Fetch the max frame size.
162    ///
163    /// This method may be called at any time. The returned
164    /// value is an implementation-specific constant.
165    ///
166    /// @return The size of the largest frame that this implementation
167    /// supports being passed into `SendFrame()`.
168    pub fn r#get_max_frame_size(
169        &self,
170        ___deadline: zx::MonotonicInstant,
171    ) -> Result<u32, fidl::Error> {
172        let _response =
173            self.client.send_query::<fidl::encoding::EmptyPayload, DeviceGetMaxFrameSizeResponse>(
174                (),
175                0x1d2d652e8b06d463,
176                fidl::encoding::DynamicFlags::empty(),
177                ___deadline,
178            )?;
179        Ok(_response.size)
180    }
181
182    /// Sends a Spinel-formatted frame to the device.
183    ///
184    /// Calling this method while the device is closed will cause
185    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
186    ///
187    /// See `->OnReadyForSendFrames()` for flow-control considerations.
188    pub fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
189        self.client.send::<DeviceSendFrameRequest>(
190            (data,),
191            0x634f2957b35c5944,
192            fidl::encoding::DynamicFlags::empty(),
193        )
194    }
195
196    /// Increases the number of additional frames that the caller is
197    /// currently ready to receive, as a method of inbound flow-control.
198    ///
199    /// The caller can use this method to regulate the speed at which
200    /// inbound frames are handled. This method should be called periodically
201    /// to ensure low-latency frame delivery.
202    ///
203    /// Calling this method with a non-zero value indicates to the
204    /// receiver that the caller is ready to receive the specified
205    /// additional number of frames.
206    ///
207    /// This method SHOULD NOT be called with a value of zero. If the
208    /// receiver gets this call with a value of zero, it MUST be ignored.
209    ///
210    /// Frames will not be received until this method is first called
211    /// with a non-zero value. Once received, the receiver will limit
212    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
213    /// to the given number of frames.
214    ///
215    /// Calling this method while the device is closed will do nothing.
216    ///
217    /// A reasonable usage pattern would be to first call this method
218    /// with a value of 4, calling it again with a value of 2 after
219    /// every second received inbound frame.
220    ///
221    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
222    pub fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
223        self.client.send::<DeviceReadyToReceiveFramesRequest>(
224            (number_of_frames,),
225            0x3147df23fdd53b87,
226            fidl::encoding::DynamicFlags::empty(),
227        )
228    }
229}
230
231#[cfg(target_os = "fuchsia")]
232impl From<DeviceSynchronousProxy> for zx::Handle {
233    fn from(value: DeviceSynchronousProxy) -> Self {
234        value.into_channel().into()
235    }
236}
237
238#[cfg(target_os = "fuchsia")]
239impl From<fidl::Channel> for DeviceSynchronousProxy {
240    fn from(value: fidl::Channel) -> Self {
241        Self::new(value)
242    }
243}
244
245#[cfg(target_os = "fuchsia")]
246impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
247    type Protocol = DeviceMarker;
248
249    fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
250        Self::new(value.into_channel())
251    }
252}
253
254#[derive(Debug, Clone)]
255pub struct DeviceProxy {
256    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
257}
258
259impl fidl::endpoints::Proxy for DeviceProxy {
260    type Protocol = DeviceMarker;
261
262    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
263        Self::new(inner)
264    }
265
266    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
267        self.client.into_channel().map_err(|client| Self { client })
268    }
269
270    fn as_channel(&self) -> &::fidl::AsyncChannel {
271        self.client.as_channel()
272    }
273}
274
275impl DeviceProxy {
276    /// Create a new Proxy for fuchsia.lowpan.spinel/Device.
277    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
278        let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
279        Self { client: fidl::client::Client::new(channel, protocol_name) }
280    }
281
282    /// Get a Stream of events from the remote end of the protocol.
283    ///
284    /// # Panics
285    ///
286    /// Panics if the event stream was already taken.
287    pub fn take_event_stream(&self) -> DeviceEventStream {
288        DeviceEventStream { event_receiver: self.client.take_event_receiver() }
289    }
290
291    /// Opens the Spinel connection and performs initialization.
292    ///
293    /// This method will block until the Device is ready to use or
294    /// an error has been encountered. If an error is indicated,
295    /// the device is still considered closed.
296    ///
297    /// Calling this method will typically induce reset if
298    /// supported by the underlying hardware. It may be called
299    /// while the device is already open in order to trigger a
300    /// reset.
301    ///
302    /// Possible error codes:
303    ///
304    /// * `Error::IO_ERROR`: An IO error occurred.
305    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
306    ///                         See logs for more details.
307    pub fn r#open(
308        &self,
309    ) -> fidl::client::QueryResponseFut<
310        DeviceOpenResult,
311        fidl::encoding::DefaultFuchsiaResourceDialect,
312    > {
313        DeviceProxyInterface::r#open(self)
314    }
315
316    /// Close the Spinel connection.
317    ///
318    /// This method will block until the Device has successfully
319    /// been put into a closed (preferably low-power) state. An
320    /// error may be indicated if a problem was encountered that
321    /// may indicate the device did not close cleanly.
322    ///
323    /// Calling this method will always cause this interface to be
324    /// closed, even if an error is reported. Thus, the error may
325    /// be simply ignored or logged.
326    ///
327    /// Calling this method when the device is already closed
328    /// will do nothing.
329    ///
330    /// Possible error codes:
331    ///
332    /// * `Error::IO_ERROR`: An IO error occurred.
333    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
334    ///                         See logs for more details.
335    pub fn r#close(
336        &self,
337    ) -> fidl::client::QueryResponseFut<
338        DeviceCloseResult,
339        fidl::encoding::DefaultFuchsiaResourceDialect,
340    > {
341        DeviceProxyInterface::r#close(self)
342    }
343
344    /// Fetch the max frame size.
345    ///
346    /// This method may be called at any time. The returned
347    /// value is an implementation-specific constant.
348    ///
349    /// @return The size of the largest frame that this implementation
350    /// supports being passed into `SendFrame()`.
351    pub fn r#get_max_frame_size(
352        &self,
353    ) -> fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect> {
354        DeviceProxyInterface::r#get_max_frame_size(self)
355    }
356
357    /// Sends a Spinel-formatted frame to the device.
358    ///
359    /// Calling this method while the device is closed will cause
360    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
361    ///
362    /// See `->OnReadyForSendFrames()` for flow-control considerations.
363    pub fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
364        DeviceProxyInterface::r#send_frame(self, data)
365    }
366
367    /// Increases the number of additional frames that the caller is
368    /// currently ready to receive, as a method of inbound flow-control.
369    ///
370    /// The caller can use this method to regulate the speed at which
371    /// inbound frames are handled. This method should be called periodically
372    /// to ensure low-latency frame delivery.
373    ///
374    /// Calling this method with a non-zero value indicates to the
375    /// receiver that the caller is ready to receive the specified
376    /// additional number of frames.
377    ///
378    /// This method SHOULD NOT be called with a value of zero. If the
379    /// receiver gets this call with a value of zero, it MUST be ignored.
380    ///
381    /// Frames will not be received until this method is first called
382    /// with a non-zero value. Once received, the receiver will limit
383    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
384    /// to the given number of frames.
385    ///
386    /// Calling this method while the device is closed will do nothing.
387    ///
388    /// A reasonable usage pattern would be to first call this method
389    /// with a value of 4, calling it again with a value of 2 after
390    /// every second received inbound frame.
391    ///
392    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
393    pub fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
394        DeviceProxyInterface::r#ready_to_receive_frames(self, number_of_frames)
395    }
396}
397
398impl DeviceProxyInterface for DeviceProxy {
399    type OpenResponseFut = fidl::client::QueryResponseFut<
400        DeviceOpenResult,
401        fidl::encoding::DefaultFuchsiaResourceDialect,
402    >;
403    fn r#open(&self) -> Self::OpenResponseFut {
404        fn _decode(
405            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
406        ) -> Result<DeviceOpenResult, fidl::Error> {
407            let _response = fidl::client::decode_transaction_body::<
408                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
409                fidl::encoding::DefaultFuchsiaResourceDialect,
410                0x508cecb73a776ef7,
411            >(_buf?)?;
412            Ok(_response.map(|x| x))
413        }
414        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceOpenResult>(
415            (),
416            0x508cecb73a776ef7,
417            fidl::encoding::DynamicFlags::empty(),
418            _decode,
419        )
420    }
421
422    type CloseResponseFut = fidl::client::QueryResponseFut<
423        DeviceCloseResult,
424        fidl::encoding::DefaultFuchsiaResourceDialect,
425    >;
426    fn r#close(&self) -> Self::CloseResponseFut {
427        fn _decode(
428            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
429        ) -> Result<DeviceCloseResult, fidl::Error> {
430            let _response = fidl::client::decode_transaction_body::<
431                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>,
432                fidl::encoding::DefaultFuchsiaResourceDialect,
433                0x621a0f31b867781a,
434            >(_buf?)?;
435            Ok(_response.map(|x| x))
436        }
437        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, DeviceCloseResult>(
438            (),
439            0x621a0f31b867781a,
440            fidl::encoding::DynamicFlags::empty(),
441            _decode,
442        )
443    }
444
445    type GetMaxFrameSizeResponseFut =
446        fidl::client::QueryResponseFut<u32, fidl::encoding::DefaultFuchsiaResourceDialect>;
447    fn r#get_max_frame_size(&self) -> Self::GetMaxFrameSizeResponseFut {
448        fn _decode(
449            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
450        ) -> Result<u32, fidl::Error> {
451            let _response = fidl::client::decode_transaction_body::<
452                DeviceGetMaxFrameSizeResponse,
453                fidl::encoding::DefaultFuchsiaResourceDialect,
454                0x1d2d652e8b06d463,
455            >(_buf?)?;
456            Ok(_response.size)
457        }
458        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, u32>(
459            (),
460            0x1d2d652e8b06d463,
461            fidl::encoding::DynamicFlags::empty(),
462            _decode,
463        )
464    }
465
466    fn r#send_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
467        self.client.send::<DeviceSendFrameRequest>(
468            (data,),
469            0x634f2957b35c5944,
470            fidl::encoding::DynamicFlags::empty(),
471        )
472    }
473
474    fn r#ready_to_receive_frames(&self, mut number_of_frames: u32) -> Result<(), fidl::Error> {
475        self.client.send::<DeviceReadyToReceiveFramesRequest>(
476            (number_of_frames,),
477            0x3147df23fdd53b87,
478            fidl::encoding::DynamicFlags::empty(),
479        )
480    }
481}
482
483pub struct DeviceEventStream {
484    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
485}
486
487impl std::marker::Unpin for DeviceEventStream {}
488
489impl futures::stream::FusedStream for DeviceEventStream {
490    fn is_terminated(&self) -> bool {
491        self.event_receiver.is_terminated()
492    }
493}
494
495impl futures::Stream for DeviceEventStream {
496    type Item = Result<DeviceEvent, fidl::Error>;
497
498    fn poll_next(
499        mut self: std::pin::Pin<&mut Self>,
500        cx: &mut std::task::Context<'_>,
501    ) -> std::task::Poll<Option<Self::Item>> {
502        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
503            &mut self.event_receiver,
504            cx
505        )?) {
506            Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
507            None => std::task::Poll::Ready(None),
508        }
509    }
510}
511
512#[derive(Debug)]
513pub enum DeviceEvent {
514    OnReadyForSendFrames { number_of_frames: u32 },
515    OnReceiveFrame { data: Vec<u8> },
516    OnError { error: Error, did_close: bool },
517}
518
519impl DeviceEvent {
520    #[allow(irrefutable_let_patterns)]
521    pub fn into_on_ready_for_send_frames(self) -> Option<u32> {
522        if let DeviceEvent::OnReadyForSendFrames { number_of_frames } = self {
523            Some((number_of_frames))
524        } else {
525            None
526        }
527    }
528    #[allow(irrefutable_let_patterns)]
529    pub fn into_on_receive_frame(self) -> Option<Vec<u8>> {
530        if let DeviceEvent::OnReceiveFrame { data } = self { Some((data)) } else { None }
531    }
532    #[allow(irrefutable_let_patterns)]
533    pub fn into_on_error(self) -> Option<(Error, bool)> {
534        if let DeviceEvent::OnError { error, did_close } = self {
535            Some((error, did_close))
536        } else {
537            None
538        }
539    }
540
541    /// Decodes a message buffer as a [`DeviceEvent`].
542    fn decode(
543        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
544    ) -> Result<DeviceEvent, fidl::Error> {
545        let (bytes, _handles) = buf.split_mut();
546        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
547        debug_assert_eq!(tx_header.tx_id, 0);
548        match tx_header.ordinal {
549            0x2b1d5b28c5811b53 => {
550                let mut out = fidl::new_empty!(
551                    DeviceOnReadyForSendFramesRequest,
552                    fidl::encoding::DefaultFuchsiaResourceDialect
553                );
554                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnReadyForSendFramesRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
555                Ok((DeviceEvent::OnReadyForSendFrames { number_of_frames: out.number_of_frames }))
556            }
557            0x61937a45670aabb0 => {
558                let mut out = fidl::new_empty!(
559                    DeviceOnReceiveFrameRequest,
560                    fidl::encoding::DefaultFuchsiaResourceDialect
561                );
562                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnReceiveFrameRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
563                Ok((DeviceEvent::OnReceiveFrame { data: out.data }))
564            }
565            0x4d20e65a9d2625e1 => {
566                let mut out = fidl::new_empty!(
567                    DeviceOnErrorRequest,
568                    fidl::encoding::DefaultFuchsiaResourceDialect
569                );
570                fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceOnErrorRequest>(&tx_header, _body_bytes, _handles, &mut out)?;
571                Ok((DeviceEvent::OnError { error: out.error, did_close: out.did_close }))
572            }
573            _ => Err(fidl::Error::UnknownOrdinal {
574                ordinal: tx_header.ordinal,
575                protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
576            }),
577        }
578    }
579}
580
581/// A Stream of incoming requests for fuchsia.lowpan.spinel/Device.
582pub struct DeviceRequestStream {
583    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
584    is_terminated: bool,
585}
586
587impl std::marker::Unpin for DeviceRequestStream {}
588
589impl futures::stream::FusedStream for DeviceRequestStream {
590    fn is_terminated(&self) -> bool {
591        self.is_terminated
592    }
593}
594
595impl fidl::endpoints::RequestStream for DeviceRequestStream {
596    type Protocol = DeviceMarker;
597    type ControlHandle = DeviceControlHandle;
598
599    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
600        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
601    }
602
603    fn control_handle(&self) -> Self::ControlHandle {
604        DeviceControlHandle { inner: self.inner.clone() }
605    }
606
607    fn into_inner(
608        self,
609    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
610    {
611        (self.inner, self.is_terminated)
612    }
613
614    fn from_inner(
615        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
616        is_terminated: bool,
617    ) -> Self {
618        Self { inner, is_terminated }
619    }
620}
621
622impl futures::Stream for DeviceRequestStream {
623    type Item = Result<DeviceRequest, fidl::Error>;
624
625    fn poll_next(
626        mut self: std::pin::Pin<&mut Self>,
627        cx: &mut std::task::Context<'_>,
628    ) -> std::task::Poll<Option<Self::Item>> {
629        let this = &mut *self;
630        if this.inner.check_shutdown(cx) {
631            this.is_terminated = true;
632            return std::task::Poll::Ready(None);
633        }
634        if this.is_terminated {
635            panic!("polled DeviceRequestStream after completion");
636        }
637        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
638            |bytes, handles| {
639                match this.inner.channel().read_etc(cx, bytes, handles) {
640                    std::task::Poll::Ready(Ok(())) => {}
641                    std::task::Poll::Pending => return std::task::Poll::Pending,
642                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
643                        this.is_terminated = true;
644                        return std::task::Poll::Ready(None);
645                    }
646                    std::task::Poll::Ready(Err(e)) => {
647                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
648                            e.into(),
649                        ))));
650                    }
651                }
652
653                // A message has been received from the channel
654                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
655
656                std::task::Poll::Ready(Some(match header.ordinal {
657                    0x508cecb73a776ef7 => {
658                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
659                        let mut req = fidl::new_empty!(
660                            fidl::encoding::EmptyPayload,
661                            fidl::encoding::DefaultFuchsiaResourceDialect
662                        );
663                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
664                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
665                        Ok(DeviceRequest::Open {
666                            responder: DeviceOpenResponder {
667                                control_handle: std::mem::ManuallyDrop::new(control_handle),
668                                tx_id: header.tx_id,
669                            },
670                        })
671                    }
672                    0x621a0f31b867781a => {
673                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
674                        let mut req = fidl::new_empty!(
675                            fidl::encoding::EmptyPayload,
676                            fidl::encoding::DefaultFuchsiaResourceDialect
677                        );
678                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
679                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
680                        Ok(DeviceRequest::Close {
681                            responder: DeviceCloseResponder {
682                                control_handle: std::mem::ManuallyDrop::new(control_handle),
683                                tx_id: header.tx_id,
684                            },
685                        })
686                    }
687                    0x1d2d652e8b06d463 => {
688                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
689                        let mut req = fidl::new_empty!(
690                            fidl::encoding::EmptyPayload,
691                            fidl::encoding::DefaultFuchsiaResourceDialect
692                        );
693                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
694                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
695                        Ok(DeviceRequest::GetMaxFrameSize {
696                            responder: DeviceGetMaxFrameSizeResponder {
697                                control_handle: std::mem::ManuallyDrop::new(control_handle),
698                                tx_id: header.tx_id,
699                            },
700                        })
701                    }
702                    0x634f2957b35c5944 => {
703                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
704                        let mut req = fidl::new_empty!(
705                            DeviceSendFrameRequest,
706                            fidl::encoding::DefaultFuchsiaResourceDialect
707                        );
708                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSendFrameRequest>(&header, _body_bytes, handles, &mut req)?;
709                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
710                        Ok(DeviceRequest::SendFrame { data: req.data, control_handle })
711                    }
712                    0x3147df23fdd53b87 => {
713                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
714                        let mut req = fidl::new_empty!(
715                            DeviceReadyToReceiveFramesRequest,
716                            fidl::encoding::DefaultFuchsiaResourceDialect
717                        );
718                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceReadyToReceiveFramesRequest>(&header, _body_bytes, handles, &mut req)?;
719                        let control_handle = DeviceControlHandle { inner: this.inner.clone() };
720                        Ok(DeviceRequest::ReadyToReceiveFrames {
721                            number_of_frames: req.number_of_frames,
722
723                            control_handle,
724                        })
725                    }
726                    _ => Err(fidl::Error::UnknownOrdinal {
727                        ordinal: header.ordinal,
728                        protocol_name:
729                            <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
730                    }),
731                }))
732            },
733        )
734    }
735}
736
737#[derive(Debug)]
738pub enum DeviceRequest {
739    /// Opens the Spinel connection and performs initialization.
740    ///
741    /// This method will block until the Device is ready to use or
742    /// an error has been encountered. If an error is indicated,
743    /// the device is still considered closed.
744    ///
745    /// Calling this method will typically induce reset if
746    /// supported by the underlying hardware. It may be called
747    /// while the device is already open in order to trigger a
748    /// reset.
749    ///
750    /// Possible error codes:
751    ///
752    /// * `Error::IO_ERROR`: An IO error occurred.
753    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
754    ///                         See logs for more details.
755    Open { responder: DeviceOpenResponder },
756    /// Close the Spinel connection.
757    ///
758    /// This method will block until the Device has successfully
759    /// been put into a closed (preferably low-power) state. An
760    /// error may be indicated if a problem was encountered that
761    /// may indicate the device did not close cleanly.
762    ///
763    /// Calling this method will always cause this interface to be
764    /// closed, even if an error is reported. Thus, the error may
765    /// be simply ignored or logged.
766    ///
767    /// Calling this method when the device is already closed
768    /// will do nothing.
769    ///
770    /// Possible error codes:
771    ///
772    /// * `Error::IO_ERROR`: An IO error occurred.
773    /// * `Error::UNSPECIFIED`: An unspecified error occurred.
774    ///                         See logs for more details.
775    Close { responder: DeviceCloseResponder },
776    /// Fetch the max frame size.
777    ///
778    /// This method may be called at any time. The returned
779    /// value is an implementation-specific constant.
780    ///
781    /// @return The size of the largest frame that this implementation
782    /// supports being passed into `SendFrame()`.
783    GetMaxFrameSize { responder: DeviceGetMaxFrameSizeResponder },
784    /// Sends a Spinel-formatted frame to the device.
785    ///
786    /// Calling this method while the device is closed will cause
787    /// the frame to be dropped and `->OnError()` to emit `Error::CLOSED`.
788    ///
789    /// See `->OnReadyForSendFrames()` for flow-control considerations.
790    SendFrame { data: Vec<u8>, control_handle: DeviceControlHandle },
791    /// Increases the number of additional frames that the caller is
792    /// currently ready to receive, as a method of inbound flow-control.
793    ///
794    /// The caller can use this method to regulate the speed at which
795    /// inbound frames are handled. This method should be called periodically
796    /// to ensure low-latency frame delivery.
797    ///
798    /// Calling this method with a non-zero value indicates to the
799    /// receiver that the caller is ready to receive the specified
800    /// additional number of frames.
801    ///
802    /// This method SHOULD NOT be called with a value of zero. If the
803    /// receiver gets this call with a value of zero, it MUST be ignored.
804    ///
805    /// Frames will not be received until this method is first called
806    /// with a non-zero value. Once received, the receiver will limit
807    /// the number of subsequent frames emitted via `->OnReceiveFrame()`
808    /// to the given number of frames.
809    ///
810    /// Calling this method while the device is closed will do nothing.
811    ///
812    /// A reasonable usage pattern would be to first call this method
813    /// with a value of 4, calling it again with a value of 2 after
814    /// every second received inbound frame.
815    ///
816    /// Outbound flow control is similarly accomplished via `->OnReadyForSendFrames()`.
817    ReadyToReceiveFrames { number_of_frames: u32, control_handle: DeviceControlHandle },
818}
819
820impl DeviceRequest {
821    #[allow(irrefutable_let_patterns)]
822    pub fn into_open(self) -> Option<(DeviceOpenResponder)> {
823        if let DeviceRequest::Open { responder } = self { Some((responder)) } else { None }
824    }
825
826    #[allow(irrefutable_let_patterns)]
827    pub fn into_close(self) -> Option<(DeviceCloseResponder)> {
828        if let DeviceRequest::Close { responder } = self { Some((responder)) } else { None }
829    }
830
831    #[allow(irrefutable_let_patterns)]
832    pub fn into_get_max_frame_size(self) -> Option<(DeviceGetMaxFrameSizeResponder)> {
833        if let DeviceRequest::GetMaxFrameSize { responder } = self {
834            Some((responder))
835        } else {
836            None
837        }
838    }
839
840    #[allow(irrefutable_let_patterns)]
841    pub fn into_send_frame(self) -> Option<(Vec<u8>, DeviceControlHandle)> {
842        if let DeviceRequest::SendFrame { data, control_handle } = self {
843            Some((data, control_handle))
844        } else {
845            None
846        }
847    }
848
849    #[allow(irrefutable_let_patterns)]
850    pub fn into_ready_to_receive_frames(self) -> Option<(u32, DeviceControlHandle)> {
851        if let DeviceRequest::ReadyToReceiveFrames { number_of_frames, control_handle } = self {
852            Some((number_of_frames, control_handle))
853        } else {
854            None
855        }
856    }
857
858    /// Name of the method defined in FIDL
859    pub fn method_name(&self) -> &'static str {
860        match *self {
861            DeviceRequest::Open { .. } => "open",
862            DeviceRequest::Close { .. } => "close",
863            DeviceRequest::GetMaxFrameSize { .. } => "get_max_frame_size",
864            DeviceRequest::SendFrame { .. } => "send_frame",
865            DeviceRequest::ReadyToReceiveFrames { .. } => "ready_to_receive_frames",
866        }
867    }
868}
869
870#[derive(Debug, Clone)]
871pub struct DeviceControlHandle {
872    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
873}
874
875impl fidl::endpoints::ControlHandle for DeviceControlHandle {
876    fn shutdown(&self) {
877        self.inner.shutdown()
878    }
879    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
880        self.inner.shutdown_with_epitaph(status)
881    }
882
883    fn is_closed(&self) -> bool {
884        self.inner.channel().is_closed()
885    }
886    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
887        self.inner.channel().on_closed()
888    }
889
890    #[cfg(target_os = "fuchsia")]
891    fn signal_peer(
892        &self,
893        clear_mask: zx::Signals,
894        set_mask: zx::Signals,
895    ) -> Result<(), zx_status::Status> {
896        use fidl::Peered;
897        self.inner.channel().signal_peer(clear_mask, set_mask)
898    }
899}
900
901impl DeviceControlHandle {
902    pub fn send_on_ready_for_send_frames(
903        &self,
904        mut number_of_frames: u32,
905    ) -> Result<(), fidl::Error> {
906        self.inner.send::<DeviceOnReadyForSendFramesRequest>(
907            (number_of_frames,),
908            0,
909            0x2b1d5b28c5811b53,
910            fidl::encoding::DynamicFlags::empty(),
911        )
912    }
913
914    pub fn send_on_receive_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
915        self.inner.send::<DeviceOnReceiveFrameRequest>(
916            (data,),
917            0,
918            0x61937a45670aabb0,
919            fidl::encoding::DynamicFlags::empty(),
920        )
921    }
922
923    pub fn send_on_error(&self, mut error: Error, mut did_close: bool) -> Result<(), fidl::Error> {
924        self.inner.send::<DeviceOnErrorRequest>(
925            (error, did_close),
926            0,
927            0x4d20e65a9d2625e1,
928            fidl::encoding::DynamicFlags::empty(),
929        )
930    }
931}
932
933#[must_use = "FIDL methods require a response to be sent"]
934#[derive(Debug)]
935pub struct DeviceOpenResponder {
936    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
937    tx_id: u32,
938}
939
940/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
941/// if the responder is dropped without sending a response, so that the client
942/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
943impl std::ops::Drop for DeviceOpenResponder {
944    fn drop(&mut self) {
945        self.control_handle.shutdown();
946        // Safety: drops once, never accessed again
947        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
948    }
949}
950
951impl fidl::endpoints::Responder for DeviceOpenResponder {
952    type ControlHandle = DeviceControlHandle;
953
954    fn control_handle(&self) -> &DeviceControlHandle {
955        &self.control_handle
956    }
957
958    fn drop_without_shutdown(mut self) {
959        // Safety: drops once, never accessed again due to mem::forget
960        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
961        // Prevent Drop from running (which would shut down the channel)
962        std::mem::forget(self);
963    }
964}
965
966impl DeviceOpenResponder {
967    /// Sends a response to the FIDL transaction.
968    ///
969    /// Sets the channel to shutdown if an error occurs.
970    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
971        let _result = self.send_raw(result);
972        if _result.is_err() {
973            self.control_handle.shutdown();
974        }
975        self.drop_without_shutdown();
976        _result
977    }
978
979    /// Similar to "send" but does not shutdown the channel if an error occurs.
980    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
981        let _result = self.send_raw(result);
982        self.drop_without_shutdown();
983        _result
984    }
985
986    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
987        self.control_handle
988            .inner
989            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
990                result,
991                self.tx_id,
992                0x508cecb73a776ef7,
993                fidl::encoding::DynamicFlags::empty(),
994            )
995    }
996}
997
998#[must_use = "FIDL methods require a response to be sent"]
999#[derive(Debug)]
1000pub struct DeviceCloseResponder {
1001    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1002    tx_id: u32,
1003}
1004
1005/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1006/// if the responder is dropped without sending a response, so that the client
1007/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1008impl std::ops::Drop for DeviceCloseResponder {
1009    fn drop(&mut self) {
1010        self.control_handle.shutdown();
1011        // Safety: drops once, never accessed again
1012        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1013    }
1014}
1015
1016impl fidl::endpoints::Responder for DeviceCloseResponder {
1017    type ControlHandle = DeviceControlHandle;
1018
1019    fn control_handle(&self) -> &DeviceControlHandle {
1020        &self.control_handle
1021    }
1022
1023    fn drop_without_shutdown(mut self) {
1024        // Safety: drops once, never accessed again due to mem::forget
1025        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1026        // Prevent Drop from running (which would shut down the channel)
1027        std::mem::forget(self);
1028    }
1029}
1030
1031impl DeviceCloseResponder {
1032    /// Sends a response to the FIDL transaction.
1033    ///
1034    /// Sets the channel to shutdown if an error occurs.
1035    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1036        let _result = self.send_raw(result);
1037        if _result.is_err() {
1038            self.control_handle.shutdown();
1039        }
1040        self.drop_without_shutdown();
1041        _result
1042    }
1043
1044    /// Similar to "send" but does not shutdown the channel if an error occurs.
1045    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1046        let _result = self.send_raw(result);
1047        self.drop_without_shutdown();
1048        _result
1049    }
1050
1051    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1052        self.control_handle
1053            .inner
1054            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1055                result,
1056                self.tx_id,
1057                0x621a0f31b867781a,
1058                fidl::encoding::DynamicFlags::empty(),
1059            )
1060    }
1061}
1062
1063#[must_use = "FIDL methods require a response to be sent"]
1064#[derive(Debug)]
1065pub struct DeviceGetMaxFrameSizeResponder {
1066    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1067    tx_id: u32,
1068}
1069
1070/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1071/// if the responder is dropped without sending a response, so that the client
1072/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1073impl std::ops::Drop for DeviceGetMaxFrameSizeResponder {
1074    fn drop(&mut self) {
1075        self.control_handle.shutdown();
1076        // Safety: drops once, never accessed again
1077        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1078    }
1079}
1080
1081impl fidl::endpoints::Responder for DeviceGetMaxFrameSizeResponder {
1082    type ControlHandle = DeviceControlHandle;
1083
1084    fn control_handle(&self) -> &DeviceControlHandle {
1085        &self.control_handle
1086    }
1087
1088    fn drop_without_shutdown(mut self) {
1089        // Safety: drops once, never accessed again due to mem::forget
1090        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1091        // Prevent Drop from running (which would shut down the channel)
1092        std::mem::forget(self);
1093    }
1094}
1095
1096impl DeviceGetMaxFrameSizeResponder {
1097    /// Sends a response to the FIDL transaction.
1098    ///
1099    /// Sets the channel to shutdown if an error occurs.
1100    pub fn send(self, mut size: u32) -> Result<(), fidl::Error> {
1101        let _result = self.send_raw(size);
1102        if _result.is_err() {
1103            self.control_handle.shutdown();
1104        }
1105        self.drop_without_shutdown();
1106        _result
1107    }
1108
1109    /// Similar to "send" but does not shutdown the channel if an error occurs.
1110    pub fn send_no_shutdown_on_err(self, mut size: u32) -> Result<(), fidl::Error> {
1111        let _result = self.send_raw(size);
1112        self.drop_without_shutdown();
1113        _result
1114    }
1115
1116    fn send_raw(&self, mut size: u32) -> Result<(), fidl::Error> {
1117        self.control_handle.inner.send::<DeviceGetMaxFrameSizeResponse>(
1118            (size,),
1119            self.tx_id,
1120            0x1d2d652e8b06d463,
1121            fidl::encoding::DynamicFlags::empty(),
1122        )
1123    }
1124}
1125
1126#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1127pub struct DeviceSetupMarker;
1128
1129impl fidl::endpoints::ProtocolMarker for DeviceSetupMarker {
1130    type Proxy = DeviceSetupProxy;
1131    type RequestStream = DeviceSetupRequestStream;
1132    #[cfg(target_os = "fuchsia")]
1133    type SynchronousProxy = DeviceSetupSynchronousProxy;
1134
1135    const DEBUG_NAME: &'static str = "(anonymous) DeviceSetup";
1136}
1137pub type DeviceSetupSetChannelResult = Result<(), i32>;
1138
1139pub trait DeviceSetupProxyInterface: Send + Sync {
1140    type SetChannelResponseFut: std::future::Future<Output = Result<DeviceSetupSetChannelResult, fidl::Error>>
1141        + Send;
1142    fn r#set_channel(
1143        &self,
1144        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1145    ) -> Self::SetChannelResponseFut;
1146}
1147#[derive(Debug)]
1148#[cfg(target_os = "fuchsia")]
1149pub struct DeviceSetupSynchronousProxy {
1150    client: fidl::client::sync::Client,
1151}
1152
1153#[cfg(target_os = "fuchsia")]
1154impl fidl::endpoints::SynchronousProxy for DeviceSetupSynchronousProxy {
1155    type Proxy = DeviceSetupProxy;
1156    type Protocol = DeviceSetupMarker;
1157
1158    fn from_channel(inner: fidl::Channel) -> Self {
1159        Self::new(inner)
1160    }
1161
1162    fn into_channel(self) -> fidl::Channel {
1163        self.client.into_channel()
1164    }
1165
1166    fn as_channel(&self) -> &fidl::Channel {
1167        self.client.as_channel()
1168    }
1169}
1170
1171#[cfg(target_os = "fuchsia")]
1172impl DeviceSetupSynchronousProxy {
1173    pub fn new(channel: fidl::Channel) -> Self {
1174        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1175        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1176    }
1177
1178    pub fn into_channel(self) -> fidl::Channel {
1179        self.client.into_channel()
1180    }
1181
1182    /// Waits until an event arrives and returns it. It is safe for other
1183    /// threads to make concurrent requests while waiting for an event.
1184    pub fn wait_for_event(
1185        &self,
1186        deadline: zx::MonotonicInstant,
1187    ) -> Result<DeviceSetupEvent, fidl::Error> {
1188        DeviceSetupEvent::decode(self.client.wait_for_event(deadline)?)
1189    }
1190
1191    pub fn r#set_channel(
1192        &self,
1193        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1194        ___deadline: zx::MonotonicInstant,
1195    ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1196        let _response = self.client.send_query::<
1197            DeviceSetupSetChannelRequest,
1198            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1199        >(
1200            (req,),
1201            0x7f8e02c174ef02a5,
1202            fidl::encoding::DynamicFlags::empty(),
1203            ___deadline,
1204        )?;
1205        Ok(_response.map(|x| x))
1206    }
1207}
1208
1209#[cfg(target_os = "fuchsia")]
1210impl From<DeviceSetupSynchronousProxy> for zx::Handle {
1211    fn from(value: DeviceSetupSynchronousProxy) -> Self {
1212        value.into_channel().into()
1213    }
1214}
1215
1216#[cfg(target_os = "fuchsia")]
1217impl From<fidl::Channel> for DeviceSetupSynchronousProxy {
1218    fn from(value: fidl::Channel) -> Self {
1219        Self::new(value)
1220    }
1221}
1222
1223#[cfg(target_os = "fuchsia")]
1224impl fidl::endpoints::FromClient for DeviceSetupSynchronousProxy {
1225    type Protocol = DeviceSetupMarker;
1226
1227    fn from_client(value: fidl::endpoints::ClientEnd<DeviceSetupMarker>) -> Self {
1228        Self::new(value.into_channel())
1229    }
1230}
1231
1232#[derive(Debug, Clone)]
1233pub struct DeviceSetupProxy {
1234    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1235}
1236
1237impl fidl::endpoints::Proxy for DeviceSetupProxy {
1238    type Protocol = DeviceSetupMarker;
1239
1240    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1241        Self::new(inner)
1242    }
1243
1244    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1245        self.client.into_channel().map_err(|client| Self { client })
1246    }
1247
1248    fn as_channel(&self) -> &::fidl::AsyncChannel {
1249        self.client.as_channel()
1250    }
1251}
1252
1253impl DeviceSetupProxy {
1254    /// Create a new Proxy for fuchsia.lowpan.spinel/DeviceSetup.
1255    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1256        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1257        Self { client: fidl::client::Client::new(channel, protocol_name) }
1258    }
1259
1260    /// Get a Stream of events from the remote end of the protocol.
1261    ///
1262    /// # Panics
1263    ///
1264    /// Panics if the event stream was already taken.
1265    pub fn take_event_stream(&self) -> DeviceSetupEventStream {
1266        DeviceSetupEventStream { event_receiver: self.client.take_event_receiver() }
1267    }
1268
1269    pub fn r#set_channel(
1270        &self,
1271        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1272    ) -> fidl::client::QueryResponseFut<
1273        DeviceSetupSetChannelResult,
1274        fidl::encoding::DefaultFuchsiaResourceDialect,
1275    > {
1276        DeviceSetupProxyInterface::r#set_channel(self, req)
1277    }
1278}
1279
1280impl DeviceSetupProxyInterface for DeviceSetupProxy {
1281    type SetChannelResponseFut = fidl::client::QueryResponseFut<
1282        DeviceSetupSetChannelResult,
1283        fidl::encoding::DefaultFuchsiaResourceDialect,
1284    >;
1285    fn r#set_channel(
1286        &self,
1287        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1288    ) -> Self::SetChannelResponseFut {
1289        fn _decode(
1290            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1291        ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1292            let _response = fidl::client::decode_transaction_body::<
1293                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1294                fidl::encoding::DefaultFuchsiaResourceDialect,
1295                0x7f8e02c174ef02a5,
1296            >(_buf?)?;
1297            Ok(_response.map(|x| x))
1298        }
1299        self.client
1300            .send_query_and_decode::<DeviceSetupSetChannelRequest, DeviceSetupSetChannelResult>(
1301                (req,),
1302                0x7f8e02c174ef02a5,
1303                fidl::encoding::DynamicFlags::empty(),
1304                _decode,
1305            )
1306    }
1307}
1308
1309pub struct DeviceSetupEventStream {
1310    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1311}
1312
1313impl std::marker::Unpin for DeviceSetupEventStream {}
1314
1315impl futures::stream::FusedStream for DeviceSetupEventStream {
1316    fn is_terminated(&self) -> bool {
1317        self.event_receiver.is_terminated()
1318    }
1319}
1320
1321impl futures::Stream for DeviceSetupEventStream {
1322    type Item = Result<DeviceSetupEvent, fidl::Error>;
1323
1324    fn poll_next(
1325        mut self: std::pin::Pin<&mut Self>,
1326        cx: &mut std::task::Context<'_>,
1327    ) -> std::task::Poll<Option<Self::Item>> {
1328        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1329            &mut self.event_receiver,
1330            cx
1331        )?) {
1332            Some(buf) => std::task::Poll::Ready(Some(DeviceSetupEvent::decode(buf))),
1333            None => std::task::Poll::Ready(None),
1334        }
1335    }
1336}
1337
1338#[derive(Debug)]
1339pub enum DeviceSetupEvent {}
1340
1341impl DeviceSetupEvent {
1342    /// Decodes a message buffer as a [`DeviceSetupEvent`].
1343    fn decode(
1344        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1345    ) -> Result<DeviceSetupEvent, fidl::Error> {
1346        let (bytes, _handles) = buf.split_mut();
1347        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1348        debug_assert_eq!(tx_header.tx_id, 0);
1349        match tx_header.ordinal {
1350            _ => Err(fidl::Error::UnknownOrdinal {
1351                ordinal: tx_header.ordinal,
1352                protocol_name: <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1353            }),
1354        }
1355    }
1356}
1357
1358/// A Stream of incoming requests for fuchsia.lowpan.spinel/DeviceSetup.
1359pub struct DeviceSetupRequestStream {
1360    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1361    is_terminated: bool,
1362}
1363
1364impl std::marker::Unpin for DeviceSetupRequestStream {}
1365
1366impl futures::stream::FusedStream for DeviceSetupRequestStream {
1367    fn is_terminated(&self) -> bool {
1368        self.is_terminated
1369    }
1370}
1371
1372impl fidl::endpoints::RequestStream for DeviceSetupRequestStream {
1373    type Protocol = DeviceSetupMarker;
1374    type ControlHandle = DeviceSetupControlHandle;
1375
1376    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1377        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1378    }
1379
1380    fn control_handle(&self) -> Self::ControlHandle {
1381        DeviceSetupControlHandle { inner: self.inner.clone() }
1382    }
1383
1384    fn into_inner(
1385        self,
1386    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1387    {
1388        (self.inner, self.is_terminated)
1389    }
1390
1391    fn from_inner(
1392        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1393        is_terminated: bool,
1394    ) -> Self {
1395        Self { inner, is_terminated }
1396    }
1397}
1398
1399impl futures::Stream for DeviceSetupRequestStream {
1400    type Item = Result<DeviceSetupRequest, fidl::Error>;
1401
1402    fn poll_next(
1403        mut self: std::pin::Pin<&mut Self>,
1404        cx: &mut std::task::Context<'_>,
1405    ) -> std::task::Poll<Option<Self::Item>> {
1406        let this = &mut *self;
1407        if this.inner.check_shutdown(cx) {
1408            this.is_terminated = true;
1409            return std::task::Poll::Ready(None);
1410        }
1411        if this.is_terminated {
1412            panic!("polled DeviceSetupRequestStream after completion");
1413        }
1414        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1415            |bytes, handles| {
1416                match this.inner.channel().read_etc(cx, bytes, handles) {
1417                    std::task::Poll::Ready(Ok(())) => {}
1418                    std::task::Poll::Pending => return std::task::Poll::Pending,
1419                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1420                        this.is_terminated = true;
1421                        return std::task::Poll::Ready(None);
1422                    }
1423                    std::task::Poll::Ready(Err(e)) => {
1424                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1425                            e.into(),
1426                        ))));
1427                    }
1428                }
1429
1430                // A message has been received from the channel
1431                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1432
1433                std::task::Poll::Ready(Some(match header.ordinal {
1434                    0x7f8e02c174ef02a5 => {
1435                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1436                        let mut req = fidl::new_empty!(
1437                            DeviceSetupSetChannelRequest,
1438                            fidl::encoding::DefaultFuchsiaResourceDialect
1439                        );
1440                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetupSetChannelRequest>(&header, _body_bytes, handles, &mut req)?;
1441                        let control_handle = DeviceSetupControlHandle { inner: this.inner.clone() };
1442                        Ok(DeviceSetupRequest::SetChannel {
1443                            req: req.req,
1444
1445                            responder: DeviceSetupSetChannelResponder {
1446                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1447                                tx_id: header.tx_id,
1448                            },
1449                        })
1450                    }
1451                    _ => Err(fidl::Error::UnknownOrdinal {
1452                        ordinal: header.ordinal,
1453                        protocol_name:
1454                            <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1455                    }),
1456                }))
1457            },
1458        )
1459    }
1460}
1461
1462#[derive(Debug)]
1463pub enum DeviceSetupRequest {
1464    SetChannel {
1465        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1466        responder: DeviceSetupSetChannelResponder,
1467    },
1468}
1469
1470impl DeviceSetupRequest {
1471    #[allow(irrefutable_let_patterns)]
1472    pub fn into_set_channel(
1473        self,
1474    ) -> Option<(fidl::endpoints::ServerEnd<DeviceMarker>, DeviceSetupSetChannelResponder)> {
1475        if let DeviceSetupRequest::SetChannel { req, responder } = self {
1476            Some((req, responder))
1477        } else {
1478            None
1479        }
1480    }
1481
1482    /// Name of the method defined in FIDL
1483    pub fn method_name(&self) -> &'static str {
1484        match *self {
1485            DeviceSetupRequest::SetChannel { .. } => "set_channel",
1486        }
1487    }
1488}
1489
1490#[derive(Debug, Clone)]
1491pub struct DeviceSetupControlHandle {
1492    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1493}
1494
1495impl fidl::endpoints::ControlHandle for DeviceSetupControlHandle {
1496    fn shutdown(&self) {
1497        self.inner.shutdown()
1498    }
1499    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1500        self.inner.shutdown_with_epitaph(status)
1501    }
1502
1503    fn is_closed(&self) -> bool {
1504        self.inner.channel().is_closed()
1505    }
1506    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1507        self.inner.channel().on_closed()
1508    }
1509
1510    #[cfg(target_os = "fuchsia")]
1511    fn signal_peer(
1512        &self,
1513        clear_mask: zx::Signals,
1514        set_mask: zx::Signals,
1515    ) -> Result<(), zx_status::Status> {
1516        use fidl::Peered;
1517        self.inner.channel().signal_peer(clear_mask, set_mask)
1518    }
1519}
1520
1521impl DeviceSetupControlHandle {}
1522
1523#[must_use = "FIDL methods require a response to be sent"]
1524#[derive(Debug)]
1525pub struct DeviceSetupSetChannelResponder {
1526    control_handle: std::mem::ManuallyDrop<DeviceSetupControlHandle>,
1527    tx_id: u32,
1528}
1529
1530/// Set the the channel to be shutdown (see [`DeviceSetupControlHandle::shutdown`])
1531/// if the responder is dropped without sending a response, so that the client
1532/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1533impl std::ops::Drop for DeviceSetupSetChannelResponder {
1534    fn drop(&mut self) {
1535        self.control_handle.shutdown();
1536        // Safety: drops once, never accessed again
1537        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1538    }
1539}
1540
1541impl fidl::endpoints::Responder for DeviceSetupSetChannelResponder {
1542    type ControlHandle = DeviceSetupControlHandle;
1543
1544    fn control_handle(&self) -> &DeviceSetupControlHandle {
1545        &self.control_handle
1546    }
1547
1548    fn drop_without_shutdown(mut self) {
1549        // Safety: drops once, never accessed again due to mem::forget
1550        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1551        // Prevent Drop from running (which would shut down the channel)
1552        std::mem::forget(self);
1553    }
1554}
1555
1556impl DeviceSetupSetChannelResponder {
1557    /// Sends a response to the FIDL transaction.
1558    ///
1559    /// Sets the channel to shutdown if an error occurs.
1560    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1561        let _result = self.send_raw(result);
1562        if _result.is_err() {
1563            self.control_handle.shutdown();
1564        }
1565        self.drop_without_shutdown();
1566        _result
1567    }
1568
1569    /// Similar to "send" but does not shutdown the channel if an error occurs.
1570    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1571        let _result = self.send_raw(result);
1572        self.drop_without_shutdown();
1573        _result
1574    }
1575
1576    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1577        self.control_handle
1578            .inner
1579            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1580                result,
1581                self.tx_id,
1582                0x7f8e02c174ef02a5,
1583                fidl::encoding::DynamicFlags::empty(),
1584            )
1585    }
1586}
1587
1588#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1589pub struct ServiceMarker;
1590
1591#[cfg(target_os = "fuchsia")]
1592impl fidl::endpoints::ServiceMarker for ServiceMarker {
1593    type Proxy = ServiceProxy;
1594    type Request = ServiceRequest;
1595    const SERVICE_NAME: &'static str = "fuchsia.lowpan.spinel.Service";
1596}
1597
1598/// A request for one of the member protocols of Service.
1599///
1600#[cfg(target_os = "fuchsia")]
1601pub enum ServiceRequest {
1602    DeviceSetup(DeviceSetupRequestStream),
1603}
1604
1605#[cfg(target_os = "fuchsia")]
1606impl fidl::endpoints::ServiceRequest for ServiceRequest {
1607    type Service = ServiceMarker;
1608
1609    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1610        match name {
1611            "device_setup" => Self::DeviceSetup(
1612                <DeviceSetupRequestStream as fidl::endpoints::RequestStream>::from_channel(
1613                    _channel,
1614                ),
1615            ),
1616            _ => panic!("no such member protocol name for service Service"),
1617        }
1618    }
1619
1620    fn member_names() -> &'static [&'static str] {
1621        &["device_setup"]
1622    }
1623}
1624#[cfg(target_os = "fuchsia")]
1625pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1626
1627#[cfg(target_os = "fuchsia")]
1628impl fidl::endpoints::ServiceProxy for ServiceProxy {
1629    type Service = ServiceMarker;
1630
1631    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1632        Self(opener)
1633    }
1634}
1635
1636#[cfg(target_os = "fuchsia")]
1637impl ServiceProxy {
1638    pub fn connect_to_device_setup(&self) -> Result<DeviceSetupProxy, fidl::Error> {
1639        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceSetupMarker>();
1640        self.connect_channel_to_device_setup(server_end)?;
1641        Ok(proxy)
1642    }
1643
1644    /// Like `connect_to_device_setup`, but returns a sync proxy.
1645    /// See [`Self::connect_to_device_setup`] for more details.
1646    pub fn connect_to_device_setup_sync(&self) -> Result<DeviceSetupSynchronousProxy, fidl::Error> {
1647        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceSetupMarker>();
1648        self.connect_channel_to_device_setup(server_end)?;
1649        Ok(proxy)
1650    }
1651
1652    /// Like `connect_to_device_setup`, but accepts a server end.
1653    /// See [`Self::connect_to_device_setup`] for more details.
1654    pub fn connect_channel_to_device_setup(
1655        &self,
1656        server_end: fidl::endpoints::ServerEnd<DeviceSetupMarker>,
1657    ) -> Result<(), fidl::Error> {
1658        self.0.open_member("device_setup", server_end.into_channel())
1659    }
1660
1661    pub fn instance_name(&self) -> &str {
1662        self.0.instance_name()
1663    }
1664}
1665
1666mod internal {
1667    use super::*;
1668
1669    impl fidl::encoding::ResourceTypeMarker for DeviceSetupSetChannelRequest {
1670        type Borrowed<'a> = &'a mut Self;
1671        fn take_or_borrow<'a>(
1672            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1673        ) -> Self::Borrowed<'a> {
1674            value
1675        }
1676    }
1677
1678    unsafe impl fidl::encoding::TypeMarker for DeviceSetupSetChannelRequest {
1679        type Owned = Self;
1680
1681        #[inline(always)]
1682        fn inline_align(_context: fidl::encoding::Context) -> usize {
1683            4
1684        }
1685
1686        #[inline(always)]
1687        fn inline_size(_context: fidl::encoding::Context) -> usize {
1688            4
1689        }
1690    }
1691
1692    unsafe impl
1693        fidl::encoding::Encode<
1694            DeviceSetupSetChannelRequest,
1695            fidl::encoding::DefaultFuchsiaResourceDialect,
1696        > for &mut DeviceSetupSetChannelRequest
1697    {
1698        #[inline]
1699        unsafe fn encode(
1700            self,
1701            encoder: &mut fidl::encoding::Encoder<
1702                '_,
1703                fidl::encoding::DefaultFuchsiaResourceDialect,
1704            >,
1705            offset: usize,
1706            _depth: fidl::encoding::Depth,
1707        ) -> fidl::Result<()> {
1708            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1709            // Delegate to tuple encoding.
1710            fidl::encoding::Encode::<DeviceSetupSetChannelRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1711                (
1712                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.req),
1713                ),
1714                encoder, offset, _depth
1715            )
1716        }
1717    }
1718    unsafe impl<
1719        T0: fidl::encoding::Encode<
1720                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1721                fidl::encoding::DefaultFuchsiaResourceDialect,
1722            >,
1723    >
1724        fidl::encoding::Encode<
1725            DeviceSetupSetChannelRequest,
1726            fidl::encoding::DefaultFuchsiaResourceDialect,
1727        > for (T0,)
1728    {
1729        #[inline]
1730        unsafe fn encode(
1731            self,
1732            encoder: &mut fidl::encoding::Encoder<
1733                '_,
1734                fidl::encoding::DefaultFuchsiaResourceDialect,
1735            >,
1736            offset: usize,
1737            depth: fidl::encoding::Depth,
1738        ) -> fidl::Result<()> {
1739            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1740            // Zero out padding regions. There's no need to apply masks
1741            // because the unmasked parts will be overwritten by fields.
1742            // Write the fields.
1743            self.0.encode(encoder, offset + 0, depth)?;
1744            Ok(())
1745        }
1746    }
1747
1748    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1749        for DeviceSetupSetChannelRequest
1750    {
1751        #[inline(always)]
1752        fn new_empty() -> Self {
1753            Self {
1754                req: fidl::new_empty!(
1755                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1756                    fidl::encoding::DefaultFuchsiaResourceDialect
1757                ),
1758            }
1759        }
1760
1761        #[inline]
1762        unsafe fn decode(
1763            &mut self,
1764            decoder: &mut fidl::encoding::Decoder<
1765                '_,
1766                fidl::encoding::DefaultFuchsiaResourceDialect,
1767            >,
1768            offset: usize,
1769            _depth: fidl::encoding::Depth,
1770        ) -> fidl::Result<()> {
1771            decoder.debug_check_bounds::<Self>(offset);
1772            // Verify that padding bytes are zero.
1773            fidl::decode!(
1774                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1775                fidl::encoding::DefaultFuchsiaResourceDialect,
1776                &mut self.req,
1777                decoder,
1778                offset + 0,
1779                _depth
1780            )?;
1781            Ok(())
1782        }
1783    }
1784}