Skip to main content

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