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::NullableHandle {
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
880    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
881        self.inner.shutdown_with_epitaph(status)
882    }
883
884    fn is_closed(&self) -> bool {
885        self.inner.channel().is_closed()
886    }
887    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
888        self.inner.channel().on_closed()
889    }
890
891    #[cfg(target_os = "fuchsia")]
892    fn signal_peer(
893        &self,
894        clear_mask: zx::Signals,
895        set_mask: zx::Signals,
896    ) -> Result<(), zx_status::Status> {
897        use fidl::Peered;
898        self.inner.channel().signal_peer(clear_mask, set_mask)
899    }
900}
901
902impl DeviceControlHandle {
903    pub fn send_on_ready_for_send_frames(
904        &self,
905        mut number_of_frames: u32,
906    ) -> Result<(), fidl::Error> {
907        self.inner.send::<DeviceOnReadyForSendFramesRequest>(
908            (number_of_frames,),
909            0,
910            0x2b1d5b28c5811b53,
911            fidl::encoding::DynamicFlags::empty(),
912        )
913    }
914
915    pub fn send_on_receive_frame(&self, mut data: &[u8]) -> Result<(), fidl::Error> {
916        self.inner.send::<DeviceOnReceiveFrameRequest>(
917            (data,),
918            0,
919            0x61937a45670aabb0,
920            fidl::encoding::DynamicFlags::empty(),
921        )
922    }
923
924    pub fn send_on_error(&self, mut error: Error, mut did_close: bool) -> Result<(), fidl::Error> {
925        self.inner.send::<DeviceOnErrorRequest>(
926            (error, did_close),
927            0,
928            0x4d20e65a9d2625e1,
929            fidl::encoding::DynamicFlags::empty(),
930        )
931    }
932}
933
934#[must_use = "FIDL methods require a response to be sent"]
935#[derive(Debug)]
936pub struct DeviceOpenResponder {
937    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
938    tx_id: u32,
939}
940
941/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
942/// if the responder is dropped without sending a response, so that the client
943/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
944impl std::ops::Drop for DeviceOpenResponder {
945    fn drop(&mut self) {
946        self.control_handle.shutdown();
947        // Safety: drops once, never accessed again
948        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
949    }
950}
951
952impl fidl::endpoints::Responder for DeviceOpenResponder {
953    type ControlHandle = DeviceControlHandle;
954
955    fn control_handle(&self) -> &DeviceControlHandle {
956        &self.control_handle
957    }
958
959    fn drop_without_shutdown(mut self) {
960        // Safety: drops once, never accessed again due to mem::forget
961        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
962        // Prevent Drop from running (which would shut down the channel)
963        std::mem::forget(self);
964    }
965}
966
967impl DeviceOpenResponder {
968    /// Sends a response to the FIDL transaction.
969    ///
970    /// Sets the channel to shutdown if an error occurs.
971    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
972        let _result = self.send_raw(result);
973        if _result.is_err() {
974            self.control_handle.shutdown();
975        }
976        self.drop_without_shutdown();
977        _result
978    }
979
980    /// Similar to "send" but does not shutdown the channel if an error occurs.
981    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
982        let _result = self.send_raw(result);
983        self.drop_without_shutdown();
984        _result
985    }
986
987    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
988        self.control_handle
989            .inner
990            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
991                result,
992                self.tx_id,
993                0x508cecb73a776ef7,
994                fidl::encoding::DynamicFlags::empty(),
995            )
996    }
997}
998
999#[must_use = "FIDL methods require a response to be sent"]
1000#[derive(Debug)]
1001pub struct DeviceCloseResponder {
1002    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1003    tx_id: u32,
1004}
1005
1006/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1007/// if the responder is dropped without sending a response, so that the client
1008/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1009impl std::ops::Drop for DeviceCloseResponder {
1010    fn drop(&mut self) {
1011        self.control_handle.shutdown();
1012        // Safety: drops once, never accessed again
1013        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1014    }
1015}
1016
1017impl fidl::endpoints::Responder for DeviceCloseResponder {
1018    type ControlHandle = DeviceControlHandle;
1019
1020    fn control_handle(&self) -> &DeviceControlHandle {
1021        &self.control_handle
1022    }
1023
1024    fn drop_without_shutdown(mut self) {
1025        // Safety: drops once, never accessed again due to mem::forget
1026        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1027        // Prevent Drop from running (which would shut down the channel)
1028        std::mem::forget(self);
1029    }
1030}
1031
1032impl DeviceCloseResponder {
1033    /// Sends a response to the FIDL transaction.
1034    ///
1035    /// Sets the channel to shutdown if an error occurs.
1036    pub fn send(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1037        let _result = self.send_raw(result);
1038        if _result.is_err() {
1039            self.control_handle.shutdown();
1040        }
1041        self.drop_without_shutdown();
1042        _result
1043    }
1044
1045    /// Similar to "send" but does not shutdown the channel if an error occurs.
1046    pub fn send_no_shutdown_on_err(self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1047        let _result = self.send_raw(result);
1048        self.drop_without_shutdown();
1049        _result
1050    }
1051
1052    fn send_raw(&self, mut result: Result<(), Error>) -> Result<(), fidl::Error> {
1053        self.control_handle
1054            .inner
1055            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, Error>>(
1056                result,
1057                self.tx_id,
1058                0x621a0f31b867781a,
1059                fidl::encoding::DynamicFlags::empty(),
1060            )
1061    }
1062}
1063
1064#[must_use = "FIDL methods require a response to be sent"]
1065#[derive(Debug)]
1066pub struct DeviceGetMaxFrameSizeResponder {
1067    control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
1068    tx_id: u32,
1069}
1070
1071/// Set the the channel to be shutdown (see [`DeviceControlHandle::shutdown`])
1072/// if the responder is dropped without sending a response, so that the client
1073/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1074impl std::ops::Drop for DeviceGetMaxFrameSizeResponder {
1075    fn drop(&mut self) {
1076        self.control_handle.shutdown();
1077        // Safety: drops once, never accessed again
1078        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1079    }
1080}
1081
1082impl fidl::endpoints::Responder for DeviceGetMaxFrameSizeResponder {
1083    type ControlHandle = DeviceControlHandle;
1084
1085    fn control_handle(&self) -> &DeviceControlHandle {
1086        &self.control_handle
1087    }
1088
1089    fn drop_without_shutdown(mut self) {
1090        // Safety: drops once, never accessed again due to mem::forget
1091        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1092        // Prevent Drop from running (which would shut down the channel)
1093        std::mem::forget(self);
1094    }
1095}
1096
1097impl DeviceGetMaxFrameSizeResponder {
1098    /// Sends a response to the FIDL transaction.
1099    ///
1100    /// Sets the channel to shutdown if an error occurs.
1101    pub fn send(self, mut size: u32) -> Result<(), fidl::Error> {
1102        let _result = self.send_raw(size);
1103        if _result.is_err() {
1104            self.control_handle.shutdown();
1105        }
1106        self.drop_without_shutdown();
1107        _result
1108    }
1109
1110    /// Similar to "send" but does not shutdown the channel if an error occurs.
1111    pub fn send_no_shutdown_on_err(self, mut size: u32) -> Result<(), fidl::Error> {
1112        let _result = self.send_raw(size);
1113        self.drop_without_shutdown();
1114        _result
1115    }
1116
1117    fn send_raw(&self, mut size: u32) -> Result<(), fidl::Error> {
1118        self.control_handle.inner.send::<DeviceGetMaxFrameSizeResponse>(
1119            (size,),
1120            self.tx_id,
1121            0x1d2d652e8b06d463,
1122            fidl::encoding::DynamicFlags::empty(),
1123        )
1124    }
1125}
1126
1127#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1128pub struct DeviceSetupMarker;
1129
1130impl fidl::endpoints::ProtocolMarker for DeviceSetupMarker {
1131    type Proxy = DeviceSetupProxy;
1132    type RequestStream = DeviceSetupRequestStream;
1133    #[cfg(target_os = "fuchsia")]
1134    type SynchronousProxy = DeviceSetupSynchronousProxy;
1135
1136    const DEBUG_NAME: &'static str = "(anonymous) DeviceSetup";
1137}
1138pub type DeviceSetupSetChannelResult = Result<(), i32>;
1139
1140pub trait DeviceSetupProxyInterface: Send + Sync {
1141    type SetChannelResponseFut: std::future::Future<Output = Result<DeviceSetupSetChannelResult, fidl::Error>>
1142        + Send;
1143    fn r#set_channel(
1144        &self,
1145        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1146    ) -> Self::SetChannelResponseFut;
1147}
1148#[derive(Debug)]
1149#[cfg(target_os = "fuchsia")]
1150pub struct DeviceSetupSynchronousProxy {
1151    client: fidl::client::sync::Client,
1152}
1153
1154#[cfg(target_os = "fuchsia")]
1155impl fidl::endpoints::SynchronousProxy for DeviceSetupSynchronousProxy {
1156    type Proxy = DeviceSetupProxy;
1157    type Protocol = DeviceSetupMarker;
1158
1159    fn from_channel(inner: fidl::Channel) -> Self {
1160        Self::new(inner)
1161    }
1162
1163    fn into_channel(self) -> fidl::Channel {
1164        self.client.into_channel()
1165    }
1166
1167    fn as_channel(&self) -> &fidl::Channel {
1168        self.client.as_channel()
1169    }
1170}
1171
1172#[cfg(target_os = "fuchsia")]
1173impl DeviceSetupSynchronousProxy {
1174    pub fn new(channel: fidl::Channel) -> Self {
1175        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1176        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1177    }
1178
1179    pub fn into_channel(self) -> fidl::Channel {
1180        self.client.into_channel()
1181    }
1182
1183    /// Waits until an event arrives and returns it. It is safe for other
1184    /// threads to make concurrent requests while waiting for an event.
1185    pub fn wait_for_event(
1186        &self,
1187        deadline: zx::MonotonicInstant,
1188    ) -> Result<DeviceSetupEvent, fidl::Error> {
1189        DeviceSetupEvent::decode(self.client.wait_for_event(deadline)?)
1190    }
1191
1192    pub fn r#set_channel(
1193        &self,
1194        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1195        ___deadline: zx::MonotonicInstant,
1196    ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1197        let _response = self.client.send_query::<
1198            DeviceSetupSetChannelRequest,
1199            fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1200        >(
1201            (req,),
1202            0x7f8e02c174ef02a5,
1203            fidl::encoding::DynamicFlags::empty(),
1204            ___deadline,
1205        )?;
1206        Ok(_response.map(|x| x))
1207    }
1208}
1209
1210#[cfg(target_os = "fuchsia")]
1211impl From<DeviceSetupSynchronousProxy> for zx::NullableHandle {
1212    fn from(value: DeviceSetupSynchronousProxy) -> Self {
1213        value.into_channel().into()
1214    }
1215}
1216
1217#[cfg(target_os = "fuchsia")]
1218impl From<fidl::Channel> for DeviceSetupSynchronousProxy {
1219    fn from(value: fidl::Channel) -> Self {
1220        Self::new(value)
1221    }
1222}
1223
1224#[cfg(target_os = "fuchsia")]
1225impl fidl::endpoints::FromClient for DeviceSetupSynchronousProxy {
1226    type Protocol = DeviceSetupMarker;
1227
1228    fn from_client(value: fidl::endpoints::ClientEnd<DeviceSetupMarker>) -> Self {
1229        Self::new(value.into_channel())
1230    }
1231}
1232
1233#[derive(Debug, Clone)]
1234pub struct DeviceSetupProxy {
1235    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1236}
1237
1238impl fidl::endpoints::Proxy for DeviceSetupProxy {
1239    type Protocol = DeviceSetupMarker;
1240
1241    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1242        Self::new(inner)
1243    }
1244
1245    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1246        self.client.into_channel().map_err(|client| Self { client })
1247    }
1248
1249    fn as_channel(&self) -> &::fidl::AsyncChannel {
1250        self.client.as_channel()
1251    }
1252}
1253
1254impl DeviceSetupProxy {
1255    /// Create a new Proxy for fuchsia.lowpan.spinel/DeviceSetup.
1256    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1257        let protocol_name = <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1258        Self { client: fidl::client::Client::new(channel, protocol_name) }
1259    }
1260
1261    /// Get a Stream of events from the remote end of the protocol.
1262    ///
1263    /// # Panics
1264    ///
1265    /// Panics if the event stream was already taken.
1266    pub fn take_event_stream(&self) -> DeviceSetupEventStream {
1267        DeviceSetupEventStream { event_receiver: self.client.take_event_receiver() }
1268    }
1269
1270    pub fn r#set_channel(
1271        &self,
1272        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1273    ) -> fidl::client::QueryResponseFut<
1274        DeviceSetupSetChannelResult,
1275        fidl::encoding::DefaultFuchsiaResourceDialect,
1276    > {
1277        DeviceSetupProxyInterface::r#set_channel(self, req)
1278    }
1279}
1280
1281impl DeviceSetupProxyInterface for DeviceSetupProxy {
1282    type SetChannelResponseFut = fidl::client::QueryResponseFut<
1283        DeviceSetupSetChannelResult,
1284        fidl::encoding::DefaultFuchsiaResourceDialect,
1285    >;
1286    fn r#set_channel(
1287        &self,
1288        mut req: fidl::endpoints::ServerEnd<DeviceMarker>,
1289    ) -> Self::SetChannelResponseFut {
1290        fn _decode(
1291            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1292        ) -> Result<DeviceSetupSetChannelResult, fidl::Error> {
1293            let _response = fidl::client::decode_transaction_body::<
1294                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>,
1295                fidl::encoding::DefaultFuchsiaResourceDialect,
1296                0x7f8e02c174ef02a5,
1297            >(_buf?)?;
1298            Ok(_response.map(|x| x))
1299        }
1300        self.client
1301            .send_query_and_decode::<DeviceSetupSetChannelRequest, DeviceSetupSetChannelResult>(
1302                (req,),
1303                0x7f8e02c174ef02a5,
1304                fidl::encoding::DynamicFlags::empty(),
1305                _decode,
1306            )
1307    }
1308}
1309
1310pub struct DeviceSetupEventStream {
1311    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1312}
1313
1314impl std::marker::Unpin for DeviceSetupEventStream {}
1315
1316impl futures::stream::FusedStream for DeviceSetupEventStream {
1317    fn is_terminated(&self) -> bool {
1318        self.event_receiver.is_terminated()
1319    }
1320}
1321
1322impl futures::Stream for DeviceSetupEventStream {
1323    type Item = Result<DeviceSetupEvent, fidl::Error>;
1324
1325    fn poll_next(
1326        mut self: std::pin::Pin<&mut Self>,
1327        cx: &mut std::task::Context<'_>,
1328    ) -> std::task::Poll<Option<Self::Item>> {
1329        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1330            &mut self.event_receiver,
1331            cx
1332        )?) {
1333            Some(buf) => std::task::Poll::Ready(Some(DeviceSetupEvent::decode(buf))),
1334            None => std::task::Poll::Ready(None),
1335        }
1336    }
1337}
1338
1339#[derive(Debug)]
1340pub enum DeviceSetupEvent {}
1341
1342impl DeviceSetupEvent {
1343    /// Decodes a message buffer as a [`DeviceSetupEvent`].
1344    fn decode(
1345        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1346    ) -> Result<DeviceSetupEvent, fidl::Error> {
1347        let (bytes, _handles) = buf.split_mut();
1348        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1349        debug_assert_eq!(tx_header.tx_id, 0);
1350        match tx_header.ordinal {
1351            _ => Err(fidl::Error::UnknownOrdinal {
1352                ordinal: tx_header.ordinal,
1353                protocol_name: <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1354            }),
1355        }
1356    }
1357}
1358
1359/// A Stream of incoming requests for fuchsia.lowpan.spinel/DeviceSetup.
1360pub struct DeviceSetupRequestStream {
1361    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1362    is_terminated: bool,
1363}
1364
1365impl std::marker::Unpin for DeviceSetupRequestStream {}
1366
1367impl futures::stream::FusedStream for DeviceSetupRequestStream {
1368    fn is_terminated(&self) -> bool {
1369        self.is_terminated
1370    }
1371}
1372
1373impl fidl::endpoints::RequestStream for DeviceSetupRequestStream {
1374    type Protocol = DeviceSetupMarker;
1375    type ControlHandle = DeviceSetupControlHandle;
1376
1377    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1378        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1379    }
1380
1381    fn control_handle(&self) -> Self::ControlHandle {
1382        DeviceSetupControlHandle { inner: self.inner.clone() }
1383    }
1384
1385    fn into_inner(
1386        self,
1387    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1388    {
1389        (self.inner, self.is_terminated)
1390    }
1391
1392    fn from_inner(
1393        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1394        is_terminated: bool,
1395    ) -> Self {
1396        Self { inner, is_terminated }
1397    }
1398}
1399
1400impl futures::Stream for DeviceSetupRequestStream {
1401    type Item = Result<DeviceSetupRequest, fidl::Error>;
1402
1403    fn poll_next(
1404        mut self: std::pin::Pin<&mut Self>,
1405        cx: &mut std::task::Context<'_>,
1406    ) -> std::task::Poll<Option<Self::Item>> {
1407        let this = &mut *self;
1408        if this.inner.check_shutdown(cx) {
1409            this.is_terminated = true;
1410            return std::task::Poll::Ready(None);
1411        }
1412        if this.is_terminated {
1413            panic!("polled DeviceSetupRequestStream after completion");
1414        }
1415        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1416            |bytes, handles| {
1417                match this.inner.channel().read_etc(cx, bytes, handles) {
1418                    std::task::Poll::Ready(Ok(())) => {}
1419                    std::task::Poll::Pending => return std::task::Poll::Pending,
1420                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1421                        this.is_terminated = true;
1422                        return std::task::Poll::Ready(None);
1423                    }
1424                    std::task::Poll::Ready(Err(e)) => {
1425                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1426                            e.into(),
1427                        ))));
1428                    }
1429                }
1430
1431                // A message has been received from the channel
1432                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1433
1434                std::task::Poll::Ready(Some(match header.ordinal {
1435                    0x7f8e02c174ef02a5 => {
1436                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1437                        let mut req = fidl::new_empty!(
1438                            DeviceSetupSetChannelRequest,
1439                            fidl::encoding::DefaultFuchsiaResourceDialect
1440                        );
1441                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DeviceSetupSetChannelRequest>(&header, _body_bytes, handles, &mut req)?;
1442                        let control_handle = DeviceSetupControlHandle { inner: this.inner.clone() };
1443                        Ok(DeviceSetupRequest::SetChannel {
1444                            req: req.req,
1445
1446                            responder: DeviceSetupSetChannelResponder {
1447                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1448                                tx_id: header.tx_id,
1449                            },
1450                        })
1451                    }
1452                    _ => Err(fidl::Error::UnknownOrdinal {
1453                        ordinal: header.ordinal,
1454                        protocol_name:
1455                            <DeviceSetupMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1456                    }),
1457                }))
1458            },
1459        )
1460    }
1461}
1462
1463#[derive(Debug)]
1464pub enum DeviceSetupRequest {
1465    SetChannel {
1466        req: fidl::endpoints::ServerEnd<DeviceMarker>,
1467        responder: DeviceSetupSetChannelResponder,
1468    },
1469}
1470
1471impl DeviceSetupRequest {
1472    #[allow(irrefutable_let_patterns)]
1473    pub fn into_set_channel(
1474        self,
1475    ) -> Option<(fidl::endpoints::ServerEnd<DeviceMarker>, DeviceSetupSetChannelResponder)> {
1476        if let DeviceSetupRequest::SetChannel { req, responder } = self {
1477            Some((req, responder))
1478        } else {
1479            None
1480        }
1481    }
1482
1483    /// Name of the method defined in FIDL
1484    pub fn method_name(&self) -> &'static str {
1485        match *self {
1486            DeviceSetupRequest::SetChannel { .. } => "set_channel",
1487        }
1488    }
1489}
1490
1491#[derive(Debug, Clone)]
1492pub struct DeviceSetupControlHandle {
1493    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1494}
1495
1496impl fidl::endpoints::ControlHandle for DeviceSetupControlHandle {
1497    fn shutdown(&self) {
1498        self.inner.shutdown()
1499    }
1500
1501    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1502        self.inner.shutdown_with_epitaph(status)
1503    }
1504
1505    fn is_closed(&self) -> bool {
1506        self.inner.channel().is_closed()
1507    }
1508    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1509        self.inner.channel().on_closed()
1510    }
1511
1512    #[cfg(target_os = "fuchsia")]
1513    fn signal_peer(
1514        &self,
1515        clear_mask: zx::Signals,
1516        set_mask: zx::Signals,
1517    ) -> Result<(), zx_status::Status> {
1518        use fidl::Peered;
1519        self.inner.channel().signal_peer(clear_mask, set_mask)
1520    }
1521}
1522
1523impl DeviceSetupControlHandle {}
1524
1525#[must_use = "FIDL methods require a response to be sent"]
1526#[derive(Debug)]
1527pub struct DeviceSetupSetChannelResponder {
1528    control_handle: std::mem::ManuallyDrop<DeviceSetupControlHandle>,
1529    tx_id: u32,
1530}
1531
1532/// Set the the channel to be shutdown (see [`DeviceSetupControlHandle::shutdown`])
1533/// if the responder is dropped without sending a response, so that the client
1534/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1535impl std::ops::Drop for DeviceSetupSetChannelResponder {
1536    fn drop(&mut self) {
1537        self.control_handle.shutdown();
1538        // Safety: drops once, never accessed again
1539        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1540    }
1541}
1542
1543impl fidl::endpoints::Responder for DeviceSetupSetChannelResponder {
1544    type ControlHandle = DeviceSetupControlHandle;
1545
1546    fn control_handle(&self) -> &DeviceSetupControlHandle {
1547        &self.control_handle
1548    }
1549
1550    fn drop_without_shutdown(mut self) {
1551        // Safety: drops once, never accessed again due to mem::forget
1552        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1553        // Prevent Drop from running (which would shut down the channel)
1554        std::mem::forget(self);
1555    }
1556}
1557
1558impl DeviceSetupSetChannelResponder {
1559    /// Sends a response to the FIDL transaction.
1560    ///
1561    /// Sets the channel to shutdown if an error occurs.
1562    pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1563        let _result = self.send_raw(result);
1564        if _result.is_err() {
1565            self.control_handle.shutdown();
1566        }
1567        self.drop_without_shutdown();
1568        _result
1569    }
1570
1571    /// Similar to "send" but does not shutdown the channel if an error occurs.
1572    pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1573        let _result = self.send_raw(result);
1574        self.drop_without_shutdown();
1575        _result
1576    }
1577
1578    fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
1579        self.control_handle
1580            .inner
1581            .send::<fidl::encoding::ResultType<fidl::encoding::EmptyStruct, i32>>(
1582                result,
1583                self.tx_id,
1584                0x7f8e02c174ef02a5,
1585                fidl::encoding::DynamicFlags::empty(),
1586            )
1587    }
1588}
1589
1590#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1591pub struct ServiceMarker;
1592
1593#[cfg(target_os = "fuchsia")]
1594impl fidl::endpoints::ServiceMarker for ServiceMarker {
1595    type Proxy = ServiceProxy;
1596    type Request = ServiceRequest;
1597    const SERVICE_NAME: &'static str = "fuchsia.lowpan.spinel.Service";
1598}
1599
1600/// A request for one of the member protocols of Service.
1601///
1602#[cfg(target_os = "fuchsia")]
1603pub enum ServiceRequest {
1604    DeviceSetup(DeviceSetupRequestStream),
1605}
1606
1607#[cfg(target_os = "fuchsia")]
1608impl fidl::endpoints::ServiceRequest for ServiceRequest {
1609    type Service = ServiceMarker;
1610
1611    fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1612        match name {
1613            "device_setup" => Self::DeviceSetup(
1614                <DeviceSetupRequestStream as fidl::endpoints::RequestStream>::from_channel(
1615                    _channel,
1616                ),
1617            ),
1618            _ => panic!("no such member protocol name for service Service"),
1619        }
1620    }
1621
1622    fn member_names() -> &'static [&'static str] {
1623        &["device_setup"]
1624    }
1625}
1626#[cfg(target_os = "fuchsia")]
1627pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1628
1629#[cfg(target_os = "fuchsia")]
1630impl fidl::endpoints::ServiceProxy for ServiceProxy {
1631    type Service = ServiceMarker;
1632
1633    fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1634        Self(opener)
1635    }
1636}
1637
1638#[cfg(target_os = "fuchsia")]
1639impl ServiceProxy {
1640    pub fn connect_to_device_setup(&self) -> Result<DeviceSetupProxy, fidl::Error> {
1641        let (proxy, server_end) = fidl::endpoints::create_proxy::<DeviceSetupMarker>();
1642        self.connect_channel_to_device_setup(server_end)?;
1643        Ok(proxy)
1644    }
1645
1646    /// Like `connect_to_device_setup`, but returns a sync proxy.
1647    /// See [`Self::connect_to_device_setup`] for more details.
1648    pub fn connect_to_device_setup_sync(&self) -> Result<DeviceSetupSynchronousProxy, fidl::Error> {
1649        let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<DeviceSetupMarker>();
1650        self.connect_channel_to_device_setup(server_end)?;
1651        Ok(proxy)
1652    }
1653
1654    /// Like `connect_to_device_setup`, but accepts a server end.
1655    /// See [`Self::connect_to_device_setup`] for more details.
1656    pub fn connect_channel_to_device_setup(
1657        &self,
1658        server_end: fidl::endpoints::ServerEnd<DeviceSetupMarker>,
1659    ) -> Result<(), fidl::Error> {
1660        self.0.open_member("device_setup", server_end.into_channel())
1661    }
1662
1663    pub fn instance_name(&self) -> &str {
1664        self.0.instance_name()
1665    }
1666}
1667
1668mod internal {
1669    use super::*;
1670
1671    impl fidl::encoding::ResourceTypeMarker for DeviceSetupSetChannelRequest {
1672        type Borrowed<'a> = &'a mut Self;
1673        fn take_or_borrow<'a>(
1674            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1675        ) -> Self::Borrowed<'a> {
1676            value
1677        }
1678    }
1679
1680    unsafe impl fidl::encoding::TypeMarker for DeviceSetupSetChannelRequest {
1681        type Owned = Self;
1682
1683        #[inline(always)]
1684        fn inline_align(_context: fidl::encoding::Context) -> usize {
1685            4
1686        }
1687
1688        #[inline(always)]
1689        fn inline_size(_context: fidl::encoding::Context) -> usize {
1690            4
1691        }
1692    }
1693
1694    unsafe impl
1695        fidl::encoding::Encode<
1696            DeviceSetupSetChannelRequest,
1697            fidl::encoding::DefaultFuchsiaResourceDialect,
1698        > for &mut DeviceSetupSetChannelRequest
1699    {
1700        #[inline]
1701        unsafe fn encode(
1702            self,
1703            encoder: &mut fidl::encoding::Encoder<
1704                '_,
1705                fidl::encoding::DefaultFuchsiaResourceDialect,
1706            >,
1707            offset: usize,
1708            _depth: fidl::encoding::Depth,
1709        ) -> fidl::Result<()> {
1710            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1711            // Delegate to tuple encoding.
1712            fidl::encoding::Encode::<DeviceSetupSetChannelRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1713                (
1714                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.req),
1715                ),
1716                encoder, offset, _depth
1717            )
1718        }
1719    }
1720    unsafe impl<
1721        T0: fidl::encoding::Encode<
1722                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1723                fidl::encoding::DefaultFuchsiaResourceDialect,
1724            >,
1725    >
1726        fidl::encoding::Encode<
1727            DeviceSetupSetChannelRequest,
1728            fidl::encoding::DefaultFuchsiaResourceDialect,
1729        > for (T0,)
1730    {
1731        #[inline]
1732        unsafe fn encode(
1733            self,
1734            encoder: &mut fidl::encoding::Encoder<
1735                '_,
1736                fidl::encoding::DefaultFuchsiaResourceDialect,
1737            >,
1738            offset: usize,
1739            depth: fidl::encoding::Depth,
1740        ) -> fidl::Result<()> {
1741            encoder.debug_check_bounds::<DeviceSetupSetChannelRequest>(offset);
1742            // Zero out padding regions. There's no need to apply masks
1743            // because the unmasked parts will be overwritten by fields.
1744            // Write the fields.
1745            self.0.encode(encoder, offset + 0, depth)?;
1746            Ok(())
1747        }
1748    }
1749
1750    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1751        for DeviceSetupSetChannelRequest
1752    {
1753        #[inline(always)]
1754        fn new_empty() -> Self {
1755            Self {
1756                req: fidl::new_empty!(
1757                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1758                    fidl::encoding::DefaultFuchsiaResourceDialect
1759                ),
1760            }
1761        }
1762
1763        #[inline]
1764        unsafe fn decode(
1765            &mut self,
1766            decoder: &mut fidl::encoding::Decoder<
1767                '_,
1768                fidl::encoding::DefaultFuchsiaResourceDialect,
1769            >,
1770            offset: usize,
1771            _depth: fidl::encoding::Depth,
1772        ) -> fidl::Result<()> {
1773            decoder.debug_check_bounds::<Self>(offset);
1774            // Verify that padding bytes are zero.
1775            fidl::decode!(
1776                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<DeviceMarker>>,
1777                fidl::encoding::DefaultFuchsiaResourceDialect,
1778                &mut self.req,
1779                decoder,
1780                offset + 0,
1781                _depth
1782            )?;
1783            Ok(())
1784        }
1785    }
1786}