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_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 HealthMarker;
16
17impl fidl::endpoints::ProtocolMarker for HealthMarker {
18 type Proxy = HealthProxy;
19 type RequestStream = HealthRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = HealthSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.usb.policy.Health";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for HealthMarker {}
26pub type HealthGetReportResult = Result<HealthReport, i32>;
27
28pub trait HealthProxyInterface: Send + Sync {
29 type GetReportResponseFut: std::future::Future<Output = Result<HealthGetReportResult, fidl::Error>>
30 + Send;
31 fn r#get_report(&self) -> Self::GetReportResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct HealthSynchronousProxy {
36 client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for HealthSynchronousProxy {
41 type Proxy = HealthProxy;
42 type Protocol = HealthMarker;
43
44 fn from_channel(inner: fidl::Channel) -> Self {
45 Self::new(inner)
46 }
47
48 fn into_channel(self) -> fidl::Channel {
49 self.client.into_channel()
50 }
51
52 fn as_channel(&self) -> &fidl::Channel {
53 self.client.as_channel()
54 }
55}
56
57#[cfg(target_os = "fuchsia")]
58impl HealthSynchronousProxy {
59 pub fn new(channel: fidl::Channel) -> Self {
60 Self { client: fidl::client::sync::Client::new(channel) }
61 }
62
63 pub fn into_channel(self) -> fidl::Channel {
64 self.client.into_channel()
65 }
66
67 pub fn wait_for_event(
70 &self,
71 deadline: zx::MonotonicInstant,
72 ) -> Result<HealthEvent, fidl::Error> {
73 HealthEvent::decode(self.client.wait_for_event::<HealthMarker>(deadline)?)
74 }
75
76 pub fn r#get_report(
78 &self,
79 ___deadline: zx::MonotonicInstant,
80 ) -> Result<HealthGetReportResult, fidl::Error> {
81 let _response = self.client.send_query::<
82 fidl::encoding::EmptyPayload,
83 fidl::encoding::FlexibleResultType<HealthReport, i32>,
84 HealthMarker,
85 >(
86 (),
87 0x45f3bc8cbb38e701,
88 fidl::encoding::DynamicFlags::FLEXIBLE,
89 ___deadline,
90 )?
91 .into_result::<HealthMarker>("get_report")?;
92 Ok(_response.map(|x| x))
93 }
94}
95
96#[cfg(target_os = "fuchsia")]
97impl From<HealthSynchronousProxy> for zx::NullableHandle {
98 fn from(value: HealthSynchronousProxy) -> Self {
99 value.into_channel().into()
100 }
101}
102
103#[cfg(target_os = "fuchsia")]
104impl From<fidl::Channel> for HealthSynchronousProxy {
105 fn from(value: fidl::Channel) -> Self {
106 Self::new(value)
107 }
108}
109
110#[cfg(target_os = "fuchsia")]
111impl fidl::endpoints::FromClient for HealthSynchronousProxy {
112 type Protocol = HealthMarker;
113
114 fn from_client(value: fidl::endpoints::ClientEnd<HealthMarker>) -> Self {
115 Self::new(value.into_channel())
116 }
117}
118
119#[derive(Debug, Clone)]
120pub struct HealthProxy {
121 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
122}
123
124impl fidl::endpoints::Proxy for HealthProxy {
125 type Protocol = HealthMarker;
126
127 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
128 Self::new(inner)
129 }
130
131 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
132 self.client.into_channel().map_err(|client| Self { client })
133 }
134
135 fn as_channel(&self) -> &::fidl::AsyncChannel {
136 self.client.as_channel()
137 }
138}
139
140impl HealthProxy {
141 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
143 let protocol_name = <HealthMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
144 Self { client: fidl::client::Client::new(channel, protocol_name) }
145 }
146
147 pub fn take_event_stream(&self) -> HealthEventStream {
153 HealthEventStream { event_receiver: self.client.take_event_receiver() }
154 }
155
156 pub fn r#get_report(
158 &self,
159 ) -> fidl::client::QueryResponseFut<
160 HealthGetReportResult,
161 fidl::encoding::DefaultFuchsiaResourceDialect,
162 > {
163 HealthProxyInterface::r#get_report(self)
164 }
165}
166
167impl HealthProxyInterface for HealthProxy {
168 type GetReportResponseFut = fidl::client::QueryResponseFut<
169 HealthGetReportResult,
170 fidl::encoding::DefaultFuchsiaResourceDialect,
171 >;
172 fn r#get_report(&self) -> Self::GetReportResponseFut {
173 fn _decode(
174 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
175 ) -> Result<HealthGetReportResult, fidl::Error> {
176 let _response = fidl::client::decode_transaction_body::<
177 fidl::encoding::FlexibleResultType<HealthReport, i32>,
178 fidl::encoding::DefaultFuchsiaResourceDialect,
179 0x45f3bc8cbb38e701,
180 >(_buf?)?
181 .into_result::<HealthMarker>("get_report")?;
182 Ok(_response.map(|x| x))
183 }
184 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, HealthGetReportResult>(
185 (),
186 0x45f3bc8cbb38e701,
187 fidl::encoding::DynamicFlags::FLEXIBLE,
188 _decode,
189 )
190 }
191}
192
193pub struct HealthEventStream {
194 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
195}
196
197impl std::marker::Unpin for HealthEventStream {}
198
199impl futures::stream::FusedStream for HealthEventStream {
200 fn is_terminated(&self) -> bool {
201 self.event_receiver.is_terminated()
202 }
203}
204
205impl futures::Stream for HealthEventStream {
206 type Item = Result<HealthEvent, fidl::Error>;
207
208 fn poll_next(
209 mut self: std::pin::Pin<&mut Self>,
210 cx: &mut std::task::Context<'_>,
211 ) -> std::task::Poll<Option<Self::Item>> {
212 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
213 &mut self.event_receiver,
214 cx
215 )?) {
216 Some(buf) => std::task::Poll::Ready(Some(HealthEvent::decode(buf))),
217 None => std::task::Poll::Ready(None),
218 }
219 }
220}
221
222#[derive(Debug)]
223pub enum HealthEvent {
224 #[non_exhaustive]
225 _UnknownEvent {
226 ordinal: u64,
228 },
229}
230
231impl HealthEvent {
232 fn decode(
234 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
235 ) -> Result<HealthEvent, fidl::Error> {
236 let (bytes, _handles) = buf.split_mut();
237 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
238 debug_assert_eq!(tx_header.tx_id, 0);
239 match tx_header.ordinal {
240 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
241 Ok(HealthEvent::_UnknownEvent { ordinal: tx_header.ordinal })
242 }
243 _ => Err(fidl::Error::UnknownOrdinal {
244 ordinal: tx_header.ordinal,
245 protocol_name: <HealthMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
246 }),
247 }
248 }
249}
250
251pub struct HealthRequestStream {
253 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
254 is_terminated: bool,
255}
256
257impl std::marker::Unpin for HealthRequestStream {}
258
259impl futures::stream::FusedStream for HealthRequestStream {
260 fn is_terminated(&self) -> bool {
261 self.is_terminated
262 }
263}
264
265impl fidl::endpoints::RequestStream for HealthRequestStream {
266 type Protocol = HealthMarker;
267 type ControlHandle = HealthControlHandle;
268
269 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
270 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
271 }
272
273 fn control_handle(&self) -> Self::ControlHandle {
274 HealthControlHandle { inner: self.inner.clone() }
275 }
276
277 fn into_inner(
278 self,
279 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
280 {
281 (self.inner, self.is_terminated)
282 }
283
284 fn from_inner(
285 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
286 is_terminated: bool,
287 ) -> Self {
288 Self { inner, is_terminated }
289 }
290}
291
292impl futures::Stream for HealthRequestStream {
293 type Item = Result<HealthRequest, fidl::Error>;
294
295 fn poll_next(
296 mut self: std::pin::Pin<&mut Self>,
297 cx: &mut std::task::Context<'_>,
298 ) -> std::task::Poll<Option<Self::Item>> {
299 let this = &mut *self;
300 if this.inner.check_shutdown(cx) {
301 this.is_terminated = true;
302 return std::task::Poll::Ready(None);
303 }
304 if this.is_terminated {
305 panic!("polled HealthRequestStream after completion");
306 }
307 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
308 |bytes, handles| {
309 match this.inner.channel().read_etc(cx, bytes, handles) {
310 std::task::Poll::Ready(Ok(())) => {}
311 std::task::Poll::Pending => return std::task::Poll::Pending,
312 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
313 this.is_terminated = true;
314 return std::task::Poll::Ready(None);
315 }
316 std::task::Poll::Ready(Err(e)) => {
317 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
318 e.into(),
319 ))));
320 }
321 }
322
323 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
325
326 std::task::Poll::Ready(Some(match header.ordinal {
327 0x45f3bc8cbb38e701 => {
328 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
329 let mut req = fidl::new_empty!(
330 fidl::encoding::EmptyPayload,
331 fidl::encoding::DefaultFuchsiaResourceDialect
332 );
333 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
334 let control_handle = HealthControlHandle { inner: this.inner.clone() };
335 Ok(HealthRequest::GetReport {
336 responder: HealthGetReportResponder {
337 control_handle: std::mem::ManuallyDrop::new(control_handle),
338 tx_id: header.tx_id,
339 },
340 })
341 }
342 _ if header.tx_id == 0
343 && header
344 .dynamic_flags()
345 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
346 {
347 Ok(HealthRequest::_UnknownMethod {
348 ordinal: header.ordinal,
349 control_handle: HealthControlHandle { inner: this.inner.clone() },
350 method_type: fidl::MethodType::OneWay,
351 })
352 }
353 _ if header
354 .dynamic_flags()
355 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
356 {
357 this.inner.send_framework_err(
358 fidl::encoding::FrameworkErr::UnknownMethod,
359 header.tx_id,
360 header.ordinal,
361 header.dynamic_flags(),
362 (bytes, handles),
363 )?;
364 Ok(HealthRequest::_UnknownMethod {
365 ordinal: header.ordinal,
366 control_handle: HealthControlHandle { inner: this.inner.clone() },
367 method_type: fidl::MethodType::TwoWay,
368 })
369 }
370 _ => Err(fidl::Error::UnknownOrdinal {
371 ordinal: header.ordinal,
372 protocol_name:
373 <HealthMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
374 }),
375 }))
376 },
377 )
378 }
379}
380
381#[derive(Debug)]
383pub enum HealthRequest {
384 GetReport { responder: HealthGetReportResponder },
386 #[non_exhaustive]
388 _UnknownMethod {
389 ordinal: u64,
391 control_handle: HealthControlHandle,
392 method_type: fidl::MethodType,
393 },
394}
395
396impl HealthRequest {
397 #[allow(irrefutable_let_patterns)]
398 pub fn into_get_report(self) -> Option<(HealthGetReportResponder)> {
399 if let HealthRequest::GetReport { responder } = self { Some((responder)) } else { None }
400 }
401
402 pub fn method_name(&self) -> &'static str {
404 match *self {
405 HealthRequest::GetReport { .. } => "get_report",
406 HealthRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
407 "unknown one-way method"
408 }
409 HealthRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
410 "unknown two-way method"
411 }
412 }
413 }
414}
415
416#[derive(Debug, Clone)]
417pub struct HealthControlHandle {
418 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
419}
420
421impl fidl::endpoints::ControlHandle for HealthControlHandle {
422 fn shutdown(&self) {
423 self.inner.shutdown()
424 }
425
426 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
427 self.inner.shutdown_with_epitaph(status)
428 }
429
430 fn is_closed(&self) -> bool {
431 self.inner.channel().is_closed()
432 }
433 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
434 self.inner.channel().on_closed()
435 }
436
437 #[cfg(target_os = "fuchsia")]
438 fn signal_peer(
439 &self,
440 clear_mask: zx::Signals,
441 set_mask: zx::Signals,
442 ) -> Result<(), zx_status::Status> {
443 use fidl::Peered;
444 self.inner.channel().signal_peer(clear_mask, set_mask)
445 }
446}
447
448impl HealthControlHandle {}
449
450#[must_use = "FIDL methods require a response to be sent"]
451#[derive(Debug)]
452pub struct HealthGetReportResponder {
453 control_handle: std::mem::ManuallyDrop<HealthControlHandle>,
454 tx_id: u32,
455}
456
457impl std::ops::Drop for HealthGetReportResponder {
461 fn drop(&mut self) {
462 self.control_handle.shutdown();
463 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
465 }
466}
467
468impl fidl::endpoints::Responder for HealthGetReportResponder {
469 type ControlHandle = HealthControlHandle;
470
471 fn control_handle(&self) -> &HealthControlHandle {
472 &self.control_handle
473 }
474
475 fn drop_without_shutdown(mut self) {
476 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
478 std::mem::forget(self);
480 }
481}
482
483impl HealthGetReportResponder {
484 pub fn send(self, mut result: Result<&HealthReport, i32>) -> Result<(), fidl::Error> {
488 let _result = self.send_raw(result);
489 if _result.is_err() {
490 self.control_handle.shutdown();
491 }
492 self.drop_without_shutdown();
493 _result
494 }
495
496 pub fn send_no_shutdown_on_err(
498 self,
499 mut result: Result<&HealthReport, i32>,
500 ) -> Result<(), fidl::Error> {
501 let _result = self.send_raw(result);
502 self.drop_without_shutdown();
503 _result
504 }
505
506 fn send_raw(&self, mut result: Result<&HealthReport, i32>) -> Result<(), fidl::Error> {
507 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<HealthReport, i32>>(
508 fidl::encoding::FlexibleResult::new(result),
509 self.tx_id,
510 0x45f3bc8cbb38e701,
511 fidl::encoding::DynamicFlags::FLEXIBLE,
512 )
513 }
514}
515
516#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
517pub struct PolicyProviderMarker;
518
519impl fidl::endpoints::ProtocolMarker for PolicyProviderMarker {
520 type Proxy = PolicyProviderProxy;
521 type RequestStream = PolicyProviderRequestStream;
522 #[cfg(target_os = "fuchsia")]
523 type SynchronousProxy = PolicyProviderSynchronousProxy;
524
525 const DEBUG_NAME: &'static str = "fuchsia.usb.policy.PolicyProvider";
526}
527impl fidl::endpoints::DiscoverableProtocolMarker for PolicyProviderMarker {}
528
529pub trait PolicyProviderProxyInterface: Send + Sync {
530 type WatchDeviceStateResponseFut: std::future::Future<
531 Output = Result<
532 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
533 fidl::Error,
534 >,
535 > + Send;
536 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut;
537}
538#[derive(Debug)]
539#[cfg(target_os = "fuchsia")]
540pub struct PolicyProviderSynchronousProxy {
541 client: fidl::client::sync::Client,
542}
543
544#[cfg(target_os = "fuchsia")]
545impl fidl::endpoints::SynchronousProxy for PolicyProviderSynchronousProxy {
546 type Proxy = PolicyProviderProxy;
547 type Protocol = PolicyProviderMarker;
548
549 fn from_channel(inner: fidl::Channel) -> Self {
550 Self::new(inner)
551 }
552
553 fn into_channel(self) -> fidl::Channel {
554 self.client.into_channel()
555 }
556
557 fn as_channel(&self) -> &fidl::Channel {
558 self.client.as_channel()
559 }
560}
561
562#[cfg(target_os = "fuchsia")]
563impl PolicyProviderSynchronousProxy {
564 pub fn new(channel: fidl::Channel) -> Self {
565 Self { client: fidl::client::sync::Client::new(channel) }
566 }
567
568 pub fn into_channel(self) -> fidl::Channel {
569 self.client.into_channel()
570 }
571
572 pub fn wait_for_event(
575 &self,
576 deadline: zx::MonotonicInstant,
577 ) -> Result<PolicyProviderEvent, fidl::Error> {
578 PolicyProviderEvent::decode(self.client.wait_for_event::<PolicyProviderMarker>(deadline)?)
579 }
580
581 pub fn r#watch_device_state(
587 &self,
588 ___deadline: zx::MonotonicInstant,
589 ) -> Result<
590 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
591 fidl::Error,
592 > {
593 let _response = self
594 .client
595 .send_query::<fidl::encoding::EmptyPayload, fidl::encoding::FlexibleResultType<
596 fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate,
597 i32,
598 >, PolicyProviderMarker>(
599 (),
600 0x44628a2275753738,
601 fidl::encoding::DynamicFlags::FLEXIBLE,
602 ___deadline,
603 )?
604 .into_result::<PolicyProviderMarker>("watch_device_state")?;
605 Ok(_response.map(|x| x))
606 }
607}
608
609#[cfg(target_os = "fuchsia")]
610impl From<PolicyProviderSynchronousProxy> for zx::NullableHandle {
611 fn from(value: PolicyProviderSynchronousProxy) -> Self {
612 value.into_channel().into()
613 }
614}
615
616#[cfg(target_os = "fuchsia")]
617impl From<fidl::Channel> for PolicyProviderSynchronousProxy {
618 fn from(value: fidl::Channel) -> Self {
619 Self::new(value)
620 }
621}
622
623#[cfg(target_os = "fuchsia")]
624impl fidl::endpoints::FromClient for PolicyProviderSynchronousProxy {
625 type Protocol = PolicyProviderMarker;
626
627 fn from_client(value: fidl::endpoints::ClientEnd<PolicyProviderMarker>) -> Self {
628 Self::new(value.into_channel())
629 }
630}
631
632#[derive(Debug, Clone)]
633pub struct PolicyProviderProxy {
634 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
635}
636
637impl fidl::endpoints::Proxy for PolicyProviderProxy {
638 type Protocol = PolicyProviderMarker;
639
640 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
641 Self::new(inner)
642 }
643
644 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
645 self.client.into_channel().map_err(|client| Self { client })
646 }
647
648 fn as_channel(&self) -> &::fidl::AsyncChannel {
649 self.client.as_channel()
650 }
651}
652
653impl PolicyProviderProxy {
654 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
656 let protocol_name = <PolicyProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
657 Self { client: fidl::client::Client::new(channel, protocol_name) }
658 }
659
660 pub fn take_event_stream(&self) -> PolicyProviderEventStream {
666 PolicyProviderEventStream { event_receiver: self.client.take_event_receiver() }
667 }
668
669 pub fn r#watch_device_state(
675 &self,
676 ) -> fidl::client::QueryResponseFut<
677 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
678 fidl::encoding::DefaultFuchsiaResourceDialect,
679 > {
680 PolicyProviderProxyInterface::r#watch_device_state(self)
681 }
682}
683
684impl PolicyProviderProxyInterface for PolicyProviderProxy {
685 type WatchDeviceStateResponseFut = fidl::client::QueryResponseFut<
686 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
687 fidl::encoding::DefaultFuchsiaResourceDialect,
688 >;
689 fn r#watch_device_state(&self) -> Self::WatchDeviceStateResponseFut {
690 fn _decode(
691 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
692 ) -> Result<
693 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
694 fidl::Error,
695 > {
696 let _response = fidl::client::decode_transaction_body::<
697 fidl::encoding::FlexibleResultType<
698 fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate,
699 i32,
700 >,
701 fidl::encoding::DefaultFuchsiaResourceDialect,
702 0x44628a2275753738,
703 >(_buf?)?
704 .into_result::<PolicyProviderMarker>("watch_device_state")?;
705 Ok(_response.map(|x| x))
706 }
707 self.client.send_query_and_decode::<
708 fidl::encoding::EmptyPayload,
709 fidl_fuchsia_hardware_usb_policy::DeviceStateWatcherWatchDeviceStateResult,
710 >(
711 (),
712 0x44628a2275753738,
713 fidl::encoding::DynamicFlags::FLEXIBLE,
714 _decode,
715 )
716 }
717}
718
719pub struct PolicyProviderEventStream {
720 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
721}
722
723impl std::marker::Unpin for PolicyProviderEventStream {}
724
725impl futures::stream::FusedStream for PolicyProviderEventStream {
726 fn is_terminated(&self) -> bool {
727 self.event_receiver.is_terminated()
728 }
729}
730
731impl futures::Stream for PolicyProviderEventStream {
732 type Item = Result<PolicyProviderEvent, fidl::Error>;
733
734 fn poll_next(
735 mut self: std::pin::Pin<&mut Self>,
736 cx: &mut std::task::Context<'_>,
737 ) -> std::task::Poll<Option<Self::Item>> {
738 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
739 &mut self.event_receiver,
740 cx
741 )?) {
742 Some(buf) => std::task::Poll::Ready(Some(PolicyProviderEvent::decode(buf))),
743 None => std::task::Poll::Ready(None),
744 }
745 }
746}
747
748#[derive(Debug)]
749pub enum PolicyProviderEvent {
750 #[non_exhaustive]
751 _UnknownEvent {
752 ordinal: u64,
754 },
755}
756
757impl PolicyProviderEvent {
758 fn decode(
760 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
761 ) -> Result<PolicyProviderEvent, fidl::Error> {
762 let (bytes, _handles) = buf.split_mut();
763 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
764 debug_assert_eq!(tx_header.tx_id, 0);
765 match tx_header.ordinal {
766 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
767 Ok(PolicyProviderEvent::_UnknownEvent { ordinal: tx_header.ordinal })
768 }
769 _ => Err(fidl::Error::UnknownOrdinal {
770 ordinal: tx_header.ordinal,
771 protocol_name:
772 <PolicyProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
773 }),
774 }
775 }
776}
777
778pub struct PolicyProviderRequestStream {
780 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
781 is_terminated: bool,
782}
783
784impl std::marker::Unpin for PolicyProviderRequestStream {}
785
786impl futures::stream::FusedStream for PolicyProviderRequestStream {
787 fn is_terminated(&self) -> bool {
788 self.is_terminated
789 }
790}
791
792impl fidl::endpoints::RequestStream for PolicyProviderRequestStream {
793 type Protocol = PolicyProviderMarker;
794 type ControlHandle = PolicyProviderControlHandle;
795
796 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
797 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
798 }
799
800 fn control_handle(&self) -> Self::ControlHandle {
801 PolicyProviderControlHandle { inner: self.inner.clone() }
802 }
803
804 fn into_inner(
805 self,
806 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
807 {
808 (self.inner, self.is_terminated)
809 }
810
811 fn from_inner(
812 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
813 is_terminated: bool,
814 ) -> Self {
815 Self { inner, is_terminated }
816 }
817}
818
819impl futures::Stream for PolicyProviderRequestStream {
820 type Item = Result<PolicyProviderRequest, fidl::Error>;
821
822 fn poll_next(
823 mut self: std::pin::Pin<&mut Self>,
824 cx: &mut std::task::Context<'_>,
825 ) -> std::task::Poll<Option<Self::Item>> {
826 let this = &mut *self;
827 if this.inner.check_shutdown(cx) {
828 this.is_terminated = true;
829 return std::task::Poll::Ready(None);
830 }
831 if this.is_terminated {
832 panic!("polled PolicyProviderRequestStream after completion");
833 }
834 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
835 |bytes, handles| {
836 match this.inner.channel().read_etc(cx, bytes, handles) {
837 std::task::Poll::Ready(Ok(())) => {}
838 std::task::Poll::Pending => return std::task::Poll::Pending,
839 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
840 this.is_terminated = true;
841 return std::task::Poll::Ready(None);
842 }
843 std::task::Poll::Ready(Err(e)) => {
844 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
845 e.into(),
846 ))));
847 }
848 }
849
850 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
852
853 std::task::Poll::Ready(Some(match header.ordinal {
854 0x44628a2275753738 => {
855 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
856 let mut req = fidl::new_empty!(
857 fidl::encoding::EmptyPayload,
858 fidl::encoding::DefaultFuchsiaResourceDialect
859 );
860 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
861 let control_handle =
862 PolicyProviderControlHandle { inner: this.inner.clone() };
863 Ok(PolicyProviderRequest::WatchDeviceState {
864 responder: PolicyProviderWatchDeviceStateResponder {
865 control_handle: std::mem::ManuallyDrop::new(control_handle),
866 tx_id: header.tx_id,
867 },
868 })
869 }
870 _ if header.tx_id == 0
871 && header
872 .dynamic_flags()
873 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
874 {
875 Ok(PolicyProviderRequest::_UnknownMethod {
876 ordinal: header.ordinal,
877 control_handle: PolicyProviderControlHandle {
878 inner: this.inner.clone(),
879 },
880 method_type: fidl::MethodType::OneWay,
881 })
882 }
883 _ if header
884 .dynamic_flags()
885 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
886 {
887 this.inner.send_framework_err(
888 fidl::encoding::FrameworkErr::UnknownMethod,
889 header.tx_id,
890 header.ordinal,
891 header.dynamic_flags(),
892 (bytes, handles),
893 )?;
894 Ok(PolicyProviderRequest::_UnknownMethod {
895 ordinal: header.ordinal,
896 control_handle: PolicyProviderControlHandle {
897 inner: this.inner.clone(),
898 },
899 method_type: fidl::MethodType::TwoWay,
900 })
901 }
902 _ => Err(fidl::Error::UnknownOrdinal {
903 ordinal: header.ordinal,
904 protocol_name:
905 <PolicyProviderMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
906 }),
907 }))
908 },
909 )
910 }
911}
912
913#[derive(Debug)]
915pub enum PolicyProviderRequest {
916 WatchDeviceState { responder: PolicyProviderWatchDeviceStateResponder },
922 #[non_exhaustive]
924 _UnknownMethod {
925 ordinal: u64,
927 control_handle: PolicyProviderControlHandle,
928 method_type: fidl::MethodType,
929 },
930}
931
932impl PolicyProviderRequest {
933 #[allow(irrefutable_let_patterns)]
934 pub fn into_watch_device_state(self) -> Option<(PolicyProviderWatchDeviceStateResponder)> {
935 if let PolicyProviderRequest::WatchDeviceState { responder } = self {
936 Some((responder))
937 } else {
938 None
939 }
940 }
941
942 pub fn method_name(&self) -> &'static str {
944 match *self {
945 PolicyProviderRequest::WatchDeviceState { .. } => "watch_device_state",
946 PolicyProviderRequest::_UnknownMethod {
947 method_type: fidl::MethodType::OneWay, ..
948 } => "unknown one-way method",
949 PolicyProviderRequest::_UnknownMethod {
950 method_type: fidl::MethodType::TwoWay, ..
951 } => "unknown two-way method",
952 }
953 }
954}
955
956#[derive(Debug, Clone)]
957pub struct PolicyProviderControlHandle {
958 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
959}
960
961impl fidl::endpoints::ControlHandle for PolicyProviderControlHandle {
962 fn shutdown(&self) {
963 self.inner.shutdown()
964 }
965
966 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
967 self.inner.shutdown_with_epitaph(status)
968 }
969
970 fn is_closed(&self) -> bool {
971 self.inner.channel().is_closed()
972 }
973 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
974 self.inner.channel().on_closed()
975 }
976
977 #[cfg(target_os = "fuchsia")]
978 fn signal_peer(
979 &self,
980 clear_mask: zx::Signals,
981 set_mask: zx::Signals,
982 ) -> Result<(), zx_status::Status> {
983 use fidl::Peered;
984 self.inner.channel().signal_peer(clear_mask, set_mask)
985 }
986}
987
988impl PolicyProviderControlHandle {}
989
990#[must_use = "FIDL methods require a response to be sent"]
991#[derive(Debug)]
992pub struct PolicyProviderWatchDeviceStateResponder {
993 control_handle: std::mem::ManuallyDrop<PolicyProviderControlHandle>,
994 tx_id: u32,
995}
996
997impl std::ops::Drop for PolicyProviderWatchDeviceStateResponder {
1001 fn drop(&mut self) {
1002 self.control_handle.shutdown();
1003 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1005 }
1006}
1007
1008impl fidl::endpoints::Responder for PolicyProviderWatchDeviceStateResponder {
1009 type ControlHandle = PolicyProviderControlHandle;
1010
1011 fn control_handle(&self) -> &PolicyProviderControlHandle {
1012 &self.control_handle
1013 }
1014
1015 fn drop_without_shutdown(mut self) {
1016 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1018 std::mem::forget(self);
1020 }
1021}
1022
1023impl PolicyProviderWatchDeviceStateResponder {
1024 pub fn send(
1028 self,
1029 mut result: Result<&fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate, i32>,
1030 ) -> Result<(), fidl::Error> {
1031 let _result = self.send_raw(result);
1032 if _result.is_err() {
1033 self.control_handle.shutdown();
1034 }
1035 self.drop_without_shutdown();
1036 _result
1037 }
1038
1039 pub fn send_no_shutdown_on_err(
1041 self,
1042 mut result: Result<&fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate, i32>,
1043 ) -> Result<(), fidl::Error> {
1044 let _result = self.send_raw(result);
1045 self.drop_without_shutdown();
1046 _result
1047 }
1048
1049 fn send_raw(
1050 &self,
1051 mut result: Result<&fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate, i32>,
1052 ) -> Result<(), fidl::Error> {
1053 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
1054 fidl_fuchsia_hardware_usb_policy::DeviceStateUpdate,
1055 i32,
1056 >>(
1057 fidl::encoding::FlexibleResult::new(result),
1058 self.tx_id,
1059 0x44628a2275753738,
1060 fidl::encoding::DynamicFlags::FLEXIBLE,
1061 )
1062 }
1063}
1064
1065mod internal {
1066 use super::*;
1067}