fidl_fuchsia_bluetooth_a2dp/
fidl_fuchsia_bluetooth_a2dp.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_a2dp_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct AudioModeMarker;
16
17impl fidl::endpoints::ProtocolMarker for AudioModeMarker {
18    type Proxy = AudioModeProxy;
19    type RequestStream = AudioModeRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = AudioModeSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.a2dp.AudioMode";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for AudioModeMarker {}
26
27pub trait AudioModeProxyInterface: Send + Sync {
28    type SetRoleResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29    fn r#set_role(&self, role: Role) -> Self::SetRoleResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct AudioModeSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for AudioModeSynchronousProxy {
39    type Proxy = AudioModeProxy;
40    type Protocol = AudioModeMarker;
41
42    fn from_channel(inner: fidl::Channel) -> Self {
43        Self::new(inner)
44    }
45
46    fn into_channel(self) -> fidl::Channel {
47        self.client.into_channel()
48    }
49
50    fn as_channel(&self) -> &fidl::Channel {
51        self.client.as_channel()
52    }
53}
54
55#[cfg(target_os = "fuchsia")]
56impl AudioModeSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        let protocol_name = <AudioModeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
60    }
61
62    pub fn into_channel(self) -> fidl::Channel {
63        self.client.into_channel()
64    }
65
66    /// Waits until an event arrives and returns it. It is safe for other
67    /// threads to make concurrent requests while waiting for an event.
68    pub fn wait_for_event(
69        &self,
70        deadline: zx::MonotonicInstant,
71    ) -> Result<AudioModeEvent, fidl::Error> {
72        AudioModeEvent::decode(self.client.wait_for_event(deadline)?)
73    }
74
75    /// Switch the device to act as the specified A2DP Role. If the device is already
76    /// set to the requested role, calling this method is a no-op.
77    ///
78    /// When this method returns, a client can depend on the following:
79    /// 1. If the role was switched, the previous profile has requested removal
80    ///    from the hosts' SDP databases, and all L2CAP channels associated with
81    ///    the previous profile have initiated or completed the process of closing.
82    /// 2. The device is in the requested A2DP role.
83    ///
84    /// If the role cannot be set due to an internal error, the server will close
85    /// the channel.
86    pub fn r#set_role(
87        &self,
88        mut role: Role,
89        ___deadline: zx::MonotonicInstant,
90    ) -> Result<(), fidl::Error> {
91        let _response =
92            self.client.send_query::<AudioModeSetRoleRequest, fidl::encoding::EmptyPayload>(
93                (role,),
94                0x55bc139643a166a6,
95                fidl::encoding::DynamicFlags::empty(),
96                ___deadline,
97            )?;
98        Ok(_response)
99    }
100}
101
102#[derive(Debug, Clone)]
103pub struct AudioModeProxy {
104    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
105}
106
107impl fidl::endpoints::Proxy for AudioModeProxy {
108    type Protocol = AudioModeMarker;
109
110    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
111        Self::new(inner)
112    }
113
114    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
115        self.client.into_channel().map_err(|client| Self { client })
116    }
117
118    fn as_channel(&self) -> &::fidl::AsyncChannel {
119        self.client.as_channel()
120    }
121}
122
123impl AudioModeProxy {
124    /// Create a new Proxy for fuchsia.bluetooth.a2dp/AudioMode.
125    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
126        let protocol_name = <AudioModeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
127        Self { client: fidl::client::Client::new(channel, protocol_name) }
128    }
129
130    /// Get a Stream of events from the remote end of the protocol.
131    ///
132    /// # Panics
133    ///
134    /// Panics if the event stream was already taken.
135    pub fn take_event_stream(&self) -> AudioModeEventStream {
136        AudioModeEventStream { event_receiver: self.client.take_event_receiver() }
137    }
138
139    /// Switch the device to act as the specified A2DP Role. If the device is already
140    /// set to the requested role, calling this method is a no-op.
141    ///
142    /// When this method returns, a client can depend on the following:
143    /// 1. If the role was switched, the previous profile has requested removal
144    ///    from the hosts' SDP databases, and all L2CAP channels associated with
145    ///    the previous profile have initiated or completed the process of closing.
146    /// 2. The device is in the requested A2DP role.
147    ///
148    /// If the role cannot be set due to an internal error, the server will close
149    /// the channel.
150    pub fn r#set_role(
151        &self,
152        mut role: Role,
153    ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
154        AudioModeProxyInterface::r#set_role(self, role)
155    }
156}
157
158impl AudioModeProxyInterface for AudioModeProxy {
159    type SetRoleResponseFut =
160        fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
161    fn r#set_role(&self, mut role: Role) -> Self::SetRoleResponseFut {
162        fn _decode(
163            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
164        ) -> Result<(), fidl::Error> {
165            let _response = fidl::client::decode_transaction_body::<
166                fidl::encoding::EmptyPayload,
167                fidl::encoding::DefaultFuchsiaResourceDialect,
168                0x55bc139643a166a6,
169            >(_buf?)?;
170            Ok(_response)
171        }
172        self.client.send_query_and_decode::<AudioModeSetRoleRequest, ()>(
173            (role,),
174            0x55bc139643a166a6,
175            fidl::encoding::DynamicFlags::empty(),
176            _decode,
177        )
178    }
179}
180
181pub struct AudioModeEventStream {
182    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
183}
184
185impl std::marker::Unpin for AudioModeEventStream {}
186
187impl futures::stream::FusedStream for AudioModeEventStream {
188    fn is_terminated(&self) -> bool {
189        self.event_receiver.is_terminated()
190    }
191}
192
193impl futures::Stream for AudioModeEventStream {
194    type Item = Result<AudioModeEvent, fidl::Error>;
195
196    fn poll_next(
197        mut self: std::pin::Pin<&mut Self>,
198        cx: &mut std::task::Context<'_>,
199    ) -> std::task::Poll<Option<Self::Item>> {
200        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
201            &mut self.event_receiver,
202            cx
203        )?) {
204            Some(buf) => std::task::Poll::Ready(Some(AudioModeEvent::decode(buf))),
205            None => std::task::Poll::Ready(None),
206        }
207    }
208}
209
210#[derive(Debug)]
211pub enum AudioModeEvent {}
212
213impl AudioModeEvent {
214    /// Decodes a message buffer as a [`AudioModeEvent`].
215    fn decode(
216        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
217    ) -> Result<AudioModeEvent, fidl::Error> {
218        let (bytes, _handles) = buf.split_mut();
219        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
220        debug_assert_eq!(tx_header.tx_id, 0);
221        match tx_header.ordinal {
222            _ => Err(fidl::Error::UnknownOrdinal {
223                ordinal: tx_header.ordinal,
224                protocol_name: <AudioModeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
225            }),
226        }
227    }
228}
229
230/// A Stream of incoming requests for fuchsia.bluetooth.a2dp/AudioMode.
231pub struct AudioModeRequestStream {
232    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
233    is_terminated: bool,
234}
235
236impl std::marker::Unpin for AudioModeRequestStream {}
237
238impl futures::stream::FusedStream for AudioModeRequestStream {
239    fn is_terminated(&self) -> bool {
240        self.is_terminated
241    }
242}
243
244impl fidl::endpoints::RequestStream for AudioModeRequestStream {
245    type Protocol = AudioModeMarker;
246    type ControlHandle = AudioModeControlHandle;
247
248    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
249        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
250    }
251
252    fn control_handle(&self) -> Self::ControlHandle {
253        AudioModeControlHandle { inner: self.inner.clone() }
254    }
255
256    fn into_inner(
257        self,
258    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
259    {
260        (self.inner, self.is_terminated)
261    }
262
263    fn from_inner(
264        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
265        is_terminated: bool,
266    ) -> Self {
267        Self { inner, is_terminated }
268    }
269}
270
271impl futures::Stream for AudioModeRequestStream {
272    type Item = Result<AudioModeRequest, fidl::Error>;
273
274    fn poll_next(
275        mut self: std::pin::Pin<&mut Self>,
276        cx: &mut std::task::Context<'_>,
277    ) -> std::task::Poll<Option<Self::Item>> {
278        let this = &mut *self;
279        if this.inner.check_shutdown(cx) {
280            this.is_terminated = true;
281            return std::task::Poll::Ready(None);
282        }
283        if this.is_terminated {
284            panic!("polled AudioModeRequestStream after completion");
285        }
286        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
287            |bytes, handles| {
288                match this.inner.channel().read_etc(cx, bytes, handles) {
289                    std::task::Poll::Ready(Ok(())) => {}
290                    std::task::Poll::Pending => return std::task::Poll::Pending,
291                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
292                        this.is_terminated = true;
293                        return std::task::Poll::Ready(None);
294                    }
295                    std::task::Poll::Ready(Err(e)) => {
296                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
297                            e.into(),
298                        ))))
299                    }
300                }
301
302                // A message has been received from the channel
303                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
304
305                std::task::Poll::Ready(Some(match header.ordinal {
306                    0x55bc139643a166a6 => {
307                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
308                        let mut req = fidl::new_empty!(
309                            AudioModeSetRoleRequest,
310                            fidl::encoding::DefaultFuchsiaResourceDialect
311                        );
312                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<AudioModeSetRoleRequest>(&header, _body_bytes, handles, &mut req)?;
313                        let control_handle = AudioModeControlHandle { inner: this.inner.clone() };
314                        Ok(AudioModeRequest::SetRole {
315                            role: req.role,
316
317                            responder: AudioModeSetRoleResponder {
318                                control_handle: std::mem::ManuallyDrop::new(control_handle),
319                                tx_id: header.tx_id,
320                            },
321                        })
322                    }
323                    _ => Err(fidl::Error::UnknownOrdinal {
324                        ordinal: header.ordinal,
325                        protocol_name:
326                            <AudioModeMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
327                    }),
328                }))
329            },
330        )
331    }
332}
333
334/// A protocol for specifying which A2DP role this device should operate.
335#[derive(Debug)]
336pub enum AudioModeRequest {
337    /// Switch the device to act as the specified A2DP Role. If the device is already
338    /// set to the requested role, calling this method is a no-op.
339    ///
340    /// When this method returns, a client can depend on the following:
341    /// 1. If the role was switched, the previous profile has requested removal
342    ///    from the hosts' SDP databases, and all L2CAP channels associated with
343    ///    the previous profile have initiated or completed the process of closing.
344    /// 2. The device is in the requested A2DP role.
345    ///
346    /// If the role cannot be set due to an internal error, the server will close
347    /// the channel.
348    SetRole { role: Role, responder: AudioModeSetRoleResponder },
349}
350
351impl AudioModeRequest {
352    #[allow(irrefutable_let_patterns)]
353    pub fn into_set_role(self) -> Option<(Role, AudioModeSetRoleResponder)> {
354        if let AudioModeRequest::SetRole { role, responder } = self {
355            Some((role, responder))
356        } else {
357            None
358        }
359    }
360
361    /// Name of the method defined in FIDL
362    pub fn method_name(&self) -> &'static str {
363        match *self {
364            AudioModeRequest::SetRole { .. } => "set_role",
365        }
366    }
367}
368
369#[derive(Debug, Clone)]
370pub struct AudioModeControlHandle {
371    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
372}
373
374impl fidl::endpoints::ControlHandle for AudioModeControlHandle {
375    fn shutdown(&self) {
376        self.inner.shutdown()
377    }
378    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
379        self.inner.shutdown_with_epitaph(status)
380    }
381
382    fn is_closed(&self) -> bool {
383        self.inner.channel().is_closed()
384    }
385    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
386        self.inner.channel().on_closed()
387    }
388
389    #[cfg(target_os = "fuchsia")]
390    fn signal_peer(
391        &self,
392        clear_mask: zx::Signals,
393        set_mask: zx::Signals,
394    ) -> Result<(), zx_status::Status> {
395        use fidl::Peered;
396        self.inner.channel().signal_peer(clear_mask, set_mask)
397    }
398}
399
400impl AudioModeControlHandle {}
401
402#[must_use = "FIDL methods require a response to be sent"]
403#[derive(Debug)]
404pub struct AudioModeSetRoleResponder {
405    control_handle: std::mem::ManuallyDrop<AudioModeControlHandle>,
406    tx_id: u32,
407}
408
409/// Set the the channel to be shutdown (see [`AudioModeControlHandle::shutdown`])
410/// if the responder is dropped without sending a response, so that the client
411/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
412impl std::ops::Drop for AudioModeSetRoleResponder {
413    fn drop(&mut self) {
414        self.control_handle.shutdown();
415        // Safety: drops once, never accessed again
416        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
417    }
418}
419
420impl fidl::endpoints::Responder for AudioModeSetRoleResponder {
421    type ControlHandle = AudioModeControlHandle;
422
423    fn control_handle(&self) -> &AudioModeControlHandle {
424        &self.control_handle
425    }
426
427    fn drop_without_shutdown(mut self) {
428        // Safety: drops once, never accessed again due to mem::forget
429        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
430        // Prevent Drop from running (which would shut down the channel)
431        std::mem::forget(self);
432    }
433}
434
435impl AudioModeSetRoleResponder {
436    /// Sends a response to the FIDL transaction.
437    ///
438    /// Sets the channel to shutdown if an error occurs.
439    pub fn send(self) -> Result<(), fidl::Error> {
440        let _result = self.send_raw();
441        if _result.is_err() {
442            self.control_handle.shutdown();
443        }
444        self.drop_without_shutdown();
445        _result
446    }
447
448    /// Similar to "send" but does not shutdown the channel if an error occurs.
449    pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
450        let _result = self.send_raw();
451        self.drop_without_shutdown();
452        _result
453    }
454
455    fn send_raw(&self) -> Result<(), fidl::Error> {
456        self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
457            (),
458            self.tx_id,
459            0x55bc139643a166a6,
460            fidl::encoding::DynamicFlags::empty(),
461        )
462    }
463}
464
465mod internal {
466    use super::*;
467}