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