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