fidl_fuchsia_bluetooth/
fidl_fuchsia_bluetooth.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_bluetooth__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ChannelMarker;
16
17impl fidl::endpoints::ProtocolMarker for ChannelMarker {
18    type Proxy = ChannelProxy;
19    type RequestStream = ChannelRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = ChannelSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "(anonymous) Channel";
24}
25
26pub trait ChannelProxyInterface: Send + Sync {
27    type Send_ResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
28    fn r#send_(&self, packets: &[Packet]) -> Self::Send_ResponseFut;
29    type ReceiveResponseFut: std::future::Future<Output = Result<Vec<Packet>, fidl::Error>> + Send;
30    fn r#receive(&self) -> Self::ReceiveResponseFut;
31    type WatchChannelParametersResponseFut: std::future::Future<Output = Result<ChannelParameters, fidl::Error>>
32        + Send;
33    fn r#watch_channel_parameters(&self) -> Self::WatchChannelParametersResponseFut;
34}
35#[derive(Debug)]
36#[cfg(target_os = "fuchsia")]
37pub struct ChannelSynchronousProxy {
38    client: fidl::client::sync::Client,
39}
40
41#[cfg(target_os = "fuchsia")]
42impl fidl::endpoints::SynchronousProxy for ChannelSynchronousProxy {
43    type Proxy = ChannelProxy;
44    type Protocol = ChannelMarker;
45
46    fn from_channel(inner: fidl::Channel) -> Self {
47        Self::new(inner)
48    }
49
50    fn into_channel(self) -> fidl::Channel {
51        self.client.into_channel()
52    }
53
54    fn as_channel(&self) -> &fidl::Channel {
55        self.client.as_channel()
56    }
57}
58
59#[cfg(target_os = "fuchsia")]
60impl ChannelSynchronousProxy {
61    pub fn new(channel: fidl::Channel) -> Self {
62        let protocol_name = <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
63        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
64    }
65
66    pub fn into_channel(self) -> fidl::Channel {
67        self.client.into_channel()
68    }
69
70    /// Waits until an event arrives and returns it. It is safe for other
71    /// threads to make concurrent requests while waiting for an event.
72    pub fn wait_for_event(
73        &self,
74        deadline: zx::MonotonicInstant,
75    ) -> Result<ChannelEvent, fidl::Error> {
76        ChannelEvent::decode(self.client.wait_for_event(deadline)?)
77    }
78
79    /// Send multiple packets of data over the channel. Only one `Send`
80    /// may be pending at a time.
81    pub fn r#send_(
82        &self,
83        mut packets: &[Packet],
84        ___deadline: zx::MonotonicInstant,
85    ) -> Result<(), fidl::Error> {
86        let _response = self.client.send_query::<
87            ChannelSendRequest,
88            fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
89        >(
90            (packets,),
91            0x6fc4419c2e763324,
92            fidl::encoding::DynamicFlags::FLEXIBLE,
93            ___deadline,
94        )?
95        .into_result::<ChannelMarker>("send_")?;
96        Ok(_response)
97    }
98
99    /// Hanging get that waits for inbound packets. Only one `Receive`
100    /// may be pending at a time.
101    pub fn r#receive(&self, ___deadline: zx::MonotonicInstant) -> Result<Vec<Packet>, fidl::Error> {
102        let _response = self.client.send_query::<
103            fidl::encoding::EmptyPayload,
104            fidl::encoding::FlexibleType<ChannelReceiveResponse>,
105        >(
106            (),
107            0x3498d7bdb7cdbfd4,
108            fidl::encoding::DynamicFlags::FLEXIBLE,
109            ___deadline,
110        )?
111        .into_result::<ChannelMarker>("receive")?;
112        Ok(_response.packets)
113    }
114
115    /// For RFCOMM channels, this will not return and calls will hang
116    /// indefinitely.
117    ///
118    /// For BR/EDR L2CAP connection-oriented channels this will currently not
119    /// return and calls will hang indefinitely. The initial channel parameters
120    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
121    ///
122    /// For LE L2CAP connection-oriented channels, the first call will
123    /// immediately return the parameters of the remote side of the channel.
124    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
125    /// which point it will return the new parameters, including those that have
126    /// not changed.
127    pub fn r#watch_channel_parameters(
128        &self,
129        ___deadline: zx::MonotonicInstant,
130    ) -> Result<ChannelParameters, fidl::Error> {
131        let _response = self.client.send_query::<
132            fidl::encoding::EmptyPayload,
133            fidl::encoding::FlexibleType<ChannelParameters>,
134        >(
135            (),
136            0x5a0cec81d5076c12,
137            fidl::encoding::DynamicFlags::FLEXIBLE,
138            ___deadline,
139        )?
140        .into_result::<ChannelMarker>("watch_channel_parameters")?;
141        Ok(_response)
142    }
143}
144
145#[cfg(target_os = "fuchsia")]
146impl From<ChannelSynchronousProxy> for zx::Handle {
147    fn from(value: ChannelSynchronousProxy) -> Self {
148        value.into_channel().into()
149    }
150}
151
152#[cfg(target_os = "fuchsia")]
153impl From<fidl::Channel> for ChannelSynchronousProxy {
154    fn from(value: fidl::Channel) -> Self {
155        Self::new(value)
156    }
157}
158
159#[cfg(target_os = "fuchsia")]
160impl fidl::endpoints::FromClient for ChannelSynchronousProxy {
161    type Protocol = ChannelMarker;
162
163    fn from_client(value: fidl::endpoints::ClientEnd<ChannelMarker>) -> Self {
164        Self::new(value.into_channel())
165    }
166}
167
168#[derive(Debug, Clone)]
169pub struct ChannelProxy {
170    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
171}
172
173impl fidl::endpoints::Proxy for ChannelProxy {
174    type Protocol = ChannelMarker;
175
176    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
177        Self::new(inner)
178    }
179
180    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
181        self.client.into_channel().map_err(|client| Self { client })
182    }
183
184    fn as_channel(&self) -> &::fidl::AsyncChannel {
185        self.client.as_channel()
186    }
187}
188
189impl ChannelProxy {
190    /// Create a new Proxy for fuchsia.bluetooth/Channel.
191    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
192        let protocol_name = <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
193        Self { client: fidl::client::Client::new(channel, protocol_name) }
194    }
195
196    /// Get a Stream of events from the remote end of the protocol.
197    ///
198    /// # Panics
199    ///
200    /// Panics if the event stream was already taken.
201    pub fn take_event_stream(&self) -> ChannelEventStream {
202        ChannelEventStream { event_receiver: self.client.take_event_receiver() }
203    }
204
205    /// Send multiple packets of data over the channel. Only one `Send`
206    /// may be pending at a time.
207    pub fn r#send_(
208        &self,
209        mut packets: &[Packet],
210    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
211        ChannelProxyInterface::r#send_(self, packets)
212    }
213
214    /// Hanging get that waits for inbound packets. Only one `Receive`
215    /// may be pending at a time.
216    pub fn r#receive(
217        &self,
218    ) -> fidl::client::QueryResponseFut<Vec<Packet>, fidl::encoding::DefaultFuchsiaResourceDialect>
219    {
220        ChannelProxyInterface::r#receive(self)
221    }
222
223    /// For RFCOMM channels, this will not return and calls will hang
224    /// indefinitely.
225    ///
226    /// For BR/EDR L2CAP connection-oriented channels this will currently not
227    /// return and calls will hang indefinitely. The initial channel parameters
228    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
229    ///
230    /// For LE L2CAP connection-oriented channels, the first call will
231    /// immediately return the parameters of the remote side of the channel.
232    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
233    /// which point it will return the new parameters, including those that have
234    /// not changed.
235    pub fn r#watch_channel_parameters(
236        &self,
237    ) -> fidl::client::QueryResponseFut<
238        ChannelParameters,
239        fidl::encoding::DefaultFuchsiaResourceDialect,
240    > {
241        ChannelProxyInterface::r#watch_channel_parameters(self)
242    }
243}
244
245impl ChannelProxyInterface for ChannelProxy {
246    type Send_ResponseFut =
247        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
248    fn r#send_(&self, mut packets: &[Packet]) -> Self::Send_ResponseFut {
249        fn _decode(
250            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
251        ) -> Result<(), fidl::Error> {
252            let _response = fidl::client::decode_transaction_body::<
253                fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>,
254                fidl::encoding::DefaultFuchsiaResourceDialect,
255                0x6fc4419c2e763324,
256            >(_buf?)?
257            .into_result::<ChannelMarker>("send_")?;
258            Ok(_response)
259        }
260        self.client.send_query_and_decode::<ChannelSendRequest, ()>(
261            (packets,),
262            0x6fc4419c2e763324,
263            fidl::encoding::DynamicFlags::FLEXIBLE,
264            _decode,
265        )
266    }
267
268    type ReceiveResponseFut =
269        fidl::client::QueryResponseFut<Vec<Packet>, fidl::encoding::DefaultFuchsiaResourceDialect>;
270    fn r#receive(&self) -> Self::ReceiveResponseFut {
271        fn _decode(
272            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
273        ) -> Result<Vec<Packet>, fidl::Error> {
274            let _response = fidl::client::decode_transaction_body::<
275                fidl::encoding::FlexibleType<ChannelReceiveResponse>,
276                fidl::encoding::DefaultFuchsiaResourceDialect,
277                0x3498d7bdb7cdbfd4,
278            >(_buf?)?
279            .into_result::<ChannelMarker>("receive")?;
280            Ok(_response.packets)
281        }
282        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, Vec<Packet>>(
283            (),
284            0x3498d7bdb7cdbfd4,
285            fidl::encoding::DynamicFlags::FLEXIBLE,
286            _decode,
287        )
288    }
289
290    type WatchChannelParametersResponseFut = fidl::client::QueryResponseFut<
291        ChannelParameters,
292        fidl::encoding::DefaultFuchsiaResourceDialect,
293    >;
294    fn r#watch_channel_parameters(&self) -> Self::WatchChannelParametersResponseFut {
295        fn _decode(
296            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
297        ) -> Result<ChannelParameters, fidl::Error> {
298            let _response = fidl::client::decode_transaction_body::<
299                fidl::encoding::FlexibleType<ChannelParameters>,
300                fidl::encoding::DefaultFuchsiaResourceDialect,
301                0x5a0cec81d5076c12,
302            >(_buf?)?
303            .into_result::<ChannelMarker>("watch_channel_parameters")?;
304            Ok(_response)
305        }
306        self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ChannelParameters>(
307            (),
308            0x5a0cec81d5076c12,
309            fidl::encoding::DynamicFlags::FLEXIBLE,
310            _decode,
311        )
312    }
313}
314
315pub struct ChannelEventStream {
316    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
317}
318
319impl std::marker::Unpin for ChannelEventStream {}
320
321impl futures::stream::FusedStream for ChannelEventStream {
322    fn is_terminated(&self) -> bool {
323        self.event_receiver.is_terminated()
324    }
325}
326
327impl futures::Stream for ChannelEventStream {
328    type Item = Result<ChannelEvent, fidl::Error>;
329
330    fn poll_next(
331        mut self: std::pin::Pin<&mut Self>,
332        cx: &mut std::task::Context<'_>,
333    ) -> std::task::Poll<Option<Self::Item>> {
334        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
335            &mut self.event_receiver,
336            cx
337        )?) {
338            Some(buf) => std::task::Poll::Ready(Some(ChannelEvent::decode(buf))),
339            None => std::task::Poll::Ready(None),
340        }
341    }
342}
343
344#[derive(Debug)]
345pub enum ChannelEvent {
346    #[non_exhaustive]
347    _UnknownEvent {
348        /// Ordinal of the event that was sent.
349        ordinal: u64,
350    },
351}
352
353impl ChannelEvent {
354    /// Decodes a message buffer as a [`ChannelEvent`].
355    fn decode(
356        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
357    ) -> Result<ChannelEvent, fidl::Error> {
358        let (bytes, _handles) = buf.split_mut();
359        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
360        debug_assert_eq!(tx_header.tx_id, 0);
361        match tx_header.ordinal {
362            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
363                Ok(ChannelEvent::_UnknownEvent { ordinal: tx_header.ordinal })
364            }
365            _ => Err(fidl::Error::UnknownOrdinal {
366                ordinal: tx_header.ordinal,
367                protocol_name: <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
368            }),
369        }
370    }
371}
372
373/// A Stream of incoming requests for fuchsia.bluetooth/Channel.
374pub struct ChannelRequestStream {
375    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
376    is_terminated: bool,
377}
378
379impl std::marker::Unpin for ChannelRequestStream {}
380
381impl futures::stream::FusedStream for ChannelRequestStream {
382    fn is_terminated(&self) -> bool {
383        self.is_terminated
384    }
385}
386
387impl fidl::endpoints::RequestStream for ChannelRequestStream {
388    type Protocol = ChannelMarker;
389    type ControlHandle = ChannelControlHandle;
390
391    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
392        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
393    }
394
395    fn control_handle(&self) -> Self::ControlHandle {
396        ChannelControlHandle { inner: self.inner.clone() }
397    }
398
399    fn into_inner(
400        self,
401    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
402    {
403        (self.inner, self.is_terminated)
404    }
405
406    fn from_inner(
407        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
408        is_terminated: bool,
409    ) -> Self {
410        Self { inner, is_terminated }
411    }
412}
413
414impl futures::Stream for ChannelRequestStream {
415    type Item = Result<ChannelRequest, fidl::Error>;
416
417    fn poll_next(
418        mut self: std::pin::Pin<&mut Self>,
419        cx: &mut std::task::Context<'_>,
420    ) -> std::task::Poll<Option<Self::Item>> {
421        let this = &mut *self;
422        if this.inner.check_shutdown(cx) {
423            this.is_terminated = true;
424            return std::task::Poll::Ready(None);
425        }
426        if this.is_terminated {
427            panic!("polled ChannelRequestStream after completion");
428        }
429        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
430            |bytes, handles| {
431                match this.inner.channel().read_etc(cx, bytes, handles) {
432                    std::task::Poll::Ready(Ok(())) => {}
433                    std::task::Poll::Pending => return std::task::Poll::Pending,
434                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
435                        this.is_terminated = true;
436                        return std::task::Poll::Ready(None);
437                    }
438                    std::task::Poll::Ready(Err(e)) => {
439                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
440                            e.into(),
441                        ))))
442                    }
443                }
444
445                // A message has been received from the channel
446                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
447
448                std::task::Poll::Ready(Some(match header.ordinal {
449                    0x6fc4419c2e763324 => {
450                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
451                        let mut req = fidl::new_empty!(
452                            ChannelSendRequest,
453                            fidl::encoding::DefaultFuchsiaResourceDialect
454                        );
455                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ChannelSendRequest>(&header, _body_bytes, handles, &mut req)?;
456                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
457                        Ok(ChannelRequest::Send_ {
458                            packets: req.packets,
459
460                            responder: ChannelSend_Responder {
461                                control_handle: std::mem::ManuallyDrop::new(control_handle),
462                                tx_id: header.tx_id,
463                            },
464                        })
465                    }
466                    0x3498d7bdb7cdbfd4 => {
467                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
468                        let mut req = fidl::new_empty!(
469                            fidl::encoding::EmptyPayload,
470                            fidl::encoding::DefaultFuchsiaResourceDialect
471                        );
472                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
473                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
474                        Ok(ChannelRequest::Receive {
475                            responder: ChannelReceiveResponder {
476                                control_handle: std::mem::ManuallyDrop::new(control_handle),
477                                tx_id: header.tx_id,
478                            },
479                        })
480                    }
481                    0x5a0cec81d5076c12 => {
482                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
483                        let mut req = fidl::new_empty!(
484                            fidl::encoding::EmptyPayload,
485                            fidl::encoding::DefaultFuchsiaResourceDialect
486                        );
487                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
488                        let control_handle = ChannelControlHandle { inner: this.inner.clone() };
489                        Ok(ChannelRequest::WatchChannelParameters {
490                            responder: ChannelWatchChannelParametersResponder {
491                                control_handle: std::mem::ManuallyDrop::new(control_handle),
492                                tx_id: header.tx_id,
493                            },
494                        })
495                    }
496                    _ if header.tx_id == 0
497                        && header
498                            .dynamic_flags()
499                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
500                    {
501                        Ok(ChannelRequest::_UnknownMethod {
502                            ordinal: header.ordinal,
503                            control_handle: ChannelControlHandle { inner: this.inner.clone() },
504                            method_type: fidl::MethodType::OneWay,
505                        })
506                    }
507                    _ if header
508                        .dynamic_flags()
509                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
510                    {
511                        this.inner.send_framework_err(
512                            fidl::encoding::FrameworkErr::UnknownMethod,
513                            header.tx_id,
514                            header.ordinal,
515                            header.dynamic_flags(),
516                            (bytes, handles),
517                        )?;
518                        Ok(ChannelRequest::_UnknownMethod {
519                            ordinal: header.ordinal,
520                            control_handle: ChannelControlHandle { inner: this.inner.clone() },
521                            method_type: fidl::MethodType::TwoWay,
522                        })
523                    }
524                    _ => Err(fidl::Error::UnknownOrdinal {
525                        ordinal: header.ordinal,
526                        protocol_name:
527                            <ChannelMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
528                    }),
529                }))
530            },
531        )
532    }
533}
534
535/// A duplex channel for sending/recieving [`Packet`]s. This protocol also
536/// serves as a token to keeping the `Channel` open. Closing this protocol (and
537/// the associated `socket` for BR/EDR channels) will close the underlying
538/// channel.
539#[derive(Debug)]
540pub enum ChannelRequest {
541    /// Send multiple packets of data over the channel. Only one `Send`
542    /// may be pending at a time.
543    Send_ { packets: Vec<Packet>, responder: ChannelSend_Responder },
544    /// Hanging get that waits for inbound packets. Only one `Receive`
545    /// may be pending at a time.
546    Receive { responder: ChannelReceiveResponder },
547    /// For RFCOMM channels, this will not return and calls will hang
548    /// indefinitely.
549    ///
550    /// For BR/EDR L2CAP connection-oriented channels this will currently not
551    /// return and calls will hang indefinitely. The initial channel parameters
552    /// are provided in [`fuchsia.bluetooth.bredr/Channel`].
553    ///
554    /// For LE L2CAP connection-oriented channels, the first call will
555    /// immediately return the parameters of the remote side of the channel.
556    /// Subsequent calls will hang until the [`ChannelParameters`] change, at
557    /// which point it will return the new parameters, including those that have
558    /// not changed.
559    WatchChannelParameters { responder: ChannelWatchChannelParametersResponder },
560    /// An interaction was received which does not match any known method.
561    #[non_exhaustive]
562    _UnknownMethod {
563        /// Ordinal of the method that was called.
564        ordinal: u64,
565        control_handle: ChannelControlHandle,
566        method_type: fidl::MethodType,
567    },
568}
569
570impl ChannelRequest {
571    #[allow(irrefutable_let_patterns)]
572    pub fn into_send_(self) -> Option<(Vec<Packet>, ChannelSend_Responder)> {
573        if let ChannelRequest::Send_ { packets, responder } = self {
574            Some((packets, responder))
575        } else {
576            None
577        }
578    }
579
580    #[allow(irrefutable_let_patterns)]
581    pub fn into_receive(self) -> Option<(ChannelReceiveResponder)> {
582        if let ChannelRequest::Receive { responder } = self {
583            Some((responder))
584        } else {
585            None
586        }
587    }
588
589    #[allow(irrefutable_let_patterns)]
590    pub fn into_watch_channel_parameters(self) -> Option<(ChannelWatchChannelParametersResponder)> {
591        if let ChannelRequest::WatchChannelParameters { responder } = self {
592            Some((responder))
593        } else {
594            None
595        }
596    }
597
598    /// Name of the method defined in FIDL
599    pub fn method_name(&self) -> &'static str {
600        match *self {
601            ChannelRequest::Send_ { .. } => "send_",
602            ChannelRequest::Receive { .. } => "receive",
603            ChannelRequest::WatchChannelParameters { .. } => "watch_channel_parameters",
604            ChannelRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
605                "unknown one-way method"
606            }
607            ChannelRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
608                "unknown two-way method"
609            }
610        }
611    }
612}
613
614#[derive(Debug, Clone)]
615pub struct ChannelControlHandle {
616    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
617}
618
619impl fidl::endpoints::ControlHandle for ChannelControlHandle {
620    fn shutdown(&self) {
621        self.inner.shutdown()
622    }
623    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
624        self.inner.shutdown_with_epitaph(status)
625    }
626
627    fn is_closed(&self) -> bool {
628        self.inner.channel().is_closed()
629    }
630    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
631        self.inner.channel().on_closed()
632    }
633
634    #[cfg(target_os = "fuchsia")]
635    fn signal_peer(
636        &self,
637        clear_mask: zx::Signals,
638        set_mask: zx::Signals,
639    ) -> Result<(), zx_status::Status> {
640        use fidl::Peered;
641        self.inner.channel().signal_peer(clear_mask, set_mask)
642    }
643}
644
645impl ChannelControlHandle {}
646
647#[must_use = "FIDL methods require a response to be sent"]
648#[derive(Debug)]
649pub struct ChannelSend_Responder {
650    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
651    tx_id: u32,
652}
653
654/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
655/// if the responder is dropped without sending a response, so that the client
656/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
657impl std::ops::Drop for ChannelSend_Responder {
658    fn drop(&mut self) {
659        self.control_handle.shutdown();
660        // Safety: drops once, never accessed again
661        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
662    }
663}
664
665impl fidl::endpoints::Responder for ChannelSend_Responder {
666    type ControlHandle = ChannelControlHandle;
667
668    fn control_handle(&self) -> &ChannelControlHandle {
669        &self.control_handle
670    }
671
672    fn drop_without_shutdown(mut self) {
673        // Safety: drops once, never accessed again due to mem::forget
674        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
675        // Prevent Drop from running (which would shut down the channel)
676        std::mem::forget(self);
677    }
678}
679
680impl ChannelSend_Responder {
681    /// Sends a response to the FIDL transaction.
682    ///
683    /// Sets the channel to shutdown if an error occurs.
684    pub fn send(self) -> Result<(), fidl::Error> {
685        let _result = self.send_raw();
686        if _result.is_err() {
687            self.control_handle.shutdown();
688        }
689        self.drop_without_shutdown();
690        _result
691    }
692
693    /// Similar to "send" but does not shutdown the channel if an error occurs.
694    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
695        let _result = self.send_raw();
696        self.drop_without_shutdown();
697        _result
698    }
699
700    fn send_raw(&self) -> Result<(), fidl::Error> {
701        self.control_handle.inner.send::<fidl::encoding::FlexibleType<fidl::encoding::EmptyStruct>>(
702            fidl::encoding::Flexible::new(()),
703            self.tx_id,
704            0x6fc4419c2e763324,
705            fidl::encoding::DynamicFlags::FLEXIBLE,
706        )
707    }
708}
709
710#[must_use = "FIDL methods require a response to be sent"]
711#[derive(Debug)]
712pub struct ChannelReceiveResponder {
713    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
714    tx_id: u32,
715}
716
717/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
718/// if the responder is dropped without sending a response, so that the client
719/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
720impl std::ops::Drop for ChannelReceiveResponder {
721    fn drop(&mut self) {
722        self.control_handle.shutdown();
723        // Safety: drops once, never accessed again
724        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
725    }
726}
727
728impl fidl::endpoints::Responder for ChannelReceiveResponder {
729    type ControlHandle = ChannelControlHandle;
730
731    fn control_handle(&self) -> &ChannelControlHandle {
732        &self.control_handle
733    }
734
735    fn drop_without_shutdown(mut self) {
736        // Safety: drops once, never accessed again due to mem::forget
737        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
738        // Prevent Drop from running (which would shut down the channel)
739        std::mem::forget(self);
740    }
741}
742
743impl ChannelReceiveResponder {
744    /// Sends a response to the FIDL transaction.
745    ///
746    /// Sets the channel to shutdown if an error occurs.
747    pub fn send(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
748        let _result = self.send_raw(packets);
749        if _result.is_err() {
750            self.control_handle.shutdown();
751        }
752        self.drop_without_shutdown();
753        _result
754    }
755
756    /// Similar to "send" but does not shutdown the channel if an error occurs.
757    pub fn send_no_shutdown_on_err(self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
758        let _result = self.send_raw(packets);
759        self.drop_without_shutdown();
760        _result
761    }
762
763    fn send_raw(&self, mut packets: &[Packet]) -> Result<(), fidl::Error> {
764        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelReceiveResponse>>(
765            fidl::encoding::Flexible::new((packets,)),
766            self.tx_id,
767            0x3498d7bdb7cdbfd4,
768            fidl::encoding::DynamicFlags::FLEXIBLE,
769        )
770    }
771}
772
773#[must_use = "FIDL methods require a response to be sent"]
774#[derive(Debug)]
775pub struct ChannelWatchChannelParametersResponder {
776    control_handle: std::mem::ManuallyDrop<ChannelControlHandle>,
777    tx_id: u32,
778}
779
780/// Set the the channel to be shutdown (see [`ChannelControlHandle::shutdown`])
781/// if the responder is dropped without sending a response, so that the client
782/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
783impl std::ops::Drop for ChannelWatchChannelParametersResponder {
784    fn drop(&mut self) {
785        self.control_handle.shutdown();
786        // Safety: drops once, never accessed again
787        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
788    }
789}
790
791impl fidl::endpoints::Responder for ChannelWatchChannelParametersResponder {
792    type ControlHandle = ChannelControlHandle;
793
794    fn control_handle(&self) -> &ChannelControlHandle {
795        &self.control_handle
796    }
797
798    fn drop_without_shutdown(mut self) {
799        // Safety: drops once, never accessed again due to mem::forget
800        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
801        // Prevent Drop from running (which would shut down the channel)
802        std::mem::forget(self);
803    }
804}
805
806impl ChannelWatchChannelParametersResponder {
807    /// Sends a response to the FIDL transaction.
808    ///
809    /// Sets the channel to shutdown if an error occurs.
810    pub fn send(self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
811        let _result = self.send_raw(payload);
812        if _result.is_err() {
813            self.control_handle.shutdown();
814        }
815        self.drop_without_shutdown();
816        _result
817    }
818
819    /// Similar to "send" but does not shutdown the channel if an error occurs.
820    pub fn send_no_shutdown_on_err(
821        self,
822        mut payload: &ChannelParameters,
823    ) -> Result<(), fidl::Error> {
824        let _result = self.send_raw(payload);
825        self.drop_without_shutdown();
826        _result
827    }
828
829    fn send_raw(&self, mut payload: &ChannelParameters) -> Result<(), fidl::Error> {
830        self.control_handle.inner.send::<fidl::encoding::FlexibleType<ChannelParameters>>(
831            fidl::encoding::Flexible::new(payload),
832            self.tx_id,
833            0x5a0cec81d5076c12,
834            fidl::encoding::DynamicFlags::FLEXIBLE,
835        )
836    }
837}
838
839mod internal {
840    use super::*;
841}