fidl_fuchsia_bluetooth_hfp_test/
fidl_fuchsia_bluetooth_hfp_test.rs
1#![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 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 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 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#[derive(Debug, Clone)]
101pub struct HfpTestProxy {
102 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
103}
104
105impl fidl::endpoints::Proxy for HfpTestProxy {
106 type Protocol = HfpTestMarker;
107
108 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
109 Self::new(inner)
110 }
111
112 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
113 self.client.into_channel().map_err(|client| Self { client })
114 }
115
116 fn as_channel(&self) -> &::fidl::AsyncChannel {
117 self.client.as_channel()
118 }
119}
120
121impl HfpTestProxy {
122 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
124 let protocol_name = <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
125 Self { client: fidl::client::Client::new(channel, protocol_name) }
126 }
127
128 pub fn take_event_stream(&self) -> HfpTestEventStream {
134 HfpTestEventStream { event_receiver: self.client.take_event_receiver() }
135 }
136
137 pub fn r#battery_indicator(&self, mut level: u8) -> Result<(), fidl::Error> {
142 HfpTestProxyInterface::r#battery_indicator(self, level)
143 }
144
145 pub fn r#set_connection_behavior(
147 &self,
148 mut behavior: &ConnectionBehavior,
149 ) -> Result<(), fidl::Error> {
150 HfpTestProxyInterface::r#set_connection_behavior(self, behavior)
151 }
152}
153
154impl HfpTestProxyInterface for HfpTestProxy {
155 fn r#battery_indicator(&self, mut level: u8) -> Result<(), fidl::Error> {
156 self.client.send::<HfpTestBatteryIndicatorRequest>(
157 (level,),
158 0x2e77903bc47766a,
159 fidl::encoding::DynamicFlags::empty(),
160 )
161 }
162
163 fn r#set_connection_behavior(
164 &self,
165 mut behavior: &ConnectionBehavior,
166 ) -> Result<(), fidl::Error> {
167 self.client.send::<HfpTestSetConnectionBehaviorRequest>(
168 (behavior,),
169 0x33ef757527a5bf07,
170 fidl::encoding::DynamicFlags::empty(),
171 )
172 }
173}
174
175pub struct HfpTestEventStream {
176 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
177}
178
179impl std::marker::Unpin for HfpTestEventStream {}
180
181impl futures::stream::FusedStream for HfpTestEventStream {
182 fn is_terminated(&self) -> bool {
183 self.event_receiver.is_terminated()
184 }
185}
186
187impl futures::Stream for HfpTestEventStream {
188 type Item = Result<HfpTestEvent, fidl::Error>;
189
190 fn poll_next(
191 mut self: std::pin::Pin<&mut Self>,
192 cx: &mut std::task::Context<'_>,
193 ) -> std::task::Poll<Option<Self::Item>> {
194 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
195 &mut self.event_receiver,
196 cx
197 )?) {
198 Some(buf) => std::task::Poll::Ready(Some(HfpTestEvent::decode(buf))),
199 None => std::task::Poll::Ready(None),
200 }
201 }
202}
203
204#[derive(Debug)]
205pub enum HfpTestEvent {}
206
207impl HfpTestEvent {
208 fn decode(
210 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
211 ) -> Result<HfpTestEvent, fidl::Error> {
212 let (bytes, _handles) = buf.split_mut();
213 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
214 debug_assert_eq!(tx_header.tx_id, 0);
215 match tx_header.ordinal {
216 _ => Err(fidl::Error::UnknownOrdinal {
217 ordinal: tx_header.ordinal,
218 protocol_name: <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
219 }),
220 }
221 }
222}
223
224pub struct HfpTestRequestStream {
226 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
227 is_terminated: bool,
228}
229
230impl std::marker::Unpin for HfpTestRequestStream {}
231
232impl futures::stream::FusedStream for HfpTestRequestStream {
233 fn is_terminated(&self) -> bool {
234 self.is_terminated
235 }
236}
237
238impl fidl::endpoints::RequestStream for HfpTestRequestStream {
239 type Protocol = HfpTestMarker;
240 type ControlHandle = HfpTestControlHandle;
241
242 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
243 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
244 }
245
246 fn control_handle(&self) -> Self::ControlHandle {
247 HfpTestControlHandle { inner: self.inner.clone() }
248 }
249
250 fn into_inner(
251 self,
252 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
253 {
254 (self.inner, self.is_terminated)
255 }
256
257 fn from_inner(
258 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
259 is_terminated: bool,
260 ) -> Self {
261 Self { inner, is_terminated }
262 }
263}
264
265impl futures::Stream for HfpTestRequestStream {
266 type Item = Result<HfpTestRequest, fidl::Error>;
267
268 fn poll_next(
269 mut self: std::pin::Pin<&mut Self>,
270 cx: &mut std::task::Context<'_>,
271 ) -> std::task::Poll<Option<Self::Item>> {
272 let this = &mut *self;
273 if this.inner.check_shutdown(cx) {
274 this.is_terminated = true;
275 return std::task::Poll::Ready(None);
276 }
277 if this.is_terminated {
278 panic!("polled HfpTestRequestStream after completion");
279 }
280 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
281 |bytes, handles| {
282 match this.inner.channel().read_etc(cx, bytes, handles) {
283 std::task::Poll::Ready(Ok(())) => {}
284 std::task::Poll::Pending => return std::task::Poll::Pending,
285 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
286 this.is_terminated = true;
287 return std::task::Poll::Ready(None);
288 }
289 std::task::Poll::Ready(Err(e)) => {
290 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
291 e.into(),
292 ))))
293 }
294 }
295
296 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
298
299 std::task::Poll::Ready(Some(match header.ordinal {
300 0x2e77903bc47766a => {
301 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
302 let mut req = fidl::new_empty!(
303 HfpTestBatteryIndicatorRequest,
304 fidl::encoding::DefaultFuchsiaResourceDialect
305 );
306 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<HfpTestBatteryIndicatorRequest>(&header, _body_bytes, handles, &mut req)?;
307 let control_handle = HfpTestControlHandle { inner: this.inner.clone() };
308 Ok(HfpTestRequest::BatteryIndicator { level: req.level, control_handle })
309 }
310 0x33ef757527a5bf07 => {
311 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
312 let mut req = fidl::new_empty!(
313 HfpTestSetConnectionBehaviorRequest,
314 fidl::encoding::DefaultFuchsiaResourceDialect
315 );
316 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<HfpTestSetConnectionBehaviorRequest>(&header, _body_bytes, handles, &mut req)?;
317 let control_handle = HfpTestControlHandle { inner: this.inner.clone() };
318 Ok(HfpTestRequest::SetConnectionBehavior {
319 behavior: req.behavior,
320
321 control_handle,
322 })
323 }
324 _ => Err(fidl::Error::UnknownOrdinal {
325 ordinal: header.ordinal,
326 protocol_name:
327 <HfpTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
328 }),
329 }))
330 },
331 )
332 }
333}
334
335#[derive(Debug)]
337pub enum HfpTestRequest {
338 BatteryIndicator { level: u8, control_handle: HfpTestControlHandle },
343 SetConnectionBehavior { behavior: ConnectionBehavior, control_handle: HfpTestControlHandle },
345}
346
347impl HfpTestRequest {
348 #[allow(irrefutable_let_patterns)]
349 pub fn into_battery_indicator(self) -> Option<(u8, HfpTestControlHandle)> {
350 if let HfpTestRequest::BatteryIndicator { level, control_handle } = self {
351 Some((level, control_handle))
352 } else {
353 None
354 }
355 }
356
357 #[allow(irrefutable_let_patterns)]
358 pub fn into_set_connection_behavior(
359 self,
360 ) -> Option<(ConnectionBehavior, HfpTestControlHandle)> {
361 if let HfpTestRequest::SetConnectionBehavior { behavior, control_handle } = self {
362 Some((behavior, control_handle))
363 } else {
364 None
365 }
366 }
367
368 pub fn method_name(&self) -> &'static str {
370 match *self {
371 HfpTestRequest::BatteryIndicator { .. } => "battery_indicator",
372 HfpTestRequest::SetConnectionBehavior { .. } => "set_connection_behavior",
373 }
374 }
375}
376
377#[derive(Debug, Clone)]
378pub struct HfpTestControlHandle {
379 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
380}
381
382impl fidl::endpoints::ControlHandle for HfpTestControlHandle {
383 fn shutdown(&self) {
384 self.inner.shutdown()
385 }
386 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
387 self.inner.shutdown_with_epitaph(status)
388 }
389
390 fn is_closed(&self) -> bool {
391 self.inner.channel().is_closed()
392 }
393 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
394 self.inner.channel().on_closed()
395 }
396
397 #[cfg(target_os = "fuchsia")]
398 fn signal_peer(
399 &self,
400 clear_mask: zx::Signals,
401 set_mask: zx::Signals,
402 ) -> Result<(), zx_status::Status> {
403 use fidl::Peered;
404 self.inner.channel().signal_peer(clear_mask, set_mask)
405 }
406}
407
408impl HfpTestControlHandle {}
409
410mod internal {
411 use super::*;
412}