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 _};
10use futures::future::{self, MaybeDone, TryFutureExt};
11use zx_status;
12
13pub type ChannelIndex = u16;
15
16pub type InterfaceName = String;
22
23pub type PowerDbm = i8;
33
34pub const MAX_LOWPAN_DEVICES: u32 = 8;
35
36#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
37pub struct DeviceWatcherWatchDevicesResponse {
38 pub added: Vec<String>,
39 pub removed: Vec<String>,
40}
41
42impl fidl::Persistable for DeviceWatcherWatchDevicesResponse {}
43
44#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
48#[repr(C)]
49pub struct MacAddress {
50 pub octets: [u8; 8],
51}
52
53impl fidl::Persistable for MacAddress {}
54
55#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
56pub struct DeviceWatcherMarker;
57
58impl fidl::endpoints::ProtocolMarker for DeviceWatcherMarker {
59 type Proxy = DeviceWatcherProxy;
60 type RequestStream = DeviceWatcherRequestStream;
61 #[cfg(target_os = "fuchsia")]
62 type SynchronousProxy = DeviceWatcherSynchronousProxy;
63
64 const DEBUG_NAME: &'static str = "fuchsia.lowpan.DeviceWatcher";
65}
66impl fidl::endpoints::DiscoverableProtocolMarker for DeviceWatcherMarker {}
67
68pub trait DeviceWatcherProxyInterface: Send + Sync {
69 type WatchDevicesResponseFut: std::future::Future<Output = Result<(Vec<String>, Vec<String>), fidl::Error>>
70 + Send;
71 fn r#watch_devices(&self) -> Self::WatchDevicesResponseFut;
72}
73#[derive(Debug)]
74#[cfg(target_os = "fuchsia")]
75pub struct DeviceWatcherSynchronousProxy {
76 client: fidl::client::sync::Client,
77}
78
79#[cfg(target_os = "fuchsia")]
80impl fidl::endpoints::SynchronousProxy for DeviceWatcherSynchronousProxy {
81 type Proxy = DeviceWatcherProxy;
82 type Protocol = DeviceWatcherMarker;
83
84 fn from_channel(inner: fidl::Channel) -> Self {
85 Self::new(inner)
86 }
87
88 fn into_channel(self) -> fidl::Channel {
89 self.client.into_channel()
90 }
91
92 fn as_channel(&self) -> &fidl::Channel {
93 self.client.as_channel()
94 }
95}
96
97#[cfg(target_os = "fuchsia")]
98impl DeviceWatcherSynchronousProxy {
99 pub fn new(channel: fidl::Channel) -> Self {
100 let protocol_name = <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
101 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
102 }
103
104 pub fn into_channel(self) -> fidl::Channel {
105 self.client.into_channel()
106 }
107
108 pub fn wait_for_event(
111 &self,
112 deadline: zx::MonotonicInstant,
113 ) -> Result<DeviceWatcherEvent, fidl::Error> {
114 DeviceWatcherEvent::decode(self.client.wait_for_event(deadline)?)
115 }
116
117 pub fn r#watch_devices(
140 &self,
141 ___deadline: zx::MonotonicInstant,
142 ) -> Result<(Vec<String>, Vec<String>), fidl::Error> {
143 let _response = self
144 .client
145 .send_query::<fidl::encoding::EmptyPayload, DeviceWatcherWatchDevicesResponse>(
146 (),
147 0x61e58136ee1f49b8,
148 fidl::encoding::DynamicFlags::empty(),
149 ___deadline,
150 )?;
151 Ok((_response.added, _response.removed))
152 }
153}
154
155#[derive(Debug, Clone)]
156pub struct DeviceWatcherProxy {
157 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
158}
159
160impl fidl::endpoints::Proxy for DeviceWatcherProxy {
161 type Protocol = DeviceWatcherMarker;
162
163 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
164 Self::new(inner)
165 }
166
167 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
168 self.client.into_channel().map_err(|client| Self { client })
169 }
170
171 fn as_channel(&self) -> &::fidl::AsyncChannel {
172 self.client.as_channel()
173 }
174}
175
176impl DeviceWatcherProxy {
177 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
179 let protocol_name = <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
180 Self { client: fidl::client::Client::new(channel, protocol_name) }
181 }
182
183 pub fn take_event_stream(&self) -> DeviceWatcherEventStream {
189 DeviceWatcherEventStream { event_receiver: self.client.take_event_receiver() }
190 }
191
192 pub fn r#watch_devices(
215 &self,
216 ) -> fidl::client::QueryResponseFut<
217 (Vec<String>, Vec<String>),
218 fidl::encoding::DefaultFuchsiaResourceDialect,
219 > {
220 DeviceWatcherProxyInterface::r#watch_devices(self)
221 }
222}
223
224impl DeviceWatcherProxyInterface for DeviceWatcherProxy {
225 type WatchDevicesResponseFut = fidl::client::QueryResponseFut<
226 (Vec<String>, Vec<String>),
227 fidl::encoding::DefaultFuchsiaResourceDialect,
228 >;
229 fn r#watch_devices(&self) -> Self::WatchDevicesResponseFut {
230 fn _decode(
231 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
232 ) -> Result<(Vec<String>, Vec<String>), fidl::Error> {
233 let _response = fidl::client::decode_transaction_body::<
234 DeviceWatcherWatchDevicesResponse,
235 fidl::encoding::DefaultFuchsiaResourceDialect,
236 0x61e58136ee1f49b8,
237 >(_buf?)?;
238 Ok((_response.added, _response.removed))
239 }
240 self.client
241 .send_query_and_decode::<fidl::encoding::EmptyPayload, (Vec<String>, Vec<String>)>(
242 (),
243 0x61e58136ee1f49b8,
244 fidl::encoding::DynamicFlags::empty(),
245 _decode,
246 )
247 }
248}
249
250pub struct DeviceWatcherEventStream {
251 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
252}
253
254impl std::marker::Unpin for DeviceWatcherEventStream {}
255
256impl futures::stream::FusedStream for DeviceWatcherEventStream {
257 fn is_terminated(&self) -> bool {
258 self.event_receiver.is_terminated()
259 }
260}
261
262impl futures::Stream for DeviceWatcherEventStream {
263 type Item = Result<DeviceWatcherEvent, fidl::Error>;
264
265 fn poll_next(
266 mut self: std::pin::Pin<&mut Self>,
267 cx: &mut std::task::Context<'_>,
268 ) -> std::task::Poll<Option<Self::Item>> {
269 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
270 &mut self.event_receiver,
271 cx
272 )?) {
273 Some(buf) => std::task::Poll::Ready(Some(DeviceWatcherEvent::decode(buf))),
274 None => std::task::Poll::Ready(None),
275 }
276 }
277}
278
279#[derive(Debug)]
280pub enum DeviceWatcherEvent {}
281
282impl DeviceWatcherEvent {
283 fn decode(
285 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
286 ) -> Result<DeviceWatcherEvent, fidl::Error> {
287 let (bytes, _handles) = buf.split_mut();
288 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
289 debug_assert_eq!(tx_header.tx_id, 0);
290 match tx_header.ordinal {
291 _ => Err(fidl::Error::UnknownOrdinal {
292 ordinal: tx_header.ordinal,
293 protocol_name: <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
294 }),
295 }
296 }
297}
298
299pub struct DeviceWatcherRequestStream {
301 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
302 is_terminated: bool,
303}
304
305impl std::marker::Unpin for DeviceWatcherRequestStream {}
306
307impl futures::stream::FusedStream for DeviceWatcherRequestStream {
308 fn is_terminated(&self) -> bool {
309 self.is_terminated
310 }
311}
312
313impl fidl::endpoints::RequestStream for DeviceWatcherRequestStream {
314 type Protocol = DeviceWatcherMarker;
315 type ControlHandle = DeviceWatcherControlHandle;
316
317 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
318 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
319 }
320
321 fn control_handle(&self) -> Self::ControlHandle {
322 DeviceWatcherControlHandle { inner: self.inner.clone() }
323 }
324
325 fn into_inner(
326 self,
327 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
328 {
329 (self.inner, self.is_terminated)
330 }
331
332 fn from_inner(
333 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
334 is_terminated: bool,
335 ) -> Self {
336 Self { inner, is_terminated }
337 }
338}
339
340impl futures::Stream for DeviceWatcherRequestStream {
341 type Item = Result<DeviceWatcherRequest, fidl::Error>;
342
343 fn poll_next(
344 mut self: std::pin::Pin<&mut Self>,
345 cx: &mut std::task::Context<'_>,
346 ) -> std::task::Poll<Option<Self::Item>> {
347 let this = &mut *self;
348 if this.inner.check_shutdown(cx) {
349 this.is_terminated = true;
350 return std::task::Poll::Ready(None);
351 }
352 if this.is_terminated {
353 panic!("polled DeviceWatcherRequestStream after completion");
354 }
355 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
356 |bytes, handles| {
357 match this.inner.channel().read_etc(cx, bytes, handles) {
358 std::task::Poll::Ready(Ok(())) => {}
359 std::task::Poll::Pending => return std::task::Poll::Pending,
360 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
361 this.is_terminated = true;
362 return std::task::Poll::Ready(None);
363 }
364 std::task::Poll::Ready(Err(e)) => {
365 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
366 e.into(),
367 ))))
368 }
369 }
370
371 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
373
374 std::task::Poll::Ready(Some(match header.ordinal {
375 0x61e58136ee1f49b8 => {
376 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
377 let mut req = fidl::new_empty!(
378 fidl::encoding::EmptyPayload,
379 fidl::encoding::DefaultFuchsiaResourceDialect
380 );
381 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
382 let control_handle =
383 DeviceWatcherControlHandle { inner: this.inner.clone() };
384 Ok(DeviceWatcherRequest::WatchDevices {
385 responder: DeviceWatcherWatchDevicesResponder {
386 control_handle: std::mem::ManuallyDrop::new(control_handle),
387 tx_id: header.tx_id,
388 },
389 })
390 }
391 _ => Err(fidl::Error::UnknownOrdinal {
392 ordinal: header.ordinal,
393 protocol_name:
394 <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
395 }),
396 }))
397 },
398 )
399 }
400}
401
402#[derive(Debug)]
405pub enum DeviceWatcherRequest {
406 WatchDevices { responder: DeviceWatcherWatchDevicesResponder },
429}
430
431impl DeviceWatcherRequest {
432 #[allow(irrefutable_let_patterns)]
433 pub fn into_watch_devices(self) -> Option<(DeviceWatcherWatchDevicesResponder)> {
434 if let DeviceWatcherRequest::WatchDevices { responder } = self {
435 Some((responder))
436 } else {
437 None
438 }
439 }
440
441 pub fn method_name(&self) -> &'static str {
443 match *self {
444 DeviceWatcherRequest::WatchDevices { .. } => "watch_devices",
445 }
446 }
447}
448
449#[derive(Debug, Clone)]
450pub struct DeviceWatcherControlHandle {
451 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
452}
453
454impl fidl::endpoints::ControlHandle for DeviceWatcherControlHandle {
455 fn shutdown(&self) {
456 self.inner.shutdown()
457 }
458 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
459 self.inner.shutdown_with_epitaph(status)
460 }
461
462 fn is_closed(&self) -> bool {
463 self.inner.channel().is_closed()
464 }
465 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
466 self.inner.channel().on_closed()
467 }
468
469 #[cfg(target_os = "fuchsia")]
470 fn signal_peer(
471 &self,
472 clear_mask: zx::Signals,
473 set_mask: zx::Signals,
474 ) -> Result<(), zx_status::Status> {
475 use fidl::Peered;
476 self.inner.channel().signal_peer(clear_mask, set_mask)
477 }
478}
479
480impl DeviceWatcherControlHandle {}
481
482#[must_use = "FIDL methods require a response to be sent"]
483#[derive(Debug)]
484pub struct DeviceWatcherWatchDevicesResponder {
485 control_handle: std::mem::ManuallyDrop<DeviceWatcherControlHandle>,
486 tx_id: u32,
487}
488
489impl std::ops::Drop for DeviceWatcherWatchDevicesResponder {
493 fn drop(&mut self) {
494 self.control_handle.shutdown();
495 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
497 }
498}
499
500impl fidl::endpoints::Responder for DeviceWatcherWatchDevicesResponder {
501 type ControlHandle = DeviceWatcherControlHandle;
502
503 fn control_handle(&self) -> &DeviceWatcherControlHandle {
504 &self.control_handle
505 }
506
507 fn drop_without_shutdown(mut self) {
508 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
510 std::mem::forget(self);
512 }
513}
514
515impl DeviceWatcherWatchDevicesResponder {
516 pub fn send(self, mut added: &[String], mut removed: &[String]) -> Result<(), fidl::Error> {
520 let _result = self.send_raw(added, removed);
521 if _result.is_err() {
522 self.control_handle.shutdown();
523 }
524 self.drop_without_shutdown();
525 _result
526 }
527
528 pub fn send_no_shutdown_on_err(
530 self,
531 mut added: &[String],
532 mut removed: &[String],
533 ) -> Result<(), fidl::Error> {
534 let _result = self.send_raw(added, removed);
535 self.drop_without_shutdown();
536 _result
537 }
538
539 fn send_raw(&self, mut added: &[String], mut removed: &[String]) -> Result<(), fidl::Error> {
540 self.control_handle.inner.send::<DeviceWatcherWatchDevicesResponse>(
541 (added, removed),
542 self.tx_id,
543 0x61e58136ee1f49b8,
544 fidl::encoding::DynamicFlags::empty(),
545 )
546 }
547}
548
549mod internal {
550 use super::*;
551
552 impl fidl::encoding::ValueTypeMarker for DeviceWatcherWatchDevicesResponse {
553 type Borrowed<'a> = &'a Self;
554 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
555 value
556 }
557 }
558
559 unsafe impl fidl::encoding::TypeMarker for DeviceWatcherWatchDevicesResponse {
560 type Owned = Self;
561
562 #[inline(always)]
563 fn inline_align(_context: fidl::encoding::Context) -> usize {
564 8
565 }
566
567 #[inline(always)]
568 fn inline_size(_context: fidl::encoding::Context) -> usize {
569 32
570 }
571 }
572
573 unsafe impl<D: fidl::encoding::ResourceDialect>
574 fidl::encoding::Encode<DeviceWatcherWatchDevicesResponse, D>
575 for &DeviceWatcherWatchDevicesResponse
576 {
577 #[inline]
578 unsafe fn encode(
579 self,
580 encoder: &mut fidl::encoding::Encoder<'_, D>,
581 offset: usize,
582 _depth: fidl::encoding::Depth,
583 ) -> fidl::Result<()> {
584 encoder.debug_check_bounds::<DeviceWatcherWatchDevicesResponse>(offset);
585 fidl::encoding::Encode::<DeviceWatcherWatchDevicesResponse, D>::encode(
587 (
588 <fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8> as fidl::encoding::ValueTypeMarker>::borrow(&self.added),
589 <fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8> as fidl::encoding::ValueTypeMarker>::borrow(&self.removed),
590 ),
591 encoder, offset, _depth
592 )
593 }
594 }
595 unsafe impl<
596 D: fidl::encoding::ResourceDialect,
597 T0: fidl::encoding::Encode<fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>, D>,
598 T1: fidl::encoding::Encode<fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>, D>,
599 > fidl::encoding::Encode<DeviceWatcherWatchDevicesResponse, D> for (T0, T1)
600 {
601 #[inline]
602 unsafe fn encode(
603 self,
604 encoder: &mut fidl::encoding::Encoder<'_, D>,
605 offset: usize,
606 depth: fidl::encoding::Depth,
607 ) -> fidl::Result<()> {
608 encoder.debug_check_bounds::<DeviceWatcherWatchDevicesResponse>(offset);
609 self.0.encode(encoder, offset + 0, depth)?;
613 self.1.encode(encoder, offset + 16, depth)?;
614 Ok(())
615 }
616 }
617
618 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
619 for DeviceWatcherWatchDevicesResponse
620 {
621 #[inline(always)]
622 fn new_empty() -> Self {
623 Self {
624 added: fidl::new_empty!(
625 fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>,
626 D
627 ),
628 removed: fidl::new_empty!(
629 fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>,
630 D
631 ),
632 }
633 }
634
635 #[inline]
636 unsafe fn decode(
637 &mut self,
638 decoder: &mut fidl::encoding::Decoder<'_, D>,
639 offset: usize,
640 _depth: fidl::encoding::Depth,
641 ) -> fidl::Result<()> {
642 decoder.debug_check_bounds::<Self>(offset);
643 fidl::decode!(
645 fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>,
646 D,
647 &mut self.added,
648 decoder,
649 offset + 0,
650 _depth
651 )?;
652 fidl::decode!(
653 fidl::encoding::Vector<fidl::encoding::BoundedString<32>, 8>,
654 D,
655 &mut self.removed,
656 decoder,
657 offset + 16,
658 _depth
659 )?;
660 Ok(())
661 }
662 }
663
664 impl fidl::encoding::ValueTypeMarker for MacAddress {
665 type Borrowed<'a> = &'a Self;
666 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
667 value
668 }
669 }
670
671 unsafe impl fidl::encoding::TypeMarker for MacAddress {
672 type Owned = Self;
673
674 #[inline(always)]
675 fn inline_align(_context: fidl::encoding::Context) -> usize {
676 1
677 }
678
679 #[inline(always)]
680 fn inline_size(_context: fidl::encoding::Context) -> usize {
681 8
682 }
683 #[inline(always)]
684 fn encode_is_copy() -> bool {
685 true
686 }
687
688 #[inline(always)]
689 fn decode_is_copy() -> bool {
690 true
691 }
692 }
693
694 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<MacAddress, D>
695 for &MacAddress
696 {
697 #[inline]
698 unsafe fn encode(
699 self,
700 encoder: &mut fidl::encoding::Encoder<'_, D>,
701 offset: usize,
702 _depth: fidl::encoding::Depth,
703 ) -> fidl::Result<()> {
704 encoder.debug_check_bounds::<MacAddress>(offset);
705 unsafe {
706 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
708 (buf_ptr as *mut MacAddress).write_unaligned((self as *const MacAddress).read());
709 }
712 Ok(())
713 }
714 }
715 unsafe impl<
716 D: fidl::encoding::ResourceDialect,
717 T0: fidl::encoding::Encode<fidl::encoding::Array<u8, 8>, D>,
718 > fidl::encoding::Encode<MacAddress, D> for (T0,)
719 {
720 #[inline]
721 unsafe fn encode(
722 self,
723 encoder: &mut fidl::encoding::Encoder<'_, D>,
724 offset: usize,
725 depth: fidl::encoding::Depth,
726 ) -> fidl::Result<()> {
727 encoder.debug_check_bounds::<MacAddress>(offset);
728 self.0.encode(encoder, offset + 0, depth)?;
732 Ok(())
733 }
734 }
735
736 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for MacAddress {
737 #[inline(always)]
738 fn new_empty() -> Self {
739 Self { octets: fidl::new_empty!(fidl::encoding::Array<u8, 8>, D) }
740 }
741
742 #[inline]
743 unsafe fn decode(
744 &mut self,
745 decoder: &mut fidl::encoding::Decoder<'_, D>,
746 offset: usize,
747 _depth: fidl::encoding::Depth,
748 ) -> fidl::Result<()> {
749 decoder.debug_check_bounds::<Self>(offset);
750 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
751 unsafe {
754 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 8);
755 }
756 Ok(())
757 }
758 }
759}