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_devfs_test__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
15pub struct DeviceMarker;
16
17impl fidl::endpoints::ProtocolMarker for DeviceMarker {
18 type Proxy = DeviceProxy;
19 type RequestStream = DeviceRequestStream;
20 #[cfg(target_os = "fuchsia")]
21 type SynchronousProxy = DeviceSynchronousProxy;
22
23 const DEBUG_NAME: &'static str = "fuchsia.devfs.test.Device";
24}
25impl fidl::endpoints::DiscoverableProtocolMarker for DeviceMarker {}
26
27pub trait DeviceProxyInterface: Send + Sync {
28 type PingResponseFut: std::future::Future<Output = Result<(), fidl::Error>> + Send;
29 fn r#ping(&self) -> Self::PingResponseFut;
30}
31#[derive(Debug)]
32#[cfg(target_os = "fuchsia")]
33pub struct DeviceSynchronousProxy {
34 client: fidl::client::sync::Client,
35}
36
37#[cfg(target_os = "fuchsia")]
38impl fidl::endpoints::SynchronousProxy for DeviceSynchronousProxy {
39 type Proxy = DeviceProxy;
40 type Protocol = DeviceMarker;
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 DeviceSynchronousProxy {
57 pub fn new(channel: fidl::Channel) -> Self {
58 let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
59 Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
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<DeviceEvent, fidl::Error> {
72 DeviceEvent::decode(self.client.wait_for_event(deadline)?)
73 }
74
75 pub fn r#ping(&self, ___deadline: zx::MonotonicInstant) -> Result<(), fidl::Error> {
76 let _response =
77 self.client.send_query::<fidl::encoding::EmptyPayload, fidl::encoding::EmptyPayload>(
78 (),
79 0x9d972c4388e131a,
80 fidl::encoding::DynamicFlags::empty(),
81 ___deadline,
82 )?;
83 Ok(_response)
84 }
85}
86
87#[cfg(target_os = "fuchsia")]
88impl From<DeviceSynchronousProxy> for zx::Handle {
89 fn from(value: DeviceSynchronousProxy) -> Self {
90 value.into_channel().into()
91 }
92}
93
94#[cfg(target_os = "fuchsia")]
95impl From<fidl::Channel> for DeviceSynchronousProxy {
96 fn from(value: fidl::Channel) -> Self {
97 Self::new(value)
98 }
99}
100
101#[cfg(target_os = "fuchsia")]
102impl fidl::endpoints::FromClient for DeviceSynchronousProxy {
103 type Protocol = DeviceMarker;
104
105 fn from_client(value: fidl::endpoints::ClientEnd<DeviceMarker>) -> Self {
106 Self::new(value.into_channel())
107 }
108}
109
110#[derive(Debug, Clone)]
111pub struct DeviceProxy {
112 client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
113}
114
115impl fidl::endpoints::Proxy for DeviceProxy {
116 type Protocol = DeviceMarker;
117
118 fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
119 Self::new(inner)
120 }
121
122 fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
123 self.client.into_channel().map_err(|client| Self { client })
124 }
125
126 fn as_channel(&self) -> &::fidl::AsyncChannel {
127 self.client.as_channel()
128 }
129}
130
131impl DeviceProxy {
132 pub fn new(channel: ::fidl::AsyncChannel) -> Self {
134 let protocol_name = <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
135 Self { client: fidl::client::Client::new(channel, protocol_name) }
136 }
137
138 pub fn take_event_stream(&self) -> DeviceEventStream {
144 DeviceEventStream { event_receiver: self.client.take_event_receiver() }
145 }
146
147 pub fn r#ping(
148 &self,
149 ) -> fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect> {
150 DeviceProxyInterface::r#ping(self)
151 }
152}
153
154impl DeviceProxyInterface for DeviceProxy {
155 type PingResponseFut =
156 fidl::client::QueryResponseFut<(), fidl::encoding::DefaultFuchsiaResourceDialect>;
157 fn r#ping(&self) -> Self::PingResponseFut {
158 fn _decode(
159 mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
160 ) -> Result<(), fidl::Error> {
161 let _response = fidl::client::decode_transaction_body::<
162 fidl::encoding::EmptyPayload,
163 fidl::encoding::DefaultFuchsiaResourceDialect,
164 0x9d972c4388e131a,
165 >(_buf?)?;
166 Ok(_response)
167 }
168 self.client.send_query_and_decode::<fidl::encoding::EmptyPayload, ()>(
169 (),
170 0x9d972c4388e131a,
171 fidl::encoding::DynamicFlags::empty(),
172 _decode,
173 )
174 }
175}
176
177pub struct DeviceEventStream {
178 event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
179}
180
181impl std::marker::Unpin for DeviceEventStream {}
182
183impl futures::stream::FusedStream for DeviceEventStream {
184 fn is_terminated(&self) -> bool {
185 self.event_receiver.is_terminated()
186 }
187}
188
189impl futures::Stream for DeviceEventStream {
190 type Item = Result<DeviceEvent, fidl::Error>;
191
192 fn poll_next(
193 mut self: std::pin::Pin<&mut Self>,
194 cx: &mut std::task::Context<'_>,
195 ) -> std::task::Poll<Option<Self::Item>> {
196 match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
197 &mut self.event_receiver,
198 cx
199 )?) {
200 Some(buf) => std::task::Poll::Ready(Some(DeviceEvent::decode(buf))),
201 None => std::task::Poll::Ready(None),
202 }
203 }
204}
205
206#[derive(Debug)]
207pub enum DeviceEvent {}
208
209impl DeviceEvent {
210 fn decode(
212 mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
213 ) -> Result<DeviceEvent, fidl::Error> {
214 let (bytes, _handles) = buf.split_mut();
215 let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
216 debug_assert_eq!(tx_header.tx_id, 0);
217 match tx_header.ordinal {
218 _ => Err(fidl::Error::UnknownOrdinal {
219 ordinal: tx_header.ordinal,
220 protocol_name: <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
221 }),
222 }
223 }
224}
225
226pub struct DeviceRequestStream {
228 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
229 is_terminated: bool,
230}
231
232impl std::marker::Unpin for DeviceRequestStream {}
233
234impl futures::stream::FusedStream for DeviceRequestStream {
235 fn is_terminated(&self) -> bool {
236 self.is_terminated
237 }
238}
239
240impl fidl::endpoints::RequestStream for DeviceRequestStream {
241 type Protocol = DeviceMarker;
242 type ControlHandle = DeviceControlHandle;
243
244 fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
245 Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
246 }
247
248 fn control_handle(&self) -> Self::ControlHandle {
249 DeviceControlHandle { inner: self.inner.clone() }
250 }
251
252 fn into_inner(
253 self,
254 ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
255 {
256 (self.inner, self.is_terminated)
257 }
258
259 fn from_inner(
260 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
261 is_terminated: bool,
262 ) -> Self {
263 Self { inner, is_terminated }
264 }
265}
266
267impl futures::Stream for DeviceRequestStream {
268 type Item = Result<DeviceRequest, fidl::Error>;
269
270 fn poll_next(
271 mut self: std::pin::Pin<&mut Self>,
272 cx: &mut std::task::Context<'_>,
273 ) -> std::task::Poll<Option<Self::Item>> {
274 let this = &mut *self;
275 if this.inner.check_shutdown(cx) {
276 this.is_terminated = true;
277 return std::task::Poll::Ready(None);
278 }
279 if this.is_terminated {
280 panic!("polled DeviceRequestStream after completion");
281 }
282 fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
283 |bytes, handles| {
284 match this.inner.channel().read_etc(cx, bytes, handles) {
285 std::task::Poll::Ready(Ok(())) => {}
286 std::task::Poll::Pending => return std::task::Poll::Pending,
287 std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
288 this.is_terminated = true;
289 return std::task::Poll::Ready(None);
290 }
291 std::task::Poll::Ready(Err(e)) => {
292 return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
293 e.into(),
294 ))))
295 }
296 }
297
298 let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
300
301 std::task::Poll::Ready(Some(match header.ordinal {
302 0x9d972c4388e131a => {
303 header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
304 let mut req = fidl::new_empty!(
305 fidl::encoding::EmptyPayload,
306 fidl::encoding::DefaultFuchsiaResourceDialect
307 );
308 fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
309 let control_handle = DeviceControlHandle { inner: this.inner.clone() };
310 Ok(DeviceRequest::Ping {
311 responder: DevicePingResponder {
312 control_handle: std::mem::ManuallyDrop::new(control_handle),
313 tx_id: header.tx_id,
314 },
315 })
316 }
317 _ => Err(fidl::Error::UnknownOrdinal {
318 ordinal: header.ordinal,
319 protocol_name:
320 <DeviceMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
321 }),
322 }))
323 },
324 )
325 }
326}
327
328#[derive(Debug)]
329pub enum DeviceRequest {
330 Ping { responder: DevicePingResponder },
331}
332
333impl DeviceRequest {
334 #[allow(irrefutable_let_patterns)]
335 pub fn into_ping(self) -> Option<(DevicePingResponder)> {
336 if let DeviceRequest::Ping { responder } = self {
337 Some((responder))
338 } else {
339 None
340 }
341 }
342
343 pub fn method_name(&self) -> &'static str {
345 match *self {
346 DeviceRequest::Ping { .. } => "ping",
347 }
348 }
349}
350
351#[derive(Debug, Clone)]
352pub struct DeviceControlHandle {
353 inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
354}
355
356impl fidl::endpoints::ControlHandle for DeviceControlHandle {
357 fn shutdown(&self) {
358 self.inner.shutdown()
359 }
360 fn shutdown_with_epitaph(&self, status: zx_status::Status) {
361 self.inner.shutdown_with_epitaph(status)
362 }
363
364 fn is_closed(&self) -> bool {
365 self.inner.channel().is_closed()
366 }
367 fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
368 self.inner.channel().on_closed()
369 }
370
371 #[cfg(target_os = "fuchsia")]
372 fn signal_peer(
373 &self,
374 clear_mask: zx::Signals,
375 set_mask: zx::Signals,
376 ) -> Result<(), zx_status::Status> {
377 use fidl::Peered;
378 self.inner.channel().signal_peer(clear_mask, set_mask)
379 }
380}
381
382impl DeviceControlHandle {}
383
384#[must_use = "FIDL methods require a response to be sent"]
385#[derive(Debug)]
386pub struct DevicePingResponder {
387 control_handle: std::mem::ManuallyDrop<DeviceControlHandle>,
388 tx_id: u32,
389}
390
391impl std::ops::Drop for DevicePingResponder {
395 fn drop(&mut self) {
396 self.control_handle.shutdown();
397 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
399 }
400}
401
402impl fidl::endpoints::Responder for DevicePingResponder {
403 type ControlHandle = DeviceControlHandle;
404
405 fn control_handle(&self) -> &DeviceControlHandle {
406 &self.control_handle
407 }
408
409 fn drop_without_shutdown(mut self) {
410 unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
412 std::mem::forget(self);
414 }
415}
416
417impl DevicePingResponder {
418 pub fn send(self) -> Result<(), fidl::Error> {
422 let _result = self.send_raw();
423 if _result.is_err() {
424 self.control_handle.shutdown();
425 }
426 self.drop_without_shutdown();
427 _result
428 }
429
430 pub fn send_no_shutdown_on_err(self) -> Result<(), fidl::Error> {
432 let _result = self.send_raw();
433 self.drop_without_shutdown();
434 _result
435 }
436
437 fn send_raw(&self) -> Result<(), fidl::Error> {
438 self.control_handle.inner.send::<fidl::encoding::EmptyPayload>(
439 (),
440 self.tx_id,
441 0x9d972c4388e131a,
442 fidl::encoding::DynamicFlags::empty(),
443 )
444 }
445}
446
447mod internal {
448 use super::*;
449}