fidl_fuchsia_driver_registrar/
fidl_fuchsia_driver_registrar.rs1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_driver_registrar__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DriverRegistrarMarker;
16
17impl fidl::endpoints::ProtocolMarker for DriverRegistrarMarker {
18 type Proxy = DriverRegistrarProxy;
19 type RequestStream = DriverRegistrarRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = DriverRegistrarSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.driver.registrar.DriverRegistrar";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DriverRegistrarMarker {}
26pub type DriverRegistrarRegisterResult = Result<(), i32>;
27
28pub trait DriverRegistrarProxyInterface: Send + Sync {
29 type RegisterResponseFut: std::future::Future<Output = Result<DriverRegistrarRegisterResult, fidl::Error>>
30 + Send;
31 fn r#register(&self, driver_url: &str) -> Self::RegisterResponseFut;
32}
33#[derive(Debug)]
34#[cfg(target_os = "fuchsia")]
35pub struct DriverRegistrarSynchronousProxy {
36 client: fidl::client::sync::Client,
37}
38
39#[cfg(target_os = "fuchsia")]
40impl fidl::endpoints::SynchronousProxy for DriverRegistrarSynchronousProxy {
41 type Proxy = DriverRegistrarProxy;
42 type Protocol = DriverRegistrarMarker;
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 DriverRegistrarSynchronousProxy {
59 pub fn new(channel: fidl::Channel) -> Self {
60 let protocol_name = <DriverRegistrarMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
61 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
62 }
63
64 pub fn into_channel(self) -> fidl::Channel {
65 self.client.into_channel()
66 }
67
68 pub fn wait_for_event(
71 &self,
72 deadline: zx::MonotonicInstant,
73 ) -> Result<DriverRegistrarEvent, fidl::Error> {
74 DriverRegistrarEvent::decode(self.client.wait_for_event(deadline)?)
75 }
76
77 pub fn r#register(
96 &self,
97 mut driver_url: &str,
98 ___deadline: zx::MonotonicInstant,
99 ) -> Result<DriverRegistrarRegisterResult, fidl::Error> {
100 let _response = self.client.send_query::<
101 DriverRegistrarRegisterRequest,
102 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
103 >(
104 (driver_url,),
105 0x5c5f637b5f7c6a6,
106 fidl::encoding::DynamicFlags::FLEXIBLE,
107 ___deadline,
108 )?
109 .into_result::<DriverRegistrarMarker>("register")?;
110 Ok(_response.map(|x| x))
111 }
112}
113
114#[cfg(target_os = "fuchsia")]
115impl From<DriverRegistrarSynchronousProxy> for zx::Handle {
116 fn from(value: DriverRegistrarSynchronousProxy) -> Self {
117 value.into_channel().into()
118 }
119}
120
121#[cfg(target_os = "fuchsia")]
122impl From<fidl::Channel> for DriverRegistrarSynchronousProxy {
123 fn from(value: fidl::Channel) -> Self {
124 Self::new(value)
125 }
126}
127
128#[cfg(target_os = "fuchsia")]
129impl fidl::endpoints::FromClient for DriverRegistrarSynchronousProxy {
130 type Protocol = DriverRegistrarMarker;
131
132 fn from_client(value: fidl::endpoints::ClientEnd<DriverRegistrarMarker>) -> Self {
133 Self::new(value.into_channel())
134 }
135}
136
137#[derive(Debug, Clone)]
138pub struct DriverRegistrarProxy {
139 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
140}
141
142impl fidl::endpoints::Proxy for DriverRegistrarProxy {
143 type Protocol = DriverRegistrarMarker;
144
145 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
146 Self::new(inner)
147 }
148
149 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
150 self.client.into_channel().map_err(|client| Self { client })
151 }
152
153 fn as_channel(&self) -> &::fidl::AsyncChannel {
154 self.client.as_channel()
155 }
156}
157
158impl DriverRegistrarProxy {
159 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
161 let protocol_name = <DriverRegistrarMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
162 Self { client: fidl::client::Client::new(channel, protocol_name) }
163 }
164
165 pub fn take_event_stream(&self) -> DriverRegistrarEventStream {
171 DriverRegistrarEventStream { event_receiver: self.client.take_event_receiver() }
172 }
173
174 pub fn r#register(
193 &self,
194 mut driver_url: &str,
195 ) -> fidl::client::QueryResponseFut<
196 DriverRegistrarRegisterResult,
197 fidl::encoding::DefaultFuchsiaResourceDialect,
198 > {
199 DriverRegistrarProxyInterface::r#register(self, driver_url)
200 }
201}
202
203impl DriverRegistrarProxyInterface for DriverRegistrarProxy {
204 type RegisterResponseFut = fidl::client::QueryResponseFut<
205 DriverRegistrarRegisterResult,
206 fidl::encoding::DefaultFuchsiaResourceDialect,
207 >;
208 fn r#register(&self, mut driver_url: &str) -> Self::RegisterResponseFut {
209 fn _decode(
210 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
211 ) -> Result<DriverRegistrarRegisterResult, fidl::Error> {
212 let _response = fidl::client::decode_transaction_body::<
213 fidl::encoding::FlexibleResultType<fidl::encoding::EmptyStruct, i32>,
214 fidl::encoding::DefaultFuchsiaResourceDialect,
215 0x5c5f637b5f7c6a6,
216 >(_buf?)?
217 .into_result::<DriverRegistrarMarker>("register")?;
218 Ok(_response.map(|x| x))
219 }
220 self.client
221 .send_query_and_decode::<DriverRegistrarRegisterRequest, DriverRegistrarRegisterResult>(
222 (driver_url,),
223 0x5c5f637b5f7c6a6,
224 fidl::encoding::DynamicFlags::FLEXIBLE,
225 _decode,
226 )
227 }
228}
229
230pub struct DriverRegistrarEventStream {
231 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
232}
233
234impl std::marker::Unpin for DriverRegistrarEventStream {}
235
236impl futures::stream::FusedStream for DriverRegistrarEventStream {
237 fn is_terminated(&self) -> bool {
238 self.event_receiver.is_terminated()
239 }
240}
241
242impl futures::Stream for DriverRegistrarEventStream {
243 type Item = Result<DriverRegistrarEvent, fidl::Error>;
244
245 fn poll_next(
246 mut self: std::pin::Pin<&mut Self>,
247 cx: &mut std::task::Context<'_>,
248 ) -> std::task::Poll<Option<Self::Item>> {
249 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
250 &mut self.event_receiver,
251 cx
252 )?) {
253 Some(buf) => std::task::Poll::Ready(Some(DriverRegistrarEvent::decode(buf))),
254 None => std::task::Poll::Ready(None),
255 }
256 }
257}
258
259#[derive(Debug)]
260pub enum DriverRegistrarEvent {
261 #[non_exhaustive]
262 _UnknownEvent {
263 ordinal: u64,
265 },
266}
267
268impl DriverRegistrarEvent {
269 fn decode(
271 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
272 ) -> Result<DriverRegistrarEvent, fidl::Error> {
273 let (bytes, _handles) = buf.split_mut();
274 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
275 debug_assert_eq!(tx_header.tx_id, 0);
276 match tx_header.ordinal {
277 _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
278 Ok(DriverRegistrarEvent::_UnknownEvent { ordinal: tx_header.ordinal })
279 }
280 _ => Err(fidl::Error::UnknownOrdinal {
281 ordinal: tx_header.ordinal,
282 protocol_name:
283 <DriverRegistrarMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
284 }),
285 }
286 }
287}
288
289pub struct DriverRegistrarRequestStream {
291 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
292 is_terminated: bool,
293}
294
295impl std::marker::Unpin for DriverRegistrarRequestStream {}
296
297impl futures::stream::FusedStream for DriverRegistrarRequestStream {
298 fn is_terminated(&self) -> bool {
299 self.is_terminated
300 }
301}
302
303impl fidl::endpoints::RequestStream for DriverRegistrarRequestStream {
304 type Protocol = DriverRegistrarMarker;
305 type ControlHandle = DriverRegistrarControlHandle;
306
307 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
308 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
309 }
310
311 fn control_handle(&self) -> Self::ControlHandle {
312 DriverRegistrarControlHandle { inner: self.inner.clone() }
313 }
314
315 fn into_inner(
316 self,
317 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
318 {
319 (self.inner, self.is_terminated)
320 }
321
322 fn from_inner(
323 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
324 is_terminated: bool,
325 ) -> Self {
326 Self { inner, is_terminated }
327 }
328}
329
330impl futures::Stream for DriverRegistrarRequestStream {
331 type Item = Result<DriverRegistrarRequest, fidl::Error>;
332
333 fn poll_next(
334 mut self: std::pin::Pin<&mut Self>,
335 cx: &mut std::task::Context<'_>,
336 ) -> std::task::Poll<Option<Self::Item>> {
337 let this = &mut *self;
338 if this.inner.check_shutdown(cx) {
339 this.is_terminated = true;
340 return std::task::Poll::Ready(None);
341 }
342 if this.is_terminated {
343 panic!("polled DriverRegistrarRequestStream after completion");
344 }
345 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
346 |bytes, handles| {
347 match this.inner.channel().read_etc(cx, bytes, handles) {
348 std::task::Poll::Ready(Ok(())) => {}
349 std::task::Poll::Pending => return std::task::Poll::Pending,
350 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
351 this.is_terminated = true;
352 return std::task::Poll::Ready(None);
353 }
354 std::task::Poll::Ready(Err(e)) => {
355 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
356 e.into(),
357 ))))
358 }
359 }
360
361 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
363
364 std::task::Poll::Ready(Some(match header.ordinal {
365 0x5c5f637b5f7c6a6 => {
366 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
367 let mut req = fidl::new_empty!(
368 DriverRegistrarRegisterRequest,
369 fidl::encoding::DefaultFuchsiaResourceDialect
370 );
371 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DriverRegistrarRegisterRequest>(&header, _body_bytes, handles, &mut req)?;
372 let control_handle =
373 DriverRegistrarControlHandle { inner: this.inner.clone() };
374 Ok(DriverRegistrarRequest::Register {
375 driver_url: req.driver_url,
376
377 responder: DriverRegistrarRegisterResponder {
378 control_handle: std::mem::ManuallyDrop::new(control_handle),
379 tx_id: header.tx_id,
380 },
381 })
382 }
383 _ if header.tx_id == 0
384 && header
385 .dynamic_flags()
386 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
387 {
388 Ok(DriverRegistrarRequest::_UnknownMethod {
389 ordinal: header.ordinal,
390 control_handle: DriverRegistrarControlHandle {
391 inner: this.inner.clone(),
392 },
393 method_type: fidl::MethodType::OneWay,
394 })
395 }
396 _ if header
397 .dynamic_flags()
398 .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
399 {
400 this.inner.send_framework_err(
401 fidl::encoding::FrameworkErr::UnknownMethod,
402 header.tx_id,
403 header.ordinal,
404 header.dynamic_flags(),
405 (bytes, handles),
406 )?;
407 Ok(DriverRegistrarRequest::_UnknownMethod {
408 ordinal: header.ordinal,
409 control_handle: DriverRegistrarControlHandle {
410 inner: this.inner.clone(),
411 },
412 method_type: fidl::MethodType::TwoWay,
413 })
414 }
415 _ => Err(fidl::Error::UnknownOrdinal {
416 ordinal: header.ordinal,
417 protocol_name:
418 <DriverRegistrarMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
419 }),
420 }))
421 },
422 )
423 }
424}
425
426#[derive(Debug)]
428pub enum DriverRegistrarRequest {
429 Register { driver_url: String, responder: DriverRegistrarRegisterResponder },
448 #[non_exhaustive]
450 _UnknownMethod {
451 ordinal: u64,
453 control_handle: DriverRegistrarControlHandle,
454 method_type: fidl::MethodType,
455 },
456}
457
458impl DriverRegistrarRequest {
459 #[allow(irrefutable_let_patterns)]
460 pub fn into_register(self) -> Option<(String, DriverRegistrarRegisterResponder)> {
461 if let DriverRegistrarRequest::Register { driver_url, responder } = self {
462 Some((driver_url, responder))
463 } else {
464 None
465 }
466 }
467
468 pub fn method_name(&self) -> &'static str {
470 match *self {
471 DriverRegistrarRequest::Register { .. } => "register",
472 DriverRegistrarRequest::_UnknownMethod {
473 method_type: fidl::MethodType::OneWay,
474 ..
475 } => "unknown one-way method",
476 DriverRegistrarRequest::_UnknownMethod {
477 method_type: fidl::MethodType::TwoWay,
478 ..
479 } => "unknown two-way method",
480 }
481 }
482}
483
484#[derive(Debug, Clone)]
485pub struct DriverRegistrarControlHandle {
486 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
487}
488
489impl fidl::endpoints::ControlHandle for DriverRegistrarControlHandle {
490 fn shutdown(&self) {
491 self.inner.shutdown()
492 }
493 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
494 self.inner.shutdown_with_epitaph(status)
495 }
496
497 fn is_closed(&self) -> bool {
498 self.inner.channel().is_closed()
499 }
500 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
501 self.inner.channel().on_closed()
502 }
503
504 #[cfg(target_os = "fuchsia")]
505 fn signal_peer(
506 &self,
507 clear_mask: zx::Signals,
508 set_mask: zx::Signals,
509 ) -> Result<(), zx_status::Status> {
510 use fidl::Peered;
511 self.inner.channel().signal_peer(clear_mask, set_mask)
512 }
513}
514
515impl DriverRegistrarControlHandle {}
516
517#[must_use = "FIDL methods require a response to be sent"]
518#[derive(Debug)]
519pub struct DriverRegistrarRegisterResponder {
520 control_handle: std::mem::ManuallyDrop<DriverRegistrarControlHandle>,
521 tx_id: u32,
522}
523
524impl std::ops::Drop for DriverRegistrarRegisterResponder {
528 fn drop(&mut self) {
529 self.control_handle.shutdown();
530 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
532 }
533}
534
535impl fidl::endpoints::Responder for DriverRegistrarRegisterResponder {
536 type ControlHandle = DriverRegistrarControlHandle;
537
538 fn control_handle(&self) -> &DriverRegistrarControlHandle {
539 &self.control_handle
540 }
541
542 fn drop_without_shutdown(mut self) {
543 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
545 std::mem::forget(self);
547 }
548}
549
550impl DriverRegistrarRegisterResponder {
551 pub fn send(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
555 let _result = self.send_raw(result);
556 if _result.is_err() {
557 self.control_handle.shutdown();
558 }
559 self.drop_without_shutdown();
560 _result
561 }
562
563 pub fn send_no_shutdown_on_err(self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
565 let _result = self.send_raw(result);
566 self.drop_without_shutdown();
567 _result
568 }
569
570 fn send_raw(&self, mut result: Result<(), i32>) -> Result<(), fidl::Error> {
571 self.control_handle.inner.send::<fidl::encoding::FlexibleResultType<
572 fidl::encoding::EmptyStruct,
573 i32,
574 >>(
575 fidl::encoding::FlexibleResult::new(result),
576 self.tx_id,
577 0x5c5f637b5f7c6a6,
578 fidl::encoding::DynamicFlags::FLEXIBLE,
579 )
580 }
581}
582
583mod internal {
584 use super::*;
585}