fidl_fuchsia_bluetooth_hfp_test/
fidl_fuchsia_bluetooth_hfp_test.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_hfp_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct HfpTestMarker;
16
17impl fidl::endpoints::ProtocolMarker for HfpTestMarker {
18    type Proxy = HfpTestProxy;
19    type RequestStream = HfpTestRequestStream;
20    #[cfg(target_os = "fuchsia")]
21    type SynchronousProxy = HfpTestSynchronousProxy;
22
23    const DEBUG_NAME: &'static str = "fuchsia.bluetooth.hfp.test.HfpTest";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for HfpTestMarker {}
26
27pub trait HfpTestProxyInterface: Send + Sync {
28    fn r#battery_indicator(&self, level: u8) -> Result<(), fidl::Error>;
29    fn r#set_connection_behavior(&self, behavior: &ConnectionBehavior) -> Result<(), fidl::Error>;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct HfpTestSynchronousProxy {
34    client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for HfpTestSynchronousProxy {
39    type Proxy = HfpTestProxy;
40    type Protocol = HfpTestMarker;
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 HfpTestSynchronousProxy {
57    pub fn new(channel: fidl::Channel) -> Self {
58        let protocol_name = <HfpTestMarker 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<HfpTestEvent, fidl::Error> {
72        HfpTestEvent::decode(self.client.wait_for_event(deadline)?)
73    }
74
75    /// Set the value of the AG battery indicator.
76    ///
77    /// `level` must be within the range 0-5 inclusive. Values outside of this
78    /// range cause the channel to close.
79    pub fn r#battery_indicator(&self, mut level: u8) -> Result<(), fidl::Error> {
80        self.client.send::<HfpTestBatteryIndicatorRequest>(
81            (level,),
82            0x2e77903bc47766a,
83            fidl::encoding::DynamicFlags::empty(),
84        )
85    }
86
87    /// Configure the connection behavior when the component discovers new peers.
88    pub fn r#set_connection_behavior(
89        &self,
90        mut behavior: &ConnectionBehavior,
91    ) -> Result<(), fidl::Error> {
92        self.client.send::<HfpTestSetConnectionBehaviorRequest>(
93            (behavior,),
94            0x33ef757527a5bf07,
95            fidl::encoding::DynamicFlags::empty(),
96        )
97    }
98}
99
100#[cfg(target_os = "fuchsia")]
101impl From<HfpTestSynchronousProxy> for zx::Handle {
102    fn from(value: HfpTestSynchronousProxy) -> Self {
103        value.into_channel().into()
104    }
105}
106
107#[cfg(target_os = "fuchsia")]
108impl From<fidl::Channel> for HfpTestSynchronousProxy {
109    fn from(value: fidl::Channel) -> Self {
110        Self::new(value)
111    }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl fidl::endpoints::FromClient for HfpTestSynchronousProxy {
116    type Protocol = HfpTestMarker;
117
118    fn from_client(value: fidl::endpoints::ClientEnd<HfpTestMarker>) -> Self {
119        Self::new(value.into_channel())
120    }
121}
122
123#[derive(Debug, Clone)]
124pub struct HfpTestProxy {
125    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
126}
127
128impl fidl::endpoints::Proxy for HfpTestProxy {
129    type Protocol = HfpTestMarker;
130
131    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
132        Self::new(inner)
133    }
134
135    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
136        self.client.into_channel().map_err(|client| Self { client })
137    }
138
139    fn as_channel(&self) -> &::fidl::AsyncChannel {
140        self.client.as_channel()
141    }
142}
143
144impl HfpTestProxy {
145    /// Create a new Proxy for fuchsia.bluetooth.hfp.test/HfpTest.
146    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
147        let protocol_name = <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
148        Self { client: fidl::client::Client::new(channel, protocol_name) }
149    }
150
151    /// Get a Stream of events from the remote end of the protocol.
152    ///
153    /// # Panics
154    ///
155    /// Panics if the event stream was already taken.
156    pub fn take_event_stream(&self) -> HfpTestEventStream {
157        HfpTestEventStream { event_receiver: self.client.take_event_receiver() }
158    }
159
160    /// Set the value of the AG battery indicator.
161    ///
162    /// `level` must be within the range 0-5 inclusive. Values outside of this
163    /// range cause the channel to close.
164    pub fn r#battery_indicator(&self, mut level: u8) -> Result<(), fidl::Error> {
165        HfpTestProxyInterface::r#battery_indicator(self, level)
166    }
167
168    /// Configure the connection behavior when the component discovers new peers.
169    pub fn r#set_connection_behavior(
170        &self,
171        mut behavior: &ConnectionBehavior,
172    ) -> Result<(), fidl::Error> {
173        HfpTestProxyInterface::r#set_connection_behavior(self, behavior)
174    }
175}
176
177impl HfpTestProxyInterface for HfpTestProxy {
178    fn r#battery_indicator(&self, mut level: u8) -> Result<(), fidl::Error> {
179        self.client.send::<HfpTestBatteryIndicatorRequest>(
180            (level,),
181            0x2e77903bc47766a,
182            fidl::encoding::DynamicFlags::empty(),
183        )
184    }
185
186    fn r#set_connection_behavior(
187        &self,
188        mut behavior: &ConnectionBehavior,
189    ) -> Result<(), fidl::Error> {
190        self.client.send::<HfpTestSetConnectionBehaviorRequest>(
191            (behavior,),
192            0x33ef757527a5bf07,
193            fidl::encoding::DynamicFlags::empty(),
194        )
195    }
196}
197
198pub struct HfpTestEventStream {
199    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
200}
201
202impl std::marker::Unpin for HfpTestEventStream {}
203
204impl futures::stream::FusedStream for HfpTestEventStream {
205    fn is_terminated(&self) -> bool {
206        self.event_receiver.is_terminated()
207    }
208}
209
210impl futures::Stream for HfpTestEventStream {
211    type Item = Result<HfpTestEvent, fidl::Error>;
212
213    fn poll_next(
214        mut self: std::pin::Pin<&mut Self>,
215        cx: &mut std::task::Context<'_>,
216    ) -> std::task::Poll<Option<Self::Item>> {
217        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
218            &mut self.event_receiver,
219            cx
220        )?) {
221            Some(buf) => std::task::Poll::Ready(Some(HfpTestEvent::decode(buf))),
222            None => std::task::Poll::Ready(None),
223        }
224    }
225}
226
227#[derive(Debug)]
228pub enum HfpTestEvent {}
229
230impl HfpTestEvent {
231    /// Decodes a message buffer as a [`HfpTestEvent`].
232    fn decode(
233        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
234    ) -> Result<HfpTestEvent, fidl::Error> {
235        let (bytes, _handles) = buf.split_mut();
236        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
237        debug_assert_eq!(tx_header.tx_id, 0);
238        match tx_header.ordinal {
239            _ => Err(fidl::Error::UnknownOrdinal {
240                ordinal: tx_header.ordinal,
241                protocol_name: <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
242            }),
243        }
244    }
245}
246
247/// A Stream of incoming requests for fuchsia.bluetooth.hfp.test/HfpTest.
248pub struct HfpTestRequestStream {
249    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
250    is_terminated: bool,
251}
252
253impl std::marker::Unpin for HfpTestRequestStream {}
254
255impl futures::stream::FusedStream for HfpTestRequestStream {
256    fn is_terminated(&self) -> bool {
257        self.is_terminated
258    }
259}
260
261impl fidl::endpoints::RequestStream for HfpTestRequestStream {
262    type Protocol = HfpTestMarker;
263    type ControlHandle = HfpTestControlHandle;
264
265    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
266        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
267    }
268
269    fn control_handle(&self) -> Self::ControlHandle {
270        HfpTestControlHandle { inner: self.inner.clone() }
271    }
272
273    fn into_inner(
274        self,
275    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
276    {
277        (self.inner, self.is_terminated)
278    }
279
280    fn from_inner(
281        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
282        is_terminated: bool,
283    ) -> Self {
284        Self { inner, is_terminated }
285    }
286}
287
288impl futures::Stream for HfpTestRequestStream {
289    type Item = Result<HfpTestRequest, fidl::Error>;
290
291    fn poll_next(
292        mut self: std::pin::Pin<&mut Self>,
293        cx: &mut std::task::Context<'_>,
294    ) -> std::task::Poll<Option<Self::Item>> {
295        let this = &mut *self;
296        if this.inner.check_shutdown(cx) {
297            this.is_terminated = true;
298            return std::task::Poll::Ready(None);
299        }
300        if this.is_terminated {
301            panic!("polled HfpTestRequestStream after completion");
302        }
303        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
304            |bytes, handles| {
305                match this.inner.channel().read_etc(cx, bytes, handles) {
306                    std::task::Poll::Ready(Ok(())) => {}
307                    std::task::Poll::Pending => return std::task::Poll::Pending,
308                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
309                        this.is_terminated = true;
310                        return std::task::Poll::Ready(None);
311                    }
312                    std::task::Poll::Ready(Err(e)) => {
313                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
314                            e.into(),
315                        ))))
316                    }
317                }
318
319                // A message has been received from the channel
320                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
321
322                std::task::Poll::Ready(Some(match header.ordinal {
323                    0x2e77903bc47766a => {
324                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
325                        let mut req = fidl::new_empty!(
326                            HfpTestBatteryIndicatorRequest,
327                            fidl::encoding::DefaultFuchsiaResourceDialect
328                        );
329                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<HfpTestBatteryIndicatorRequest>(&header, _body_bytes, handles, &mut req)?;
330                        let control_handle = HfpTestControlHandle { inner: this.inner.clone() };
331                        Ok(HfpTestRequest::BatteryIndicator { level: req.level, control_handle })
332                    }
333                    0x33ef757527a5bf07 => {
334                        header.validate_request_tx_id(fidl::MethodType::OneWay)?;
335                        let mut req = fidl::new_empty!(
336                            HfpTestSetConnectionBehaviorRequest,
337                            fidl::encoding::DefaultFuchsiaResourceDialect
338                        );
339                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<HfpTestSetConnectionBehaviorRequest>(&header, _body_bytes, handles, &mut req)?;
340                        let control_handle = HfpTestControlHandle { inner: this.inner.clone() };
341                        Ok(HfpTestRequest::SetConnectionBehavior {
342                            behavior: req.behavior,
343
344                            control_handle,
345                        })
346                    }
347                    _ => Err(fidl::Error::UnknownOrdinal {
348                        ordinal: header.ordinal,
349                        protocol_name:
350                            <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
351                    }),
352                }))
353            },
354        )
355    }
356}
357
358/// Provides additional methods not in `Hfp` that are strictly for testing.
359#[derive(Debug)]
360pub enum HfpTestRequest {
361    /// Set the value of the AG battery indicator.
362    ///
363    /// `level` must be within the range 0-5 inclusive. Values outside of this
364    /// range cause the channel to close.
365    BatteryIndicator { level: u8, control_handle: HfpTestControlHandle },
366    /// Configure the connection behavior when the component discovers new peers.
367    SetConnectionBehavior { behavior: ConnectionBehavior, control_handle: HfpTestControlHandle },
368}
369
370impl HfpTestRequest {
371    #[allow(irrefutable_let_patterns)]
372    pub fn into_battery_indicator(self) -> Option<(u8, HfpTestControlHandle)> {
373        if let HfpTestRequest::BatteryIndicator { level, control_handle } = self {
374            Some((level, control_handle))
375        } else {
376            None
377        }
378    }
379
380    #[allow(irrefutable_let_patterns)]
381    pub fn into_set_connection_behavior(
382        self,
383    ) -> Option<(ConnectionBehavior, HfpTestControlHandle)> {
384        if let HfpTestRequest::SetConnectionBehavior { behavior, control_handle } = self {
385            Some((behavior, control_handle))
386        } else {
387            None
388        }
389    }
390
391    /// Name of the method defined in FIDL
392    pub fn method_name(&self) -> &'static str {
393        match *self {
394            HfpTestRequest::BatteryIndicator { .. } => "battery_indicator",
395            HfpTestRequest::SetConnectionBehavior { .. } => "set_connection_behavior",
396        }
397    }
398}
399
400#[derive(Debug, Clone)]
401pub struct HfpTestControlHandle {
402    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
403}
404
405impl fidl::endpoints::ControlHandle for HfpTestControlHandle {
406    fn shutdown(&self) {
407        self.inner.shutdown()
408    }
409    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
410        self.inner.shutdown_with_epitaph(status)
411    }
412
413    fn is_closed(&self) -> bool {
414        self.inner.channel().is_closed()
415    }
416    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
417        self.inner.channel().on_closed()
418    }
419
420    #[cfg(target_os = "fuchsia")]
421    fn signal_peer(
422        &self,
423        clear_mask: zx::Signals,
424        set_mask: zx::Signals,
425    ) -> Result<(), zx_status::Status> {
426        use fidl::Peered;
427        self.inner.channel().signal_peer(clear_mask, set_mask)
428    }
429}
430
431impl HfpTestControlHandle {}
432
433mod internal {
434    use super::*;
435}