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_hardware_usb_policy_common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct ControllerMarker;
16
17impl fidl::endpoints::ProtocolMarker for ControllerMarker {
18 type Proxy = ControllerProxy;
19 type RequestStream = ControllerRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = ControllerSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "(anonymous) Controller";
24}
25
26pub trait ControllerProxyInterface: Send + Sync {
27 type WatchDeviceStateResponseFut: std::future::Future<Output = Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error>>
28 + Send;
29 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct ControllerSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for ControllerSynchronousProxy {
39 type Proxy = ControllerProxy;
40 type Protocol = ControllerMarker;
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 ControllerSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 Self { client: fidl::client::sync::Client::new(channel) }
59 }
60
61 pub fn into_channel(self) -> fidl::Channel {
62 self.client.into_channel()
63 }
64
65 pub fn wait_for_event(
68 &self,
69 deadline: zx::MonotonicInstant,
70 ) -> Result<ControllerEvent, fidl::Error> {
71 ControllerEvent::decode(self.client.wait_for_event::<ControllerMarker>(deadline)?)
72 }
73
74 pub fn r#watch_device_state(
80 &self,
81 ___deadline: zx::MonotonicInstant,
82 ) -> Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error> {
83 let _response = self.client.send_query::<
84 fidl::encoding::EmptyPayload,
85 fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>,
86 ControllerMarker,
87 >(
88 (),
89 0x44628a2275753738,
90 fidl::encoding::DynamicFlags::FLEXIBLE,
91 ___deadline,
92 )?
93 .into_result::<ControllerMarker>("watch_device_state")?;
94 Ok(_response.map(|x| x))
95 }
96}
97
98#[cfg(target_os = "fuchsia")]
99impl From<ControllerSynchronousProxy> for zx::NullableHandle {
100 fn from(value: ControllerSynchronousProxy) -> Self {
101 value.into_channel().into()
102 }
103}
104
105#[cfg(target_os = "fuchsia")]
106impl From<fidl::Channel> for ControllerSynchronousProxy {
107 fn from(value: fidl::Channel) -> Self {
108 Self::new(value)
109 }
110}
111
112#[cfg(target_os = "fuchsia")]
113impl fidl::endpoints::FromClient for ControllerSynchronousProxy {
114 type Protocol = ControllerMarker;
115
116 fn from_client(value: fidl::endpoints::ClientEnd<ControllerMarker>) -> Self {
117 Self::new(value.into_channel())
118 }
119}
120
121#[derive(Debug, Clone)]
122pub struct ControllerProxy {
123 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
124}
125
126impl fidl::endpoints::Proxy for ControllerProxy {
127 type Protocol = ControllerMarker;
128
129 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
130 Self::new(inner)
131 }
132
133 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
134 self.client.into_channel().map_err(|client| Self { client })
135 }
136
137 fn as_channel(&self) -> &::fidl::AsyncChannel {
138 self.client.as_channel()
139 }
140}
141
142impl ControllerProxy {
143 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
145 let protocol_name = <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
146 Self { client: fidl::client::Client::new(channel, protocol_name) }
147 }
148
149 pub fn take_event_stream(&self) -> ControllerEventStream {
155 ControllerEventStream { event_receiver: self.client.take_event_receiver() }
156 }
157
158 pub fn r#watch_device_state(
164 &self,
165 ) -> fidl::client::QueryResponseFut<
166 DeviceStateWatcherWatchDeviceStateResult,
167 fidl::encoding::DefaultFuchsiaResourceDialect,
168 > {
169 ControllerProxyInterface::r#watch_device_state(self)
170 }
171}
172
173impl ControllerProxyInterface for ControllerProxy {
174 type WatchDeviceStateResponseFut = fidl::client::QueryResponseFut<
175 DeviceStateWatcherWatchDeviceStateResult,
176 fidl::encoding::DefaultFuchsiaResourceDialect,
177 >;
178 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut {
179 fn _decode(
180 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
181 ) -> Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error> {
182 let _response = fidl::client::decode_transaction_body::<
183 fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>,
184 fidl::encoding::DefaultFuchsiaResourceDialect,
185 0x44628a2275753738,
186 >(_buf?)?
187 .into_result::<ControllerMarker>("watch_device_state")?;
188 Ok(_response.map(|x| x))
189 }
190 self.client.send_query_and_decode::<
191 fidl::encoding::EmptyPayload,
192 DeviceStateWatcherWatchDeviceStateResult,
193 >(
194 (),
195 0x44628a2275753738,
196 fidl::encoding::DynamicFlags::FLEXIBLE,
197 _decode,
198 )
199 }
200}
201
202pub struct ControllerEventStream {
203 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
204}
205
206impl std::marker::Unpin for ControllerEventStream {}
207
208impl futures::stream::FusedStream for ControllerEventStream {
209 fn is_terminated(&self) -> bool {
210 self.event_receiver.is_terminated()
211 }
212}
213
214impl futures::Stream for ControllerEventStream {
215 type Item = Result<ControllerEvent, fidl::Error>;
216
217 fn poll_next(
218 mut self: std::pin::Pin<&mut Self>,
219 cx: &mut std::task::Context<'_>,
220 ) -> std::task::Poll<Option<Self::Item>> {
221 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
222 &mut self.event_receiver,
223 cx
224 )?) {
225 Some(buf) => std::task::Poll::Ready(Some(ControllerEvent::decode(buf))),
226 None => std::task::Poll::Ready(None),
227 }
228 }
229}
230
231#[derive(Debug)]
232pub enum ControllerEvent {
233 #[non_exhaustive]
234 _UnknownEvent {
235 ordinal: u64,
237 },
238}
239
240impl ControllerEvent {
241 fn decode(
243 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
244 ) -> Result<ControllerEvent, fidl::Error> {
245 let (bytes, _handles) = buf.split_mut();
246 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
247 debug_assert_eq!(tx_header.tx_id, 0);
248 match tx_header.ordinal {
249 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
250 Ok(ControllerEvent::_UnknownEvent { ordinal: tx_header.ordinal })
251 }
252 _ => Err(fidl::Error::UnknownOrdinal {
253 ordinal: tx_header.ordinal,
254 protocol_name: <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
255 }),
256 }
257 }
258}
259
260pub struct ControllerRequestStream {
262 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
263 is_terminated: bool,
264}
265
266impl std::marker::Unpin for ControllerRequestStream {}
267
268impl futures::stream::FusedStream for ControllerRequestStream {
269 fn is_terminated(&self) -> bool {
270 self.is_terminated
271 }
272}
273
274impl fidl::endpoints::RequestStream for ControllerRequestStream {
275 type Protocol = ControllerMarker;
276 type ControlHandle = ControllerControlHandle;
277
278 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
279 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
280 }
281
282 fn control_handle(&self) -> Self::ControlHandle {
283 ControllerControlHandle { inner: self.inner.clone() }
284 }
285
286 fn into_inner(
287 self,
288 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
289 {
290 (self.inner, self.is_terminated)
291 }
292
293 fn from_inner(
294 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
295 is_terminated: bool,
296 ) -> Self {
297 Self { inner, is_terminated }
298 }
299}
300
301impl futures::Stream for ControllerRequestStream {
302 type Item = Result<ControllerRequest, fidl::Error>;
303
304 fn poll_next(
305 mut self: std::pin::Pin<&mut Self>,
306 cx: &mut std::task::Context<'_>,
307 ) -> std::task::Poll<Option<Self::Item>> {
308 let this = &mut *self;
309 if this.inner.check_shutdown(cx) {
310 this.is_terminated = true;
311 return std::task::Poll::Ready(None);
312 }
313 if this.is_terminated {
314 panic!("polled ControllerRequestStream after completion");
315 }
316 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
317 |bytes, handles| {
318 match this.inner.channel().read_etc(cx, bytes, handles) {
319 std::task::Poll::Ready(Ok(())) => {}
320 std::task::Poll::Pending => return std::task::Poll::Pending,
321 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
322 this.is_terminated = true;
323 return std::task::Poll::Ready(None);
324 }
325 std::task::Poll::Ready(Err(e)) => {
326 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
327 e.into(),
328 ))));
329 }
330 }
331
332 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
334
335 std::task::Poll::Ready(Some(match header.ordinal {
336 0x44628a2275753738 => {
337 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
338 let mut req = fidl::new_empty!(
339 fidl::encoding::EmptyPayload,
340 fidl::encoding::DefaultFuchsiaResourceDialect
341 );
342 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
343 let control_handle = ControllerControlHandle { inner: this.inner.clone() };
344 Ok(ControllerRequest::WatchDeviceState {
345 responder: ControllerWatchDeviceStateResponder {
346 control_handle: std::mem::ManuallyDrop::new(control_handle),
347 tx_id: header.tx_id,
348 },
349 })
350 }
351 _ if header.tx_id == 0
352 && header
353 .dynamic_flags()
354 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
355 {
356 Ok(ControllerRequest::_UnknownMethod {
357 ordinal: header.ordinal,
358 control_handle: ControllerControlHandle { inner: this.inner.clone() },
359 method_type: fidl::MethodType::OneWay,
360 })
361 }
362 _ if header
363 .dynamic_flags()
364 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
365 {
366 this.inner.send_framework_err(
367 fidl::encoding::FrameworkErr::UnknownMethod,
368 header.tx_id,
369 header.ordinal,
370 header.dynamic_flags(),
371 (bytes, handles),
372 )?;
373 Ok(ControllerRequest::_UnknownMethod {
374 ordinal: header.ordinal,
375 control_handle: ControllerControlHandle { inner: this.inner.clone() },
376 method_type: fidl::MethodType::TwoWay,
377 })
378 }
379 _ => Err(fidl::Error::UnknownOrdinal {
380 ordinal: header.ordinal,
381 protocol_name:
382 <ControllerMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
383 }),
384 }))
385 },
386 )
387 }
388}
389
390#[derive(Debug)]
395pub enum ControllerRequest {
396 WatchDeviceState { responder: ControllerWatchDeviceStateResponder },
402 #[non_exhaustive]
404 _UnknownMethod {
405 ordinal: u64,
407 control_handle: ControllerControlHandle,
408 method_type: fidl::MethodType,
409 },
410}
411
412impl ControllerRequest {
413 #[allow(irrefutable_let_patterns)]
414 pub fn into_watch_device_state(self) -> Option<(ControllerWatchDeviceStateResponder)> {
415 if let ControllerRequest::WatchDeviceState { responder } = self {
416 Some((responder))
417 } else {
418 None
419 }
420 }
421
422 pub fn method_name(&self) -> &'static str {
424 match *self {
425 ControllerRequest::WatchDeviceState { .. } => "watch_device_state",
426 ControllerRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
427 "unknown one-way method"
428 }
429 ControllerRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
430 "unknown two-way method"
431 }
432 }
433 }
434}
435
436#[derive(Debug, Clone)]
437pub struct ControllerControlHandle {
438 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
439}
440
441impl ControllerControlHandle {
442 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
443 self.inner.shutdown_with_epitaph(status.into())
444 }
445}
446
447impl fidl::endpoints::ControlHandle for ControllerControlHandle {
448 fn shutdown(&self) {
449 self.inner.shutdown()
450 }
451
452 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
453 self.inner.shutdown_with_epitaph(status)
454 }
455
456 fn is_closed(&self) -> bool {
457 self.inner.channel().is_closed()
458 }
459 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
460 self.inner.channel().on_closed()
461 }
462
463 #[cfg(target_os = "fuchsia")]
464 fn signal_peer(
465 &self,
466 clear_mask: zx::Signals,
467 set_mask: zx::Signals,
468 ) -> Result<(), zx_status::Status> {
469 use fidl::Peered;
470 self.inner.channel().signal_peer(clear_mask, set_mask)
471 }
472}
473
474impl ControllerControlHandle {}
475
476#[must_use = "FIDL methods require a response to be sent"]
477#[derive(Debug)]
478pub struct ControllerWatchDeviceStateResponder {
479 control_handle: std::mem::ManuallyDrop<ControllerControlHandle>,
480 tx_id: u32,
481}
482
483impl std::ops::Drop for ControllerWatchDeviceStateResponder {
487 fn drop(&mut self) {
488 self.control_handle.shutdown();
489 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
491 }
492}
493
494impl fidl::endpoints::Responder for ControllerWatchDeviceStateResponder {
495 type ControlHandle = ControllerControlHandle;
496
497 fn control_handle(&self) -> &ControllerControlHandle {
498 &self.control_handle
499 }
500
501 fn drop_without_shutdown(mut self) {
502 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
504 std::mem::forget(self);
506 }
507}
508
509impl ControllerWatchDeviceStateResponder {
510 pub fn send(self, mut result: Result<&DeviceStateUpdate, i32>) -> Result<(), fidl::Error> {
514 let _result = self.send_raw(result);
515 if _result.is_err() {
516 self.control_handle.shutdown();
517 }
518 self.drop_without_shutdown();
519 _result
520 }
521
522 pub fn send_no_shutdown_on_err(
524 self,
525 mut result: Result<&DeviceStateUpdate, i32>,
526 ) -> Result<(), fidl::Error> {
527 let _result = self.send_raw(result);
528 self.drop_without_shutdown();
529 _result
530 }
531
532 fn send_raw(&self, mut result: Result<&DeviceStateUpdate, i32>) -> Result<(), fidl::Error> {
533 self.control_handle
534 .inner
535 .send::<fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>>(
536 fidl::encoding::FlexibleResult::new(result),
537 self.tx_id,
538 0x44628a2275753738,
539 fidl::encoding::DynamicFlags::FLEXIBLE,
540 )
541 }
542}
543
544#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
545pub struct DeviceStateWatcherMarker;
546
547impl fidl::endpoints::ProtocolMarker for DeviceStateWatcherMarker {
548 type Proxy = DeviceStateWatcherProxy;
549 type RequestStream = DeviceStateWatcherRequestStream;
550 #[cfg(target_os = "fuchsia")]
551 type SynchronousProxy = DeviceStateWatcherSynchronousProxy;
552
553 const DEBUG_NAME: &'static str = "(anonymous) DeviceStateWatcher";
554}
555pub type DeviceStateWatcherWatchDeviceStateResult = Result<DeviceStateUpdate, i32>;
556
557pub trait DeviceStateWatcherProxyInterface: Send + Sync {
558 type WatchDeviceStateResponseFut: std::future::Future<Output = Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error>>
559 + Send;
560 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut;
561}
562#[derive(Debug)]
563#[cfg(target_os = "fuchsia")]
564pub struct DeviceStateWatcherSynchronousProxy {
565 client: fidl::client::sync::Client,
566}
567
568#[cfg(target_os = "fuchsia")]
569impl fidl::endpoints::SynchronousProxy for DeviceStateWatcherSynchronousProxy {
570 type Proxy = DeviceStateWatcherProxy;
571 type Protocol = DeviceStateWatcherMarker;
572
573 fn from_channel(inner: fidl::Channel) -> Self {
574 Self::new(inner)
575 }
576
577 fn into_channel(self) -> fidl::Channel {
578 self.client.into_channel()
579 }
580
581 fn as_channel(&self) -> &fidl::Channel {
582 self.client.as_channel()
583 }
584}
585
586#[cfg(target_os = "fuchsia")]
587impl DeviceStateWatcherSynchronousProxy {
588 pub fn new(channel: fidl::Channel) -> Self {
589 Self { client: fidl::client::sync::Client::new(channel) }
590 }
591
592 pub fn into_channel(self) -> fidl::Channel {
593 self.client.into_channel()
594 }
595
596 pub fn wait_for_event(
599 &self,
600 deadline: zx::MonotonicInstant,
601 ) -> Result<DeviceStateWatcherEvent, fidl::Error> {
602 DeviceStateWatcherEvent::decode(
603 self.client.wait_for_event::<DeviceStateWatcherMarker>(deadline)?,
604 )
605 }
606
607 pub fn r#watch_device_state(
613 &self,
614 ___deadline: zx::MonotonicInstant,
615 ) -> Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error> {
616 let _response = self.client.send_query::<
617 fidl::encoding::EmptyPayload,
618 fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>,
619 DeviceStateWatcherMarker,
620 >(
621 (),
622 0x44628a2275753738,
623 fidl::encoding::DynamicFlags::FLEXIBLE,
624 ___deadline,
625 )?
626 .into_result::<DeviceStateWatcherMarker>("watch_device_state")?;
627 Ok(_response.map(|x| x))
628 }
629}
630
631#[cfg(target_os = "fuchsia")]
632impl From<DeviceStateWatcherSynchronousProxy> for zx::NullableHandle {
633 fn from(value: DeviceStateWatcherSynchronousProxy) -> Self {
634 value.into_channel().into()
635 }
636}
637
638#[cfg(target_os = "fuchsia")]
639impl From<fidl::Channel> for DeviceStateWatcherSynchronousProxy {
640 fn from(value: fidl::Channel) -> Self {
641 Self::new(value)
642 }
643}
644
645#[cfg(target_os = "fuchsia")]
646impl fidl::endpoints::FromClient for DeviceStateWatcherSynchronousProxy {
647 type Protocol = DeviceStateWatcherMarker;
648
649 fn from_client(value: fidl::endpoints::ClientEnd<DeviceStateWatcherMarker>) -> Self {
650 Self::new(value.into_channel())
651 }
652}
653
654#[derive(Debug, Clone)]
655pub struct DeviceStateWatcherProxy {
656 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
657}
658
659impl fidl::endpoints::Proxy for DeviceStateWatcherProxy {
660 type Protocol = DeviceStateWatcherMarker;
661
662 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
663 Self::new(inner)
664 }
665
666 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
667 self.client.into_channel().map_err(|client| Self { client })
668 }
669
670 fn as_channel(&self) -> &::fidl::AsyncChannel {
671 self.client.as_channel()
672 }
673}
674
675impl DeviceStateWatcherProxy {
676 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
678 let protocol_name =
679 <DeviceStateWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
680 Self { client: fidl::client::Client::new(channel, protocol_name) }
681 }
682
683 pub fn take_event_stream(&self) -> DeviceStateWatcherEventStream {
689 DeviceStateWatcherEventStream { event_receiver: self.client.take_event_receiver() }
690 }
691
692 pub fn r#watch_device_state(
698 &self,
699 ) -> fidl::client::QueryResponseFut<
700 DeviceStateWatcherWatchDeviceStateResult,
701 fidl::encoding::DefaultFuchsiaResourceDialect,
702 > {
703 DeviceStateWatcherProxyInterface::r#watch_device_state(self)
704 }
705}
706
707impl DeviceStateWatcherProxyInterface for DeviceStateWatcherProxy {
708 type WatchDeviceStateResponseFut = fidl::client::QueryResponseFut<
709 DeviceStateWatcherWatchDeviceStateResult,
710 fidl::encoding::DefaultFuchsiaResourceDialect,
711 >;
712 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut {
713 fn _decode(
714 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
715 ) -> Result<DeviceStateWatcherWatchDeviceStateResult, fidl::Error> {
716 let _response = fidl::client::decode_transaction_body::<
717 fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>,
718 fidl::encoding::DefaultFuchsiaResourceDialect,
719 0x44628a2275753738,
720 >(_buf?)?
721 .into_result::<DeviceStateWatcherMarker>("watch_device_state")?;
722 Ok(_response.map(|x| x))
723 }
724 self.client.send_query_and_decode::<
725 fidl::encoding::EmptyPayload,
726 DeviceStateWatcherWatchDeviceStateResult,
727 >(
728 (),
729 0x44628a2275753738,
730 fidl::encoding::DynamicFlags::FLEXIBLE,
731 _decode,
732 )
733 }
734}
735
736pub struct DeviceStateWatcherEventStream {
737 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
738}
739
740impl std::marker::Unpin for DeviceStateWatcherEventStream {}
741
742impl futures::stream::FusedStream for DeviceStateWatcherEventStream {
743 fn is_terminated(&self) -> bool {
744 self.event_receiver.is_terminated()
745 }
746}
747
748impl futures::Stream for DeviceStateWatcherEventStream {
749 type Item = Result<DeviceStateWatcherEvent, fidl::Error>;
750
751 fn poll_next(
752 mut self: std::pin::Pin<&mut Self>,
753 cx: &mut std::task::Context<'_>,
754 ) -> std::task::Poll<Option<Self::Item>> {
755 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
756 &mut self.event_receiver,
757 cx
758 )?) {
759 Some(buf) => std::task::Poll::Ready(Some(DeviceStateWatcherEvent::decode(buf))),
760 None => std::task::Poll::Ready(None),
761 }
762 }
763}
764
765#[derive(Debug)]
766pub enum DeviceStateWatcherEvent {
767 #[non_exhaustive]
768 _UnknownEvent {
769 ordinal: u64,
771 },
772}
773
774impl DeviceStateWatcherEvent {
775 fn decode(
777 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
778 ) -> Result<DeviceStateWatcherEvent, fidl::Error> {
779 let (bytes, _handles) = buf.split_mut();
780 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
781 debug_assert_eq!(tx_header.tx_id, 0);
782 match tx_header.ordinal {
783 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
784 Ok(DeviceStateWatcherEvent::_UnknownEvent { ordinal: tx_header.ordinal })
785 }
786 _ => Err(fidl::Error::UnknownOrdinal {
787 ordinal: tx_header.ordinal,
788 protocol_name:
789 <DeviceStateWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
790 }),
791 }
792 }
793}
794
795pub struct DeviceStateWatcherRequestStream {
797 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
798 is_terminated: bool,
799}
800
801impl std::marker::Unpin for DeviceStateWatcherRequestStream {}
802
803impl futures::stream::FusedStream for DeviceStateWatcherRequestStream {
804 fn is_terminated(&self) -> bool {
805 self.is_terminated
806 }
807}
808
809impl fidl::endpoints::RequestStream for DeviceStateWatcherRequestStream {
810 type Protocol = DeviceStateWatcherMarker;
811 type ControlHandle = DeviceStateWatcherControlHandle;
812
813 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
814 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
815 }
816
817 fn control_handle(&self) -> Self::ControlHandle {
818 DeviceStateWatcherControlHandle { inner: self.inner.clone() }
819 }
820
821 fn into_inner(
822 self,
823 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
824 {
825 (self.inner, self.is_terminated)
826 }
827
828 fn from_inner(
829 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
830 is_terminated: bool,
831 ) -> Self {
832 Self { inner, is_terminated }
833 }
834}
835
836impl futures::Stream for DeviceStateWatcherRequestStream {
837 type Item = Result<DeviceStateWatcherRequest, fidl::Error>;
838
839 fn poll_next(
840 mut self: std::pin::Pin<&mut Self>,
841 cx: &mut std::task::Context<'_>,
842 ) -> std::task::Poll<Option<Self::Item>> {
843 let this = &mut *self;
844 if this.inner.check_shutdown(cx) {
845 this.is_terminated = true;
846 return std::task::Poll::Ready(None);
847 }
848 if this.is_terminated {
849 panic!("polled DeviceStateWatcherRequestStream after completion");
850 }
851 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
852 |bytes, handles| {
853 match this.inner.channel().read_etc(cx, bytes, handles) {
854 std::task::Poll::Ready(Ok(())) => {}
855 std::task::Poll::Pending => return std::task::Poll::Pending,
856 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
857 this.is_terminated = true;
858 return std::task::Poll::Ready(None);
859 }
860 std::task::Poll::Ready(Err(e)) => {
861 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
862 e.into(),
863 ))));
864 }
865 }
866
867 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
869
870 std::task::Poll::Ready(Some(match header.ordinal {
871 0x44628a2275753738 => {
872 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
873 let mut req = fidl::new_empty!(fidl::encoding::EmptyPayload, fidl::encoding::DefaultFuchsiaResourceDialect);
874 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
875 let control_handle = DeviceStateWatcherControlHandle {
876 inner: this.inner.clone(),
877 };
878 Ok(DeviceStateWatcherRequest::WatchDeviceState {
879 responder: DeviceStateWatcherWatchDeviceStateResponder {
880 control_handle: std::mem::ManuallyDrop::new(control_handle),
881 tx_id: header.tx_id,
882 },
883 })
884 }
885 _ if header.tx_id == 0 && header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
886 Ok(DeviceStateWatcherRequest::_UnknownMethod {
887 ordinal: header.ordinal,
888 control_handle: DeviceStateWatcherControlHandle { inner: this.inner.clone() },
889 method_type: fidl::MethodType::OneWay,
890 })
891 }
892 _ if header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
893 this.inner.send_framework_err(
894 fidl::encoding::FrameworkErr::UnknownMethod,
895 header.tx_id,
896 header.ordinal,
897 header.dynamic_flags(),
898 (bytes, handles),
899 )?;
900 Ok(DeviceStateWatcherRequest::_UnknownMethod {
901 ordinal: header.ordinal,
902 control_handle: DeviceStateWatcherControlHandle { inner: this.inner.clone() },
903 method_type: fidl::MethodType::TwoWay,
904 })
905 }
906 _ => Err(fidl::Error::UnknownOrdinal {
907 ordinal: header.ordinal,
908 protocol_name: <DeviceStateWatcherMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
909 }),
910 }))
911 },
912 )
913 }
914}
915
916#[derive(Debug)]
918pub enum DeviceStateWatcherRequest {
919 WatchDeviceState { responder: DeviceStateWatcherWatchDeviceStateResponder },
925 #[non_exhaustive]
927 _UnknownMethod {
928 ordinal: u64,
930 control_handle: DeviceStateWatcherControlHandle,
931 method_type: fidl::MethodType,
932 },
933}
934
935impl DeviceStateWatcherRequest {
936 #[allow(irrefutable_let_patterns)]
937 pub fn into_watch_device_state(self) -> Option<(DeviceStateWatcherWatchDeviceStateResponder)> {
938 if let DeviceStateWatcherRequest::WatchDeviceState { responder } = self {
939 Some((responder))
940 } else {
941 None
942 }
943 }
944
945 pub fn method_name(&self) -> &'static str {
947 match *self {
948 DeviceStateWatcherRequest::WatchDeviceState { .. } => "watch_device_state",
949 DeviceStateWatcherRequest::_UnknownMethod {
950 method_type: fidl::MethodType::OneWay,
951 ..
952 } => "unknown one-way method",
953 DeviceStateWatcherRequest::_UnknownMethod {
954 method_type: fidl::MethodType::TwoWay,
955 ..
956 } => "unknown two-way method",
957 }
958 }
959}
960
961#[derive(Debug, Clone)]
962pub struct DeviceStateWatcherControlHandle {
963 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
964}
965
966impl DeviceStateWatcherControlHandle {
967 pub fn shutdown_with_epitaph(&self, status: impl Into<fidl::Epitaph>) {
968 self.inner.shutdown_with_epitaph(status.into())
969 }
970}
971
972impl fidl::endpoints::ControlHandle for DeviceStateWatcherControlHandle {
973 fn shutdown(&self) {
974 self.inner.shutdown()
975 }
976
977 fn shutdown_with_epitaph(&self, status: fidl::Epitaph) {
978 self.inner.shutdown_with_epitaph(status)
979 }
980
981 fn is_closed(&self) -> bool {
982 self.inner.channel().is_closed()
983 }
984 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
985 self.inner.channel().on_closed()
986 }
987
988 #[cfg(target_os = "fuchsia")]
989 fn signal_peer(
990 &self,
991 clear_mask: zx::Signals,
992 set_mask: zx::Signals,
993 ) -> Result<(), zx_status::Status> {
994 use fidl::Peered;
995 self.inner.channel().signal_peer(clear_mask, set_mask)
996 }
997}
998
999impl DeviceStateWatcherControlHandle {}
1000
1001#[must_use = "FIDL methods require a response to be sent"]
1002#[derive(Debug)]
1003pub struct DeviceStateWatcherWatchDeviceStateResponder {
1004 control_handle: std::mem::ManuallyDrop<DeviceStateWatcherControlHandle>,
1005 tx_id: u32,
1006}
1007
1008impl std::ops::Drop for DeviceStateWatcherWatchDeviceStateResponder {
1012 fn drop(&mut self) {
1013 self.control_handle.shutdown();
1014 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1016 }
1017}
1018
1019impl fidl::endpoints::Responder for DeviceStateWatcherWatchDeviceStateResponder {
1020 type ControlHandle = DeviceStateWatcherControlHandle;
1021
1022 fn control_handle(&self) -> &DeviceStateWatcherControlHandle {
1023 &self.control_handle
1024 }
1025
1026 fn drop_without_shutdown(mut self) {
1027 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1029 std::mem::forget(self);
1031 }
1032}
1033
1034impl DeviceStateWatcherWatchDeviceStateResponder {
1035 pub fn send(self, mut result: Result<&DeviceStateUpdate, i32>) -> Result<(), fidl::Error> {
1039 let _result = self.send_raw(result);
1040 if _result.is_err() {
1041 self.control_handle.shutdown();
1042 }
1043 self.drop_without_shutdown();
1044 _result
1045 }
1046
1047 pub fn send_no_shutdown_on_err(
1049 self,
1050 mut result: Result<&DeviceStateUpdate, i32>,
1051 ) -> Result<(), fidl::Error> {
1052 let _result = self.send_raw(result);
1053 self.drop_without_shutdown();
1054 _result
1055 }
1056
1057 fn send_raw(&self, mut result: Result<&DeviceStateUpdate, i32>) -> Result<(), fidl::Error> {
1058 self.control_handle
1059 .inner
1060 .send::<fidl::encoding::FlexibleResultType<DeviceStateUpdate, i32>>(
1061 fidl::encoding::FlexibleResult::new(result),
1062 self.tx_id,
1063 0x44628a2275753738,
1064 fidl::encoding::DynamicFlags::FLEXIBLE,
1065 )
1066 }
1067}
1068
1069#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1070pub struct ServiceMarker;
1071
1072#[cfg(target_os = "fuchsia")]
1073impl fidl::endpoints::ServiceMarker for ServiceMarker {
1074 type Proxy = ServiceProxy;
1075 type Request = ServiceRequest;
1076 const SERVICE_NAME: &'static str = "fuchsia.hardware.usb.policy.Service";
1077}
1078
1079#[cfg(target_os = "fuchsia")]
1083pub enum ServiceRequest {
1084 Controller(ControllerRequestStream),
1086}
1087
1088#[cfg(target_os = "fuchsia")]
1089impl fidl::endpoints::ServiceRequest for ServiceRequest {
1090 type Service = ServiceMarker;
1091
1092 fn dispatch(name: &str, _channel: fidl::AsyncChannel) -> Self {
1093 match name {
1094 "controller" => Self::Controller(
1095 <ControllerRequestStream as fidl::endpoints::RequestStream>::from_channel(_channel),
1096 ),
1097 _ => panic!("no such member protocol name for service Service"),
1098 }
1099 }
1100
1101 fn member_names() -> &'static [&'static str] {
1102 &["controller"]
1103 }
1104}
1105#[cfg(target_os = "fuchsia")]
1107pub struct ServiceProxy(#[allow(dead_code)] Box<dyn fidl::endpoints::MemberOpener>);
1108
1109#[cfg(target_os = "fuchsia")]
1110impl fidl::endpoints::ServiceProxy for ServiceProxy {
1111 type Service = ServiceMarker;
1112
1113 fn from_member_opener(opener: Box<dyn fidl::endpoints::MemberOpener>) -> Self {
1114 Self(opener)
1115 }
1116}
1117
1118#[cfg(target_os = "fuchsia")]
1119impl ServiceProxy {
1120 pub fn connect_to_controller(&self) -> Result<ControllerProxy, fidl::Error> {
1122 let (proxy, server_end) = fidl::endpoints::create_proxy::<ControllerMarker>();
1123 self.connect_channel_to_controller(server_end)?;
1124 Ok(proxy)
1125 }
1126
1127 pub fn connect_to_controller_sync(&self) -> Result<ControllerSynchronousProxy, fidl::Error> {
1130 let (proxy, server_end) = fidl::endpoints::create_sync_proxy::<ControllerMarker>();
1131 self.connect_channel_to_controller(server_end)?;
1132 Ok(proxy)
1133 }
1134
1135 pub fn connect_channel_to_controller(
1138 &self,
1139 server_end: fidl::endpoints::ServerEnd<ControllerMarker>,
1140 ) -> Result<(), fidl::Error> {
1141 self.0.open_member("controller", server_end.into_channel())
1142 }
1143
1144 pub fn instance_name(&self) -> &str {
1145 self.0.instance_name()
1146 }
1147}
1148
1149mod internal {
1150 use super::*;
1151}