fidl_fuchsia_bluetooth_rfcomm_test/
fidl_fuchsia_bluetooth_rfcomm_test.rs1#![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_rfcomm_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct RfcommTestMarker;
16
17impl fidl::endpoints::ProtocolMarker for RfcommTestMarker {
18 type Proxy = RfcommTestProxy;
19 type RequestStream = RfcommTestRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = RfcommTestSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.bluetooth.rfcomm.test.RfcommTest";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for RfcommTestMarker {}
26
27pub trait RfcommTestProxyInterface: Send + Sync {
28 fn r#disconnect(&self, id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error>;
29 fn r#remote_line_status(
30 &self,
31 id: &fidl_fuchsia_bluetooth::PeerId,
32 channel_number: u8,
33 status: Status,
34 ) -> Result<(), fidl::Error>;
35}
36#[derive(Debug)]
37#[cfg(target_os = "fuchsia")]
38pub struct RfcommTestSynchronousProxy {
39 client: fidl::client::sync::Client,
40}
41
42#[cfg(target_os = "fuchsia")]
43impl fidl::endpoints::SynchronousProxy for RfcommTestSynchronousProxy {
44 type Proxy = RfcommTestProxy;
45 type Protocol = RfcommTestMarker;
46
47 fn from_channel(inner: fidl::Channel) -> Self {
48 Self::new(inner)
49 }
50
51 fn into_channel(self) -> fidl::Channel {
52 self.client.into_channel()
53 }
54
55 fn as_channel(&self) -> &fidl::Channel {
56 self.client.as_channel()
57 }
58}
59
60#[cfg(target_os = "fuchsia")]
61impl RfcommTestSynchronousProxy {
62 pub fn new(channel: fidl::Channel) -> Self {
63 Self { client: fidl::client::sync::Client::new(channel) }
64 }
65
66 pub fn into_channel(self) -> fidl::Channel {
67 self.client.into_channel()
68 }
69
70 pub fn wait_for_event(
73 &self,
74 deadline: zx::MonotonicInstant,
75 ) -> Result<RfcommTestEvent, fidl::Error> {
76 RfcommTestEvent::decode(self.client.wait_for_event::<RfcommTestMarker>(deadline)?)
77 }
78
79 pub fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
85 self.client.send::<RfcommTestDisconnectRequest>(
86 (id,),
87 0x6173bb03e37ddddf,
88 fidl::encoding::DynamicFlags::empty(),
89 )
90 }
91
92 pub fn r#remote_line_status(
100 &self,
101 mut id: &fidl_fuchsia_bluetooth::PeerId,
102 mut channel_number: u8,
103 mut status: Status,
104 ) -> Result<(), fidl::Error> {
105 self.client.send::<RfcommTestRemoteLineStatusRequest>(
106 (id, channel_number, status),
107 0x3689603441392637,
108 fidl::encoding::DynamicFlags::empty(),
109 )
110 }
111}
112
113#[cfg(target_os = "fuchsia")]
114impl From<RfcommTestSynchronousProxy> for zx::NullableHandle {
115 fn from(value: RfcommTestSynchronousProxy) -> Self {
116 value.into_channel().into()
117 }
118}
119
120#[cfg(target_os = "fuchsia")]
121impl From<fidl::Channel> for RfcommTestSynchronousProxy {
122 fn from(value: fidl::Channel) -> Self {
123 Self::new(value)
124 }
125}
126
127#[cfg(target_os = "fuchsia")]
128impl fidl::endpoints::FromClient for RfcommTestSynchronousProxy {
129 type Protocol = RfcommTestMarker;
130
131 fn from_client(value: fidl::endpoints::ClientEnd<RfcommTestMarker>) -> Self {
132 Self::new(value.into_channel())
133 }
134}
135
136#[derive(Debug, Clone)]
137pub struct RfcommTestProxy {
138 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
139}
140
141impl fidl::endpoints::Proxy for RfcommTestProxy {
142 type Protocol = RfcommTestMarker;
143
144 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
145 Self::new(inner)
146 }
147
148 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
149 self.client.into_channel().map_err(|client| Self { client })
150 }
151
152 fn as_channel(&self) -> &::fidl::AsyncChannel {
153 self.client.as_channel()
154 }
155}
156
157impl RfcommTestProxy {
158 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
160 let protocol_name = <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
161 Self { client: fidl::client::Client::new(channel, protocol_name) }
162 }
163
164 pub fn take_event_stream(&self) -> RfcommTestEventStream {
170 RfcommTestEventStream { event_receiver: self.client.take_event_receiver() }
171 }
172
173 pub fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
179 RfcommTestProxyInterface::r#disconnect(self, id)
180 }
181
182 pub fn r#remote_line_status(
190 &self,
191 mut id: &fidl_fuchsia_bluetooth::PeerId,
192 mut channel_number: u8,
193 mut status: Status,
194 ) -> Result<(), fidl::Error> {
195 RfcommTestProxyInterface::r#remote_line_status(self, id, channel_number, status)
196 }
197}
198
199impl RfcommTestProxyInterface for RfcommTestProxy {
200 fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
201 self.client.send::<RfcommTestDisconnectRequest>(
202 (id,),
203 0x6173bb03e37ddddf,
204 fidl::encoding::DynamicFlags::empty(),
205 )
206 }
207
208 fn r#remote_line_status(
209 &self,
210 mut id: &fidl_fuchsia_bluetooth::PeerId,
211 mut channel_number: u8,
212 mut status: Status,
213 ) -> Result<(), fidl::Error> {
214 self.client.send::<RfcommTestRemoteLineStatusRequest>(
215 (id, channel_number, status),
216 0x3689603441392637,
217 fidl::encoding::DynamicFlags::empty(),
218 )
219 }
220}
221
222pub struct RfcommTestEventStream {
223 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
224}
225
226impl std::marker::Unpin for RfcommTestEventStream {}
227
228impl futures::stream::FusedStream for RfcommTestEventStream {
229 fn is_terminated(&self) -> bool {
230 self.event_receiver.is_terminated()
231 }
232}
233
234impl futures::Stream for RfcommTestEventStream {
235 type Item = Result<RfcommTestEvent, fidl::Error>;
236
237 fn poll_next(
238 mut self: std::pin::Pin<&mut Self>,
239 cx: &mut std::task::Context<'_>,
240 ) -> std::task::Poll<Option<Self::Item>> {
241 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
242 &mut self.event_receiver,
243 cx
244 )?) {
245 Some(buf) => std::task::Poll::Ready(Some(RfcommTestEvent::decode(buf))),
246 None => std::task::Poll::Ready(None),
247 }
248 }
249}
250
251#[derive(Debug)]
252pub enum RfcommTestEvent {}
253
254impl RfcommTestEvent {
255 fn decode(
257 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
258 ) -> Result<RfcommTestEvent, fidl::Error> {
259 let (bytes, _handles) = buf.split_mut();
260 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
261 debug_assert_eq!(tx_header.tx_id, 0);
262 match tx_header.ordinal {
263 _ => Err(fidl::Error::UnknownOrdinal {
264 ordinal: tx_header.ordinal,
265 protocol_name: <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
266 }),
267 }
268 }
269}
270
271pub struct RfcommTestRequestStream {
273 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
274 is_terminated: bool,
275}
276
277impl std::marker::Unpin for RfcommTestRequestStream {}
278
279impl futures::stream::FusedStream for RfcommTestRequestStream {
280 fn is_terminated(&self) -> bool {
281 self.is_terminated
282 }
283}
284
285impl fidl::endpoints::RequestStream for RfcommTestRequestStream {
286 type Protocol = RfcommTestMarker;
287 type ControlHandle = RfcommTestControlHandle;
288
289 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
290 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
291 }
292
293 fn control_handle(&self) -> Self::ControlHandle {
294 RfcommTestControlHandle { inner: self.inner.clone() }
295 }
296
297 fn into_inner(
298 self,
299 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
300 {
301 (self.inner, self.is_terminated)
302 }
303
304 fn from_inner(
305 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
306 is_terminated: bool,
307 ) -> Self {
308 Self { inner, is_terminated }
309 }
310}
311
312impl futures::Stream for RfcommTestRequestStream {
313 type Item = Result<RfcommTestRequest, fidl::Error>;
314
315 fn poll_next(
316 mut self: std::pin::Pin<&mut Self>,
317 cx: &mut std::task::Context<'_>,
318 ) -> std::task::Poll<Option<Self::Item>> {
319 let this = &mut *self;
320 if this.inner.check_shutdown(cx) {
321 this.is_terminated = true;
322 return std::task::Poll::Ready(None);
323 }
324 if this.is_terminated {
325 panic!("polled RfcommTestRequestStream after completion");
326 }
327 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
328 |bytes, handles| {
329 match this.inner.channel().read_etc(cx, bytes, handles) {
330 std::task::Poll::Ready(Ok(())) => {}
331 std::task::Poll::Pending => return std::task::Poll::Pending,
332 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
333 this.is_terminated = true;
334 return std::task::Poll::Ready(None);
335 }
336 std::task::Poll::Ready(Err(e)) => {
337 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
338 e.into(),
339 ))));
340 }
341 }
342
343 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
345
346 std::task::Poll::Ready(Some(match header.ordinal {
347 0x6173bb03e37ddddf => {
348 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
349 let mut req = fidl::new_empty!(
350 RfcommTestDisconnectRequest,
351 fidl::encoding::DefaultFuchsiaResourceDialect
352 );
353 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RfcommTestDisconnectRequest>(&header, _body_bytes, handles, &mut req)?;
354 let control_handle = RfcommTestControlHandle { inner: this.inner.clone() };
355 Ok(RfcommTestRequest::Disconnect { id: req.id, control_handle })
356 }
357 0x3689603441392637 => {
358 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
359 let mut req = fidl::new_empty!(
360 RfcommTestRemoteLineStatusRequest,
361 fidl::encoding::DefaultFuchsiaResourceDialect
362 );
363 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RfcommTestRemoteLineStatusRequest>(&header, _body_bytes, handles, &mut req)?;
364 let control_handle = RfcommTestControlHandle { inner: this.inner.clone() };
365 Ok(RfcommTestRequest::RemoteLineStatus {
366 id: req.id,
367 channel_number: req.channel_number,
368 status: req.status,
369
370 control_handle,
371 })
372 }
373 _ => Err(fidl::Error::UnknownOrdinal {
374 ordinal: header.ordinal,
375 protocol_name:
376 <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
377 }),
378 }))
379 },
380 )
381 }
382}
383
384#[derive(Debug)]
387pub enum RfcommTestRequest {
388 Disconnect { id: fidl_fuchsia_bluetooth::PeerId, control_handle: RfcommTestControlHandle },
394 RemoteLineStatus {
402 id: fidl_fuchsia_bluetooth::PeerId,
403 channel_number: u8,
404 status: Status,
405 control_handle: RfcommTestControlHandle,
406 },
407}
408
409impl RfcommTestRequest {
410 #[allow(irrefutable_let_patterns)]
411 pub fn into_disconnect(
412 self,
413 ) -> Option<(fidl_fuchsia_bluetooth::PeerId, RfcommTestControlHandle)> {
414 if let RfcommTestRequest::Disconnect { id, control_handle } = self {
415 Some((id, control_handle))
416 } else {
417 None
418 }
419 }
420
421 #[allow(irrefutable_let_patterns)]
422 pub fn into_remote_line_status(
423 self,
424 ) -> Option<(fidl_fuchsia_bluetooth::PeerId, u8, Status, RfcommTestControlHandle)> {
425 if let RfcommTestRequest::RemoteLineStatus { id, channel_number, status, control_handle } =
426 self
427 {
428 Some((id, channel_number, status, control_handle))
429 } else {
430 None
431 }
432 }
433
434 pub fn method_name(&self) -> &'static str {
436 match *self {
437 RfcommTestRequest::Disconnect { .. } => "disconnect",
438 RfcommTestRequest::RemoteLineStatus { .. } => "remote_line_status",
439 }
440 }
441}
442
443#[derive(Debug, Clone)]
444pub struct RfcommTestControlHandle {
445 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
446}
447
448impl fidl::endpoints::ControlHandle for RfcommTestControlHandle {
449 fn shutdown(&self) {
450 self.inner.shutdown()
451 }
452
453 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
454 self.inner.shutdown_with_epitaph(status)
455 }
456
457 fn is_closed(&self) -> bool {
458 self.inner.channel().is_closed()
459 }
460 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
461 self.inner.channel().on_closed()
462 }
463
464 #[cfg(target_os = "fuchsia")]
465 fn signal_peer(
466 &self,
467 clear_mask: zx::Signals,
468 set_mask: zx::Signals,
469 ) -> Result<(), zx_status::Status> {
470 use fidl::Peered;
471 self.inner.channel().signal_peer(clear_mask, set_mask)
472 }
473}
474
475impl RfcommTestControlHandle {}
476
477mod internal {
478 use super::*;
479}