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_lowpan__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceWatcherMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceWatcherMarker {
18 type Proxy = DeviceWatcherProxy;
19 type RequestStream = DeviceWatcherRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = DeviceWatcherSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.lowpan.DeviceWatcher";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceWatcherMarker {}
26
27pub trait DeviceWatcherProxyInterface: Send + Sync {
28 type WatchDevicesResponseFut: std::future::Future<Output = Result<(Vec<String>, Vec<String>), fidl::Error>>
29 + Send;
30 fn r#watch_devices(&self) -> Self::WatchDevicesResponseFut;
31}
32#[derive(Debug)]
33#[cfg(target_os = "fuchsia")]
34pub struct DeviceWatcherSynchronousProxy {
35 client: fidl::client::sync::Client,
36}
37
38#[cfg(target_os = "fuchsia")]
39impl fidl::endpoints::SynchronousProxy for DeviceWatcherSynchronousProxy {
40 type Proxy = DeviceWatcherProxy;
41 type Protocol = DeviceWatcherMarker;
42
43 fn from_channel(inner: fidl::Channel) -> Self {
44 Self::new(inner)
45 }
46
47 fn into_channel(self) -> fidl::Channel {
48 self.client.into_channel()
49 }
50
51 fn as_channel(&self) -> &fidl::Channel {
52 self.client.as_channel()
53 }
54}
55
56#[cfg(target_os = "fuchsia")]
57impl DeviceWatcherSynchronousProxy {
58 pub fn new(channel: fidl::Channel) -> Self {
59 Self { client: fidl::client::sync::Client::new(channel) }
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<DeviceWatcherEvent, fidl::Error> {
72 DeviceWatcherEvent::decode(self.client.wait_for_event::<DeviceWatcherMarker>(deadline)?)
73 }
74
75 pub fn r#watch_devices(
98 &self,
99 ___deadline: zx::MonotonicInstant,
100 ) -> Result<(Vec<String>, Vec<String>), fidl::Error> {
101 let _response = self.client.send_query::<
102 fidl::encoding::EmptyPayload,
103 DeviceWatcherWatchDevicesResponse,
104 DeviceWatcherMarker,
105 >(
106 (),
107 0x61e58136ee1f49b8,
108 fidl::encoding::DynamicFlags::empty(),
109 ___deadline,
110 )?;
111 Ok((_response.added, _response.removed))
112 }
113}
114
115#[cfg(target_os = "fuchsia")]
116impl From<DeviceWatcherSynchronousProxy> for zx::NullableHandle {
117 fn from(value: DeviceWatcherSynchronousProxy) -> Self {
118 value.into_channel().into()
119 }
120}
121
122#[cfg(target_os = "fuchsia")]
123impl From<fidl::Channel> for DeviceWatcherSynchronousProxy {
124 fn from(value: fidl::Channel) -> Self {
125 Self::new(value)
126 }
127}
128
129#[cfg(target_os = "fuchsia")]
130impl fidl::endpoints::FromClient for DeviceWatcherSynchronousProxy {
131 type Protocol = DeviceWatcherMarker;
132
133 fn from_client(value: fidl::endpoints::ClientEnd<DeviceWatcherMarker>) -> Self {
134 Self::new(value.into_channel())
135 }
136}
137
138#[derive(Debug, Clone)]
139pub struct DeviceWatcherProxy {
140 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
141}
142
143impl fidl::endpoints::Proxy for DeviceWatcherProxy {
144 type Protocol = DeviceWatcherMarker;
145
146 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
147 Self::new(inner)
148 }
149
150 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
151 self.client.into_channel().map_err(|client| Self { client })
152 }
153
154 fn as_channel(&self) -> &::fidl::AsyncChannel {
155 self.client.as_channel()
156 }
157}
158
159impl DeviceWatcherProxy {
160 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
162 let protocol_name = <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
163 Self { client: fidl::client::Client::new(channel, protocol_name) }
164 }
165
166 pub fn take_event_stream(&self) -> DeviceWatcherEventStream {
172 DeviceWatcherEventStream { event_receiver: self.client.take_event_receiver() }
173 }
174
175 pub fn r#watch_devices(
198 &self,
199 ) -> fidl::client::QueryResponseFut<
200 (Vec<String>, Vec<String>),
201 fidl::encoding::DefaultFuchsiaResourceDialect,
202 > {
203 DeviceWatcherProxyInterface::r#watch_devices(self)
204 }
205}
206
207impl DeviceWatcherProxyInterface for DeviceWatcherProxy {
208 type WatchDevicesResponseFut = fidl::client::QueryResponseFut<
209 (Vec<String>, Vec<String>),
210 fidl::encoding::DefaultFuchsiaResourceDialect,
211 >;
212 fn r#watch_devices(&self) -> Self::WatchDevicesResponseFut {
213 fn _decode(
214 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
215 ) -> Result<(Vec<String>, Vec<String>), fidl::Error> {
216 let _response = fidl::client::decode_transaction_body::<
217 DeviceWatcherWatchDevicesResponse,
218 fidl::encoding::DefaultFuchsiaResourceDialect,
219 0x61e58136ee1f49b8,
220 >(_buf?)?;
221 Ok((_response.added, _response.removed))
222 }
223 self.client
224 .send_query_and_decode::<fidl::encoding::EmptyPayload, (Vec<String>, Vec<String>)>(
225 (),
226 0x61e58136ee1f49b8,
227 fidl::encoding::DynamicFlags::empty(),
228 _decode,
229 )
230 }
231}
232
233pub struct DeviceWatcherEventStream {
234 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
235}
236
237impl std::marker::Unpin for DeviceWatcherEventStream {}
238
239impl futures::stream::FusedStream for DeviceWatcherEventStream {
240 fn is_terminated(&self) -> bool {
241 self.event_receiver.is_terminated()
242 }
243}
244
245impl futures::Stream for DeviceWatcherEventStream {
246 type Item = Result<DeviceWatcherEvent, fidl::Error>;
247
248 fn poll_next(
249 mut self: std::pin::Pin<&mut Self>,
250 cx: &mut std::task::Context<'_>,
251 ) -> std::task::Poll<Option<Self::Item>> {
252 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
253 &mut self.event_receiver,
254 cx
255 )?) {
256 Some(buf) => std::task::Poll::Ready(Some(DeviceWatcherEvent::decode(buf))),
257 None => std::task::Poll::Ready(None),
258 }
259 }
260}
261
262#[derive(Debug)]
263pub enum DeviceWatcherEvent {}
264
265impl DeviceWatcherEvent {
266 fn decode(
268 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
269 ) -> Result<DeviceWatcherEvent, fidl::Error> {
270 let (bytes, _handles) = buf.split_mut();
271 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
272 debug_assert_eq!(tx_header.tx_id, 0);
273 match tx_header.ordinal {
274 _ => Err(fidl::Error::UnknownOrdinal {
275 ordinal: tx_header.ordinal,
276 protocol_name: <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
277 }),
278 }
279 }
280}
281
282pub struct DeviceWatcherRequestStream {
284 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
285 is_terminated: bool,
286}
287
288impl std::marker::Unpin for DeviceWatcherRequestStream {}
289
290impl futures::stream::FusedStream for DeviceWatcherRequestStream {
291 fn is_terminated(&self) -> bool {
292 self.is_terminated
293 }
294}
295
296impl fidl::endpoints::RequestStream for DeviceWatcherRequestStream {
297 type Protocol = DeviceWatcherMarker;
298 type ControlHandle = DeviceWatcherControlHandle;
299
300 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
301 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
302 }
303
304 fn control_handle(&self) -> Self::ControlHandle {
305 DeviceWatcherControlHandle { inner: self.inner.clone() }
306 }
307
308 fn into_inner(
309 self,
310 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
311 {
312 (self.inner, self.is_terminated)
313 }
314
315 fn from_inner(
316 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
317 is_terminated: bool,
318 ) -> Self {
319 Self { inner, is_terminated }
320 }
321}
322
323impl futures::Stream for DeviceWatcherRequestStream {
324 type Item = Result<DeviceWatcherRequest, fidl::Error>;
325
326 fn poll_next(
327 mut self: std::pin::Pin<&mut Self>,
328 cx: &mut std::task::Context<'_>,
329 ) -> std::task::Poll<Option<Self::Item>> {
330 let this = &mut *self;
331 if this.inner.check_shutdown(cx) {
332 this.is_terminated = true;
333 return std::task::Poll::Ready(None);
334 }
335 if this.is_terminated {
336 panic!("polled DeviceWatcherRequestStream after completion");
337 }
338 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
339 |bytes, handles| {
340 match this.inner.channel().read_etc(cx, bytes, handles) {
341 std::task::Poll::Ready(Ok(())) => {}
342 std::task::Poll::Pending => return std::task::Poll::Pending,
343 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
344 this.is_terminated = true;
345 return std::task::Poll::Ready(None);
346 }
347 std::task::Poll::Ready(Err(e)) => {
348 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
349 e.into(),
350 ))));
351 }
352 }
353
354 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
356
357 std::task::Poll::Ready(Some(match header.ordinal {
358 0x61e58136ee1f49b8 => {
359 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
360 let mut req = fidl::new_empty!(
361 fidl::encoding::EmptyPayload,
362 fidl::encoding::DefaultFuchsiaResourceDialect
363 );
364 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
365 let control_handle =
366 DeviceWatcherControlHandle { inner: this.inner.clone() };
367 Ok(DeviceWatcherRequest::WatchDevices {
368 responder: DeviceWatcherWatchDevicesResponder {
369 control_handle: std::mem::ManuallyDrop::new(control_handle),
370 tx_id: header.tx_id,
371 },
372 })
373 }
374 _ => Err(fidl::Error::UnknownOrdinal {
375 ordinal: header.ordinal,
376 protocol_name:
377 <DeviceWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
378 }),
379 }))
380 },
381 )
382 }
383}
384
385#[derive(Debug)]
388pub enum DeviceWatcherRequest {
389 WatchDevices { responder: DeviceWatcherWatchDevicesResponder },
412}
413
414impl DeviceWatcherRequest {
415 #[allow(irrefutable_let_patterns)]
416 pub fn into_watch_devices(self) -> Option<(DeviceWatcherWatchDevicesResponder)> {
417 if let DeviceWatcherRequest::WatchDevices { responder } = self {
418 Some((responder))
419 } else {
420 None
421 }
422 }
423
424 pub fn method_name(&self) -> &'static str {
426 match *self {
427 DeviceWatcherRequest::WatchDevices { .. } => "watch_devices",
428 }
429 }
430}
431
432#[derive(Debug, Clone)]
433pub struct DeviceWatcherControlHandle {
434 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
435}
436
437impl fidl::endpoints::ControlHandle for DeviceWatcherControlHandle {
438 fn shutdown(&self) {
439 self.inner.shutdown()
440 }
441
442 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
443 self.inner.shutdown_with_epitaph(status)
444 }
445
446 fn is_closed(&self) -> bool {
447 self.inner.channel().is_closed()
448 }
449 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
450 self.inner.channel().on_closed()
451 }
452
453 #[cfg(target_os = "fuchsia")]
454 fn signal_peer(
455 &self,
456 clear_mask: zx::Signals,
457 set_mask: zx::Signals,
458 ) -> Result<(), zx_status::Status> {
459 use fidl::Peered;
460 self.inner.channel().signal_peer(clear_mask, set_mask)
461 }
462}
463
464impl DeviceWatcherControlHandle {}
465
466#[must_use = "FIDL methods require a response to be sent"]
467#[derive(Debug)]
468pub struct DeviceWatcherWatchDevicesResponder {
469 control_handle: std::mem::ManuallyDrop<DeviceWatcherControlHandle>,
470 tx_id: u32,
471}
472
473impl std::ops::Drop for DeviceWatcherWatchDevicesResponder {
477 fn drop(&mut self) {
478 self.control_handle.shutdown();
479 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
481 }
482}
483
484impl fidl::endpoints::Responder for DeviceWatcherWatchDevicesResponder {
485 type ControlHandle = DeviceWatcherControlHandle;
486
487 fn control_handle(&self) -> &DeviceWatcherControlHandle {
488 &self.control_handle
489 }
490
491 fn drop_without_shutdown(mut self) {
492 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
494 std::mem::forget(self);
496 }
497}
498
499impl DeviceWatcherWatchDevicesResponder {
500 pub fn send(self, mut added: &[String], mut removed: &[String]) -> Result<(), fidl::Error> {
504 let _result = self.send_raw(added, removed);
505 if _result.is_err() {
506 self.control_handle.shutdown();
507 }
508 self.drop_without_shutdown();
509 _result
510 }
511
512 pub fn send_no_shutdown_on_err(
514 self,
515 mut added: &[String],
516 mut removed: &[String],
517 ) -> Result<(), fidl::Error> {
518 let _result = self.send_raw(added, removed);
519 self.drop_without_shutdown();
520 _result
521 }
522
523 fn send_raw(&self, mut added: &[String], mut removed: &[String]) -> Result<(), fidl::Error> {
524 self.control_handle.inner.send::<DeviceWatcherWatchDevicesResponse>(
525 (added, removed),
526 self.tx_id,
527 0x61e58136ee1f49b8,
528 fidl::encoding::DynamicFlags::empty(),
529 )
530 }
531}
532
533mod internal {
534 use super::*;
535}