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 let protocol_name = <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
64 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
65 }
66
67 pub fn into_channel(self) -> fidl::Channel {
68 self.client.into_channel()
69 }
70
71 pub fn wait_for_event(
74 &self,
75 deadline: zx::MonotonicInstant,
76 ) -> Result<RfcommTestEvent, fidl::Error> {
77 RfcommTestEvent::decode(self.client.wait_for_event(deadline)?)
78 }
79
80 pub fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
86 self.client.send::<RfcommTestDisconnectRequest>(
87 (id,),
88 0x6173bb03e37ddddf,
89 fidl::encoding::DynamicFlags::empty(),
90 )
91 }
92
93 pub fn r#remote_line_status(
101 &self,
102 mut id: &fidl_fuchsia_bluetooth::PeerId,
103 mut channel_number: u8,
104 mut status: Status,
105 ) -> Result<(), fidl::Error> {
106 self.client.send::<RfcommTestRemoteLineStatusRequest>(
107 (id, channel_number, status),
108 0x3689603441392637,
109 fidl::encoding::DynamicFlags::empty(),
110 )
111 }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl From<RfcommTestSynchronousProxy> for zx::Handle {
116 fn from(value: RfcommTestSynchronousProxy) -> Self {
117 value.into_channel().into()
118 }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl From<fidl::Channel> for RfcommTestSynchronousProxy {
123 fn from(value: fidl::Channel) -> Self {
124 Self::new(value)
125 }
126}
127
128#[cfg(target_os = "fuchsia")]
129impl fidl::endpoints::FromClient for RfcommTestSynchronousProxy {
130 type Protocol = RfcommTestMarker;
131
132 fn from_client(value: fidl::endpoints::ClientEnd<RfcommTestMarker>) -> Self {
133 Self::new(value.into_channel())
134 }
135}
136
137#[derive(Debug, Clone)]
138pub struct RfcommTestProxy {
139 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
140}
141
142impl fidl::endpoints::Proxy for RfcommTestProxy {
143 type Protocol = RfcommTestMarker;
144
145 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
146 Self::new(inner)
147 }
148
149 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
150 self.client.into_channel().map_err(|client| Self { client })
151 }
152
153 fn as_channel(&self) -> &::fidl::AsyncChannel {
154 self.client.as_channel()
155 }
156}
157
158impl RfcommTestProxy {
159 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
161 let protocol_name = <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
162 Self { client: fidl::client::Client::new(channel, protocol_name) }
163 }
164
165 pub fn take_event_stream(&self) -> RfcommTestEventStream {
171 RfcommTestEventStream { event_receiver: self.client.take_event_receiver() }
172 }
173
174 pub fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
180 RfcommTestProxyInterface::r#disconnect(self, id)
181 }
182
183 pub fn r#remote_line_status(
191 &self,
192 mut id: &fidl_fuchsia_bluetooth::PeerId,
193 mut channel_number: u8,
194 mut status: Status,
195 ) -> Result<(), fidl::Error> {
196 RfcommTestProxyInterface::r#remote_line_status(self, id, channel_number, status)
197 }
198}
199
200impl RfcommTestProxyInterface for RfcommTestProxy {
201 fn r#disconnect(&self, mut id: &fidl_fuchsia_bluetooth::PeerId) -> Result<(), fidl::Error> {
202 self.client.send::<RfcommTestDisconnectRequest>(
203 (id,),
204 0x6173bb03e37ddddf,
205 fidl::encoding::DynamicFlags::empty(),
206 )
207 }
208
209 fn r#remote_line_status(
210 &self,
211 mut id: &fidl_fuchsia_bluetooth::PeerId,
212 mut channel_number: u8,
213 mut status: Status,
214 ) -> Result<(), fidl::Error> {
215 self.client.send::<RfcommTestRemoteLineStatusRequest>(
216 (id, channel_number, status),
217 0x3689603441392637,
218 fidl::encoding::DynamicFlags::empty(),
219 )
220 }
221}
222
223pub struct RfcommTestEventStream {
224 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
225}
226
227impl std::marker::Unpin for RfcommTestEventStream {}
228
229impl futures::stream::FusedStream for RfcommTestEventStream {
230 fn is_terminated(&self) -> bool {
231 self.event_receiver.is_terminated()
232 }
233}
234
235impl futures::Stream for RfcommTestEventStream {
236 type Item = Result<RfcommTestEvent, fidl::Error>;
237
238 fn poll_next(
239 mut self: std::pin::Pin<&mut Self>,
240 cx: &mut std::task::Context<'_>,
241 ) -> std::task::Poll<Option<Self::Item>> {
242 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
243 &mut self.event_receiver,
244 cx
245 )?) {
246 Some(buf) => std::task::Poll::Ready(Some(RfcommTestEvent::decode(buf))),
247 None => std::task::Poll::Ready(None),
248 }
249 }
250}
251
252#[derive(Debug)]
253pub enum RfcommTestEvent {}
254
255impl RfcommTestEvent {
256 fn decode(
258 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
259 ) -> Result<RfcommTestEvent, fidl::Error> {
260 let (bytes, _handles) = buf.split_mut();
261 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
262 debug_assert_eq!(tx_header.tx_id, 0);
263 match tx_header.ordinal {
264 _ => Err(fidl::Error::UnknownOrdinal {
265 ordinal: tx_header.ordinal,
266 protocol_name: <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
267 }),
268 }
269 }
270}
271
272pub struct RfcommTestRequestStream {
274 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
275 is_terminated: bool,
276}
277
278impl std::marker::Unpin for RfcommTestRequestStream {}
279
280impl futures::stream::FusedStream for RfcommTestRequestStream {
281 fn is_terminated(&self) -> bool {
282 self.is_terminated
283 }
284}
285
286impl fidl::endpoints::RequestStream for RfcommTestRequestStream {
287 type Protocol = RfcommTestMarker;
288 type ControlHandle = RfcommTestControlHandle;
289
290 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
291 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
292 }
293
294 fn control_handle(&self) -> Self::ControlHandle {
295 RfcommTestControlHandle { inner: self.inner.clone() }
296 }
297
298 fn into_inner(
299 self,
300 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
301 {
302 (self.inner, self.is_terminated)
303 }
304
305 fn from_inner(
306 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
307 is_terminated: bool,
308 ) -> Self {
309 Self { inner, is_terminated }
310 }
311}
312
313impl futures::Stream for RfcommTestRequestStream {
314 type Item = Result<RfcommTestRequest, fidl::Error>;
315
316 fn poll_next(
317 mut self: std::pin::Pin<&mut Self>,
318 cx: &mut std::task::Context<'_>,
319 ) -> std::task::Poll<Option<Self::Item>> {
320 let this = &mut *self;
321 if this.inner.check_shutdown(cx) {
322 this.is_terminated = true;
323 return std::task::Poll::Ready(None);
324 }
325 if this.is_terminated {
326 panic!("polled RfcommTestRequestStream after completion");
327 }
328 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
329 |bytes, handles| {
330 match this.inner.channel().read_etc(cx, bytes, handles) {
331 std::task::Poll::Ready(Ok(())) => {}
332 std::task::Poll::Pending => return std::task::Poll::Pending,
333 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
334 this.is_terminated = true;
335 return std::task::Poll::Ready(None);
336 }
337 std::task::Poll::Ready(Err(e)) => {
338 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
339 e.into(),
340 ))))
341 }
342 }
343
344 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
346
347 std::task::Poll::Ready(Some(match header.ordinal {
348 0x6173bb03e37ddddf => {
349 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
350 let mut req = fidl::new_empty!(
351 RfcommTestDisconnectRequest,
352 fidl::encoding::DefaultFuchsiaResourceDialect
353 );
354 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RfcommTestDisconnectRequest>(&header, _body_bytes, handles, &mut req)?;
355 let control_handle = RfcommTestControlHandle { inner: this.inner.clone() };
356 Ok(RfcommTestRequest::Disconnect { id: req.id, control_handle })
357 }
358 0x3689603441392637 => {
359 header.validate_request_tx_id(fidl::MethodType::OneWay)?;
360 let mut req = fidl::new_empty!(
361 RfcommTestRemoteLineStatusRequest,
362 fidl::encoding::DefaultFuchsiaResourceDialect
363 );
364 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<RfcommTestRemoteLineStatusRequest>(&header, _body_bytes, handles, &mut req)?;
365 let control_handle = RfcommTestControlHandle { inner: this.inner.clone() };
366 Ok(RfcommTestRequest::RemoteLineStatus {
367 id: req.id,
368 channel_number: req.channel_number,
369 status: req.status,
370
371 control_handle,
372 })
373 }
374 _ => Err(fidl::Error::UnknownOrdinal {
375 ordinal: header.ordinal,
376 protocol_name:
377 <RfcommTestMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
378 }),
379 }))
380 },
381 )
382 }
383}
384
385#[derive(Debug)]
388pub enum RfcommTestRequest {
389 Disconnect { id: fidl_fuchsia_bluetooth::PeerId, control_handle: RfcommTestControlHandle },
395 RemoteLineStatus {
403 id: fidl_fuchsia_bluetooth::PeerId,
404 channel_number: u8,
405 status: Status,
406 control_handle: RfcommTestControlHandle,
407 },
408}
409
410impl RfcommTestRequest {
411 #[allow(irrefutable_let_patterns)]
412 pub fn into_disconnect(
413 self,
414 ) -> Option<(fidl_fuchsia_bluetooth::PeerId, RfcommTestControlHandle)> {
415 if let RfcommTestRequest::Disconnect { id, control_handle } = self {
416 Some((id, control_handle))
417 } else {
418 None
419 }
420 }
421
422 #[allow(irrefutable_let_patterns)]
423 pub fn into_remote_line_status(
424 self,
425 ) -> Option<(fidl_fuchsia_bluetooth::PeerId, u8, Status, RfcommTestControlHandle)> {
426 if let RfcommTestRequest::RemoteLineStatus { id, channel_number, status, control_handle } =
427 self
428 {
429 Some((id, channel_number, status, control_handle))
430 } else {
431 None
432 }
433 }
434
435 pub fn method_name(&self) -> &'static str {
437 match *self {
438 RfcommTestRequest::Disconnect { .. } => "disconnect",
439 RfcommTestRequest::RemoteLineStatus { .. } => "remote_line_status",
440 }
441 }
442}
443
444#[derive(Debug, Clone)]
445pub struct RfcommTestControlHandle {
446 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
447}
448
449impl fidl::endpoints::ControlHandle for RfcommTestControlHandle {
450 fn shutdown(&self) {
451 self.inner.shutdown()
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}